Timeline.vue 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692
  1. <template>
  2. <div class="container" style="">
  3. <div v-if="layout === 'feed'" class="row">
  4. <div v-if="morePostsAvailable == true" class="col-12 mt-5 pt-3 mb-3 fixed-top">
  5. <p class="text-center">
  6. <button class="btn btn-dark px-4 rounded-pill font-weight-bold shadow" @click="syncNewPosts">Load New Posts</button>
  7. </p>
  8. </div>
  9. <div class="d-none col-12 pl-3 pl-md-0 pt-3 pl-0">
  10. <div class="d-none d-md-flex justify-content-between align-items-center">
  11. <p class="lead text-muted mb-0"><i :class="[scope == 'home' ? 'fas fa-home':'fas fa-stream']"></i> &nbsp; {{scope == 'local' ? 'Public' : 'Home'}} Timeline</p>
  12. <p class="mb-0">
  13. <span class="btn-group">
  14. <a href="#" :class="[layout=='feed'?'btn btn-sm btn-outline-primary font-weight-bold text-decoration-none':'btn btn-sm btn-outline-lighter font-weight-light text-decoration-none']" @click.prevent="switchFeedLayout('feed')"><i class="fas fa-list"></i></a>
  15. <a href="#" :class="[layout!=='feed'?'btn btn-sm btn-outline-primary font-weight-bold text-decoration-none':'btn btn-sm btn-outline-lighter font-weight-light text-decoration-none']" @click.prevent="switchFeedLayout('grid')"><i class="fas fa-th"></i></a>
  16. </span>
  17. </p>
  18. <p class="mb-0 d-none d-md-block">
  19. <a class="btn btn-block btn-primary btn-sm font-weight-bold" href="/i/compose" data-toggle="modal" data-target="#composeModal">
  20. New Post
  21. </a>
  22. </p>
  23. </div>
  24. <hr>
  25. </div>
  26. <div class="col-md-8 col-lg-8 px-0 mb-sm-3 timeline order-2 order-md-1">
  27. <div style="margin-top:-2px;">
  28. <story-component v-if="config.features.stories"></story-component>
  29. </div>
  30. <div>
  31. <div v-if="loading" class="text-center" style="padding-top:10px;">
  32. <div class="spinner-border" role="status">
  33. <span class="sr-only">Loading...</span>
  34. </div>
  35. </div>
  36. <div :data-status-id="status.id" v-for="(status, index) in feed" :key="`${index}-${status.id}`">
  37. <div v-if="index == 0 && showTips && !loading" class="my-4 card-tips">
  38. <announcements-card v-on:show-tips="showTips = $event"></announcements-card>
  39. </div>
  40. <div v-if="index == 2 && showSuggestions == true && suggestions.length" class="card mb-sm-4 status-card card-md-rounded-0 shadow-none border">
  41. <div class="card-header d-flex align-items-center justify-content-between bg-white border-0 pb-0">
  42. <h6 class="text-muted font-weight-bold mb-0">Suggestions For You</h6>
  43. <span class="cursor-pointer text-muted" v-on:click="hideSuggestions"><i class="fas fa-times"></i></span>
  44. </div>
  45. <div class="card-body row mx-0">
  46. <div class="col-12 col-md-4 mb-3" v-for="(rec, index) in suggestions">
  47. <div class="card">
  48. <div class="card-body text-center pt-3">
  49. <p class="mb-0">
  50. <a :href="'/'+rec.username">
  51. <img :src="rec.avatar" class="img-fluid rounded-circle cursor-pointer" width="45px" height="45px" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'" alt="avatar">
  52. </a>
  53. </p>
  54. <div class="py-3">
  55. <p class="font-weight-bold text-dark cursor-pointer mb-0">
  56. <a :href="'/'+rec.username" class="text-decoration-none text-dark">
  57. {{rec.username}}
  58. </a>
  59. </p>
  60. <p class="small text-muted mb-0">{{rec.message}}</p>
  61. </div>
  62. <p class="mb-0">
  63. <a class="btn btn-primary btn-block font-weight-bold py-0" href="#" @click.prevent="expRecFollow(rec.id, index)">Follow</a>
  64. </p>
  65. </div>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. <div v-if="index == 4 && showHashtagPosts && hashtagPosts.length" class="card mb-sm-4 status-card card-md-rounded-0 shadow-none border">
  71. <div class="card-header d-flex align-items-center justify-content-between bg-white border-0 pb-0">
  72. <span></span>
  73. <h6 class="text-muted font-weight-bold mb-0"><a :href="'/discover/tags/'+hashtagPostsName+'?src=tr'">#{{hashtagPostsName}}</a></h6>
  74. <span class="cursor-pointer text-muted" v-on:click="showHashtagPosts = false"><i class="fas fa-times"></i></span>
  75. </div>
  76. <div class="card-body row mx-0">
  77. <div v-for="(tag, index) in hashtagPosts" class="col-4 p-0 p-sm-2 p-md-3 hashtag-post-square">
  78. <a class="card info-overlay card-md-border-0" :href="tag.status.url">
  79. <div :class="[tag.status.filter ? 'square ' + tag.status.filter : 'square']">
  80. <div class="square-content" :style="'background-image: url('+tag.status.thumb+')'"></div>
  81. <div class="info-overlay-text">
  82. <h5 class="text-white m-auto font-weight-bold">
  83. <span class="pr-4">
  84. <span class="far fa-heart fa-lg pr-1"></span> {{tag.status.like_count}}
  85. </span>
  86. <span>
  87. <span class="fas fa-retweet fa-lg pr-1"></span> {{tag.status.share_count}}
  88. </span>
  89. </h5>
  90. </div>
  91. </div>
  92. </a>
  93. </div>
  94. </div>
  95. </div>
  96. <div :class="index == 0 ? 'card mb-sm-4 status-card card-md-rounded-0 shadow-none border mt-md-4' : 'card mb-sm-4 status-card card-md-rounded-0 shadow-none border'">
  97. <div v-if="status" class="card-header d-inline-flex align-items-center bg-white">
  98. <!-- <img v-bind:src="status.account.avatar" width="38px" height="38px" class="cursor-pointer" style="border-radius: 38px;" @click="profileUrl(status)" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'"> -->
  99. <!-- <div v-if="hasStory" class="has-story has-story-sm cursor-pointer shadow-sm" @click="profileUrl(status)">
  100. <img class="rounded-circle box-shadow" :src="status.account.avatar" width="32px" height="32px" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'">
  101. </div>
  102. <div v-else> -->
  103. <div>
  104. <img class="rounded-circle box-shadow" :src="status.account.avatar" width="32px" height="32px" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'" alt="avatar">
  105. </div>
  106. <div class="pl-2">
  107. <!-- <a class="d-block username font-weight-bold text-dark" v-bind:href="status.account.url" style="line-height:0.5;"> -->
  108. <a class="username font-weight-bold text-dark text-decoration-none" v-bind:href="profileUrl(status)" v-html="statusCardUsernameFormat(status)">
  109. Loading...
  110. </a>
  111. <span v-if="status.account.is_admin" class="fa-stack" title="Admin Account" data-toggle="tooltip" style="height:1em; line-height:1em; max-width:19px;">
  112. <i class="fas fa-certificate text-danger fa-stack-1x"></i>
  113. <i class="fas fa-crown text-white fa-sm fa-stack-1x" style="font-size:7px;"></i>
  114. </span>
  115. <!-- <span v-if="scope != 'home' && status.account.id != profile.id && status.account.relationship">
  116. <span class="px-1">•</span>
  117. <span :class="'font-weight-bold cursor-pointer ' + [status.account.relationship.following == true ? 'text-muted' : 'text-primary']" @click="followAction(status)">{{status.account.relationship.following == true ? 'Following' : 'Follow'}}</span>
  118. </span> -->
  119. <!-- <span v-if="status.account.id != profile.id">
  120. <span class="px-1">•</span>
  121. <span class="font-weight-bold cursor-pointer text-primary">Follow</span>
  122. </span> -->
  123. <div class="d-flex align-items-center">
  124. <a v-if="status.place" class="small text-decoration-none text-muted" :href="'/discover/places/'+status.place.id+'/'+status.place.slug" title="Location" data-toggle="tooltip"><i class="fas fa-map-marked-alt"></i> {{status.place.name}}, {{status.place.country}}</a>
  125. </div>
  126. </div>
  127. <div class="text-right" style="flex-grow:1;">
  128. <button class="btn btn-link text-dark py-0" type="button" @click="ctxMenu(status)">
  129. <span class="fas fa-ellipsis-h text-lighter"></span>
  130. <span class="sr-only">Post Menu</span>
  131. </button>
  132. </div>
  133. </div>
  134. <div class="postPresenterContainer" style="background: #000;">
  135. <div v-if="config.ab.top && status.pf_type === 'text'" class="w-100">
  136. <div class="w-100 card-img-top border-bottom rounded-0" style="background-image: url(/storage/textimg/bg_1.jpg);background-size: cover;width: 100%;height: 540px;">
  137. <div class="w-100 h-100 d-flex justify-content-center align-items-center">
  138. <p class="text-center text-break h3 px-5 font-weight-bold" v-html="status.content"></p>
  139. </div>
  140. </div>
  141. </div>
  142. <div v-else-if="status.pf_type === 'photo'" class="w-100">
  143. <photo-presenter :status="status" v-on:lightbox="lightbox"></photo-presenter>
  144. </div>
  145. <div v-else-if="status.pf_type === 'video'" class="w-100">
  146. <video-presenter :status="status"></video-presenter>
  147. </div>
  148. <div v-else-if="status.pf_type === 'photo:album'" class="w-100">
  149. <photo-album-presenter :status="status" v-on:lightbox="lightbox"></photo-album-presenter>
  150. </div>
  151. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  152. <video-album-presenter :status="status"></video-album-presenter>
  153. </div>
  154. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  155. <mixed-album-presenter :status="status" v-on:lightbox="lightbox"></mixed-album-presenter>
  156. </div>
  157. <div v-else class="w-100">
  158. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  159. </div>
  160. </div>
  161. <div v-if="config.features.label.covid.enabled && status.label && status.label.covid == true" class="card-body border-bottom py-2 cursor-pointer pr-2" @click="labelRedirect()">
  162. <p class="font-weight-bold d-flex justify-content-between align-items-center mb-0">
  163. <span>
  164. <i class="fas fa-info-circle mr-2"></i>
  165. For information about COVID-19, {{config.features.label.covid.org}}
  166. </span>
  167. <span>
  168. <i class="fas fa-chevron-right text-lighter"></i>
  169. </span>
  170. </p>
  171. </div>
  172. <div class="card-body">
  173. <div class="reactions my-1 pb-2">
  174. <h3 v-if="status.favourited" class="fas fa-heart text-danger pr-3 m-0 cursor-pointer" title="Like" v-on:click="likeStatus(status, $event);"></h3>
  175. <h3 v-else class="far fa-heart pr-3 m-0 like-btn text-lighter cursor-pointer" title="Like" v-on:click="likeStatus(status, $event);"></h3>
  176. <h3 v-if="!status.comments_disabled" class="far fa-comment text-lighter pr-3 m-0 cursor-pointer" title="Comment" v-on:click="commentFocus(status, $event)"></h3>
  177. <h3 v-if="status.visibility == 'public'" v-bind:class="[status.reblogged ? 'fas fa-retweet pr-3 m-0 text-primary cursor-pointer' : 'fas fa-retweet pr-3 m-0 text-lighter share-btn cursor-pointer']" title="Share" v-on:click="shareStatus(status, $event)"></h3>
  178. <h3 class="fas fa-expand pr-3 m-0 cursor-pointer text-lighter" v-on:click="lightbox(status)"></h3>
  179. <span v-if="status.taggedPeople.length" class="float-right">
  180. <span class="font-weight-light small" style="color:#718096">
  181. <i class="far fa-user" data-toggle="tooltip" title="Tagged People"></i>
  182. <span v-for="(tag, index) in status.taggedPeople" class="mr-n2">
  183. <a :href="'/'+tag.username">
  184. <img :src="tag.avatar" width="20px" height="20px" class="border rounded-circle" data-toggle="tooltip" :title="'@'+tag.username" alt="Avatar">
  185. </a>
  186. </span>
  187. </span>
  188. </span>
  189. </div>
  190. <div class="likes font-weight-bold" v-if="expLc(status) == true">
  191. <span class="like-count">{{status.favourites_count}}</span> {{status.favourites_count == 1 ? 'like' : 'likes'}}
  192. </div>
  193. <div v-if="status.pf_type != 'text'" class="caption">
  194. <p class="mb-2 read-more" style="overflow: hidden;">
  195. <span class="username font-weight-bold">
  196. <bdi><a class="text-dark" :href="profileUrl(status)">{{status.account.username}}</a></bdi>
  197. </span>
  198. <span class="status-content" v-html="status.content"></span>
  199. </p>
  200. </div>
  201. <div class="comments" v-if="status.id == replyId && !status.comments_disabled">
  202. <p class="mb-0 d-flex justify-content-between align-items-top read-more mt-2" style="overflow-y: hidden;" v-for="(reply, index) in replies">
  203. <span>
  204. <a class="text-dark font-weight-bold mr-1" :href="profileUrl(reply)">{{reply.account.username}}</a>
  205. <span v-html="reply.content" style="word-break: break-all;" class="comment-body"></span>
  206. </span>
  207. <span class="mb-0" style="min-width:38px">
  208. <span v-on:click="likeStatus(reply, $event);">
  209. <i v-bind:class="[reply.favourited ? 'fas fa-heart fa-sm text-danger cursor-pointer':'far fa-heart fa-sm text-lighter cursor-pointer']"></i>
  210. </span>
  211. <!-- <post-menu :status="reply" :profile="profile" size="sm" :modal="'true'" :feed="feed" class="d-inline-flex pl-2"></post-menu> -->
  212. <span class="text-lighter pl-2 cursor-pointer" @click="ctxMenu(reply)">
  213. <span class="fas fa-ellipsis-v text-lighter"></span>
  214. </span>
  215. </span>
  216. </p>
  217. </div>
  218. <div class="timestamp mt-2">
  219. <p class="small text-uppercase mb-0">
  220. <a :href="statusUrl(status)" class="text-muted">
  221. <timeago :datetime="status.created_at" :auto-update="60" :converter-options="{includeSeconds:true}" :title="timestampFormat(status.created_at)" v-b-tooltip.hover.bottom></timeago>
  222. </a>
  223. </p>
  224. </div>
  225. </div>
  226. <!--<div v-if="status.id == replyId && !status.comments_disabled" class="card-footer bg-white px-2 py-0">
  227. <ul class="nav align-items-center emoji-reactions" style="overflow-x: scroll;flex-wrap: unset;">
  228. <li class="nav-item" v-on:click="emojiReaction(status)" v-for="e in emoji">{{e}}</li>
  229. </ul>
  230. </div>-->
  231. <!--<div v-if="status.id == replyId && !status.comments_disabled" class="card-footer bg-white sticky-md-bottom p-0">
  232. <form class="border-0 rounded-0 align-middle" method="post" action="/i/comment" :data-id="status.id" data-truncate="false">
  233. <textarea class="form-control border-0 rounded-0" name="comment" placeholder="Add a comment…" autocomplete="off" autocorrect="off" style="height:56px;line-height: 18px;max-height:80px;resize: none; padding-right:4.2rem;" v-model="replyText"></textarea>
  234. <input type="button" value="Post" class="d-inline-block btn btn-link font-weight-bold reply-btn text-decoration-none" v-on:click.prevent="commentSubmit(status, $event)" :disabled="replyText.length == 0" />
  235. </form>
  236. </div>-->
  237. </div>
  238. </div>
  239. <div v-if="!loading && feed.length">
  240. <div class="card shadow-none">
  241. <div class="card-body">
  242. <infinite-loading @infinite="infiniteTimeline" :distance="800">
  243. <div slot="no-more" class="font-weight-bold">No more posts to load</div>
  244. <div slot="no-results" class="font-weight-bold">No more posts to load</div>
  245. </infinite-loading>
  246. </div>
  247. </div>
  248. </div>
  249. <div v-if="!loading && scope == 'home' && feed.length == 0">
  250. <div class="card shadow-none border">
  251. <div class="card-body text-center">
  252. <p class="h2 font-weight-lighter p-5">Hello, {{profile.acct}}</p>
  253. <p class="text-lighter"><i class="fas fa-camera-retro fa-5x"></i></p>
  254. <p class="h3 font-weight-lighter p-5">Start following people to build your timeline.</p>
  255. <p><a href="/discover" class="btn btn-primary font-weight-bold py-0">Discover new people and posts</a></p>
  256. </div>
  257. </div>
  258. </div>
  259. </div>
  260. </div>
  261. <div class="col-md-4 col-lg-4 my-4 order-1 order-md-2 d-none d-md-block">
  262. <div>
  263. <!-- <div class="mb-4">
  264. <a class="btn btn-block btn-primary btn-sm font-weight-bold mb-3 border" href="/i/compose" data-toggle="modal" data-target="#composeModal">
  265. <i class="far fa-plus-square pr-3 fa-lg pt-1"></i> New Post
  266. </a>
  267. </div> -->
  268. <div class="mb-4">
  269. <div v-show="!loading" class="">
  270. <div class="pb-2">
  271. <div class="media d-flex align-items-center">
  272. <a :href="!userStory ? profile.url : '/stories/' + profile.acct" class="mr-3">
  273. <!-- <img class="mr-3 rounded-circle box-shadow" :src="profile.avatar || '/storage/avatars/default.png'" alt="avatar" width="64px" height="64px" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'"> -->
  274. <div v-if="userStory" class="has-story cursor-pointer shadow-sm" @click="storyRedirect()">
  275. <img class="rounded-circle box-shadow" :src="profile.avatar" width="64px" height="64px" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'" alt="avatar">
  276. </div>
  277. <div v-else>
  278. <img class="rounded-circle box-shadow" :src="profile.avatar" width="64px" height="64px" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'" alt="avatar">
  279. </div>
  280. </a>
  281. <div class="media-body d-flex justify-content-between word-break" >
  282. <div>
  283. <p class="mb-0 px-0 font-weight-bold"><a :href="profile.url" class="text-dark">{{profile.username || 'loading...'}}</a></p>
  284. <p class="my-0 text-muted pb-0">{{profile.display_name || 'loading...'}}</p>
  285. </div>
  286. <div class="ml-2">
  287. <a class="text-muted" href="/settings/home">
  288. <i class="fas fa-cog fa-lg"></i>
  289. <span class="sr-only">User Settings</span>
  290. </a>
  291. </div>
  292. </div>
  293. </div>
  294. </div>
  295. <!-- <div class="card-footer bg-transparent border-top mt-2 py-1">
  296. <div class="d-flex justify-content-between text-center">
  297. <span class="cursor-pointer" @click="redirect(profile.url)">
  298. <p class="mb-0 font-weight-bold">{{formatCount(profile.statuses_count)}}</p>
  299. <p class="mb-0 small text-muted">Posts</p>
  300. </span>
  301. <span class="cursor-pointer" @click="redirect(profile.url+'?md=followers')">
  302. <p class="mb-0 font-weight-bold">{{formatCount(profile.followers_count)}}</p>
  303. <p class="mb-0 small text-muted">Followers</p>
  304. </span>
  305. <span class="cursor-pointer" @click="redirect(profile.url+'?md=following')">
  306. <p class="mb-0 font-weight-bold">{{formatCount(profile.following_count)}}</p>
  307. <p class="mb-0 small text-muted">Following</p>
  308. </span>
  309. </div>
  310. </div> -->
  311. </div>
  312. </div>
  313. <div v-show="modes.notify == true && !loading" class="mb-4">
  314. <notification-card></notification-card>
  315. </div>
  316. <div v-show="showSuggestions == true && suggestions.length && config.ab && config.ab.rec == true" class="mb-4">
  317. <div class="card shadow-none border">
  318. <div class="card-header bg-white d-flex align-items-center justify-content-between">
  319. <a class="small text-muted cursor-pointer" href="#" @click.prevent="refreshSuggestions" ref="suggestionRefresh"><i class="fas fa-sync-alt"></i></a>
  320. <div class="small text-dark text-uppercase font-weight-bold">Suggestions</div>
  321. <div class="small text-muted cursor-pointer" v-on:click="hideSuggestions"><i class="fas fa-times"></i></div>
  322. </div>
  323. <div class="card-body pt-0">
  324. <div v-for="(rec, index) in suggestions" class="media align-items-center mt-3">
  325. <a :href="'/'+rec.username">
  326. <img :src="rec.avatar" width="32px" height="32px" class="rounded-circle mr-3" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'" alt="avatar">
  327. </a>
  328. <div class="media-body">
  329. <p class="mb-0 font-weight-bold small">
  330. <a :href="'/'+rec.username" class="text-decoration-none text-dark">
  331. {{rec.username}}
  332. </a>
  333. </p>
  334. <p class="mb-0 small text-muted">{{rec.message}}</p>
  335. </div>
  336. <a class="font-weight-bold small" href="#" @click.prevent="expRecFollow(rec.id, index)">Follow</a>
  337. </div>
  338. </div>
  339. </div>
  340. </div>
  341. <footer>
  342. <div class="container pb-5">
  343. <p class="mb-0 text-uppercase font-weight-bold text-muted small">
  344. <a href="/site/about" class="text-dark pr-2">About</a>
  345. <a href="/site/help" class="text-dark pr-2">Help</a>
  346. <a href="/site/language" class="text-dark pr-2">Language</a>
  347. <a href="/discover/profiles" class="text-dark pr-2">Profiles</a>
  348. <a href="/discover/places" class="text-dark pr-2">Places</a>
  349. <a href="/site/privacy" class="text-dark pr-2">Privacy</a>
  350. <a href="/site/terms" class="text-dark pr-2">Terms</a>
  351. </p>
  352. <p class="mb-0 text-uppercase font-weight-bold text-muted small">
  353. <a href="http://pixelfed.org" class="text-muted" rel="noopener" title="" data-toggle="tooltip">Powered by Pixelfed</a>
  354. </p>
  355. </div>
  356. </footer>
  357. </div>
  358. </div>
  359. </div>
  360. <div v-else class="row">
  361. <div class="col-12">
  362. <!-- <div v-if="loading" class="text-center">
  363. <div class="spinner-border" role="status">
  364. <span class="sr-only">Loading...</span>
  365. </div>
  366. </div> -->
  367. <div class="row">
  368. <div class="col-12 pl-3 pl-md-0 pt-3 pl-0">
  369. <div class="d-flex justify-content-between align-items-center">
  370. <p class="lead text-muted mb-0"><i :class="[scope == 'home' ? 'fas fa-home':'fas fa-stream']"></i> &nbsp; {{scope == 'local' ? 'Public' : 'Home'}} Timeline</p>
  371. <p class="mb-0">
  372. <span class="btn-group">
  373. <a href="#" :class="[layout=='feed'?'btn btn-sm btn-outline-primary font-weight-bold text-decoration-none':'btn btn-sm btn-outline-lighter font-weight-light text-decoration-none']" @click.prevent="switchFeedLayout('feed')"><i class="fas fa-list"></i></a>
  374. <a href="#" :class="[layout!=='feed'?'btn btn-sm btn-outline-primary font-weight-bold text-decoration-none':'btn btn-sm btn-outline-lighter font-weight-light text-decoration-none']" @click.prevent="switchFeedLayout('grid')"><i class="fas fa-th"></i></a>
  375. </span>
  376. </p>
  377. <p class="mb-0 d-none d-md-block">
  378. <a class="btn btn-block btn-primary btn-sm font-weight-bold" href="/i/compose" data-toggle="modal" data-target="#composeModal">
  379. New Post
  380. </a>
  381. </p>
  382. </div>
  383. <hr>
  384. </div>
  385. <div class="col-12 col-md-4 p-1 p-md-3 mb-3" v-for="(s, index) in feed" :key="`${index}-${s.id}`">
  386. <a class="card info-overlay card-md-border-0 shadow-sm border border-light" :href="statusUrl(s)">
  387. <div :class="[s.sensitive ? 'square' : 'square ' + s.media_attachments[0].filter_class]">
  388. <span v-if="s.pf_type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  389. <span v-if="s.pf_type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  390. <span v-if="s.pf_type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  391. <div class="square-content" v-bind:style="previewBackground(s)">
  392. </div>
  393. <div class="info-overlay-text px-4">
  394. <p class="text-white m-auto text-center">
  395. {{trimCaption(s.content_text)}}
  396. </p>
  397. </div>
  398. </div>
  399. </a>
  400. <div class="py-3 media align-items-center">
  401. <a class="text-decoration-none" :href="s.account.url"><img :src="s.account.avatar" class="mr-3 rounded-circle shadow-sm" :alt="s.account.username + ' \'s avatar'" width="30px" height="30px" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'"></a>
  402. <div class="media-body">
  403. <p class="mb-0 font-weight-bold small"><a class="text-dark" :href="s.account.url">{{s.account.username}}</a></p>
  404. <p class="mb-0" style="line-height: 0.7;">
  405. <a :href="statusUrl(s)" class="small text-lighter">
  406. <timeago :datetime="s.created_at" :auto-update="60" :converter-options="{includeSeconds:true}" :title="timestampFormat(s.created_at)" v-b-tooltip.hover.bottom></timeago>
  407. </a>
  408. </p>
  409. </div>
  410. <div class="ml-3">
  411. <p class="mb-0">
  412. <span v-if="statusOwner(s)" class="font-weight-bold small">{{s.favourites_count == 1 ? '1 like' : s.favourites_count+' likes'}}</span>
  413. <span class="px-2"><i v-bind:class="[s.favourited ? 'fas fa-heart text-danger cursor-pointer' : 'far fa-heart like-btn text-lighter cursor-pointer']" v-on:click="likeStatus(s, $event);"></i></span>
  414. <span class="mr-2 cursor-pointer"><i class="fas fa-ellipsis-v" @click="ctxMenu(s)"></i></span>
  415. </p>
  416. </div>
  417. </div>
  418. </div>
  419. </div>
  420. <div v-if="!loading && feed.length">
  421. <infinite-loading @infinite="infiniteTimeline" :distance="800">
  422. <div slot="no-more" class="font-weight-bold">No more posts to load</div>
  423. <div slot="no-results" class="font-weight-bold">No more posts to load</div>
  424. </infinite-loading>
  425. </div>
  426. </div>
  427. </div>
  428. <b-modal ref="ctxModal"
  429. id="ctx-modal"
  430. hide-header
  431. hide-footer
  432. centered
  433. rounded
  434. size="sm"
  435. body-class="list-group-flush p-0 rounded">
  436. <div class="list-group text-center">
  437. <div v-if="ctxMenuStatus && ctxMenuStatus.account.id != profile.id" class="list-group-item rounded cursor-pointer font-weight-bold text-danger" @click="ctxMenuReportPost()">Report</div>
  438. <div v-if="ctxMenuStatus && ctxMenuStatus.account.id != profile.id && ctxMenuRelationship && ctxMenuRelationship.following" class="list-group-item rounded cursor-pointer font-weight-bold text-danger" @click="ctxMenuUnfollow()">Unfollow</div>
  439. <div v-if="ctxMenuStatus && ctxMenuStatus.account.id != profile.id && ctxMenuRelationship && !ctxMenuRelationship.following" class="list-group-item rounded cursor-pointer font-weight-bold text-primary" @click="ctxMenuFollow()">Follow</div>
  440. <div class="list-group-item rounded cursor-pointer" @click="ctxMenuGoToPost()">Go to post</div>
  441. <div v-if="ctxMenuStatus && ctxMenuStatus.local == true && !ctxMenuStatus.in_reply_to_id" class="list-group-item rounded cursor-pointer" @click="ctxMenuEmbed()">Embed</div>
  442. <!-- <div class="list-group-item rounded cursor-pointer" @click="ctxMenuShare()">Share</div> -->
  443. <div class="list-group-item rounded cursor-pointer" @click="ctxMenuCopyLink()">Copy Link</div>
  444. <div v-if="profile && profile.is_admin == true" class="list-group-item rounded cursor-pointer" @click="ctxModMenuShow()">Moderation Tools</div>
  445. <div v-if="ctxMenuStatus && (profile.is_admin || profile.id == ctxMenuStatus.account.id)" class="list-group-item rounded cursor-pointer" @click="deletePost(ctxMenuStatus)">Delete</div>
  446. <div class="list-group-item rounded cursor-pointer text-lighter" @click="closeCtxMenu()">Cancel</div>
  447. </div>
  448. </b-modal>
  449. <b-modal ref="ctxModModal"
  450. id="ctx-mod-modal"
  451. hide-header
  452. hide-footer
  453. centered
  454. rounded
  455. size="sm"
  456. body-class="list-group-flush p-0 rounded">
  457. <div class="list-group text-center">
  458. <div class="list-group-item rounded cursor-pointer" @click="moderatePost(ctxMenuStatus, 'unlist')">Unlist from Timelines</div>
  459. <div v-if="ctxMenuStatus.sensitive" class="list-group-item rounded cursor-pointer" @click="moderatePost(ctxMenuStatus, 'remcw')">Remove Content Warning</div>
  460. <div v-else class="list-group-item rounded cursor-pointer" @click="moderatePost(ctxMenuStatus, 'addcw')">Add Content Warning</div>
  461. <div class="list-group-item rounded cursor-pointer text-lighter" @click="ctxModMenuClose()">Cancel</div>
  462. </div>
  463. </b-modal>
  464. <b-modal ref="ctxShareModal"
  465. id="ctx-share-modal"
  466. title="Share"
  467. hide-footer
  468. centered
  469. rounded
  470. size="sm"
  471. body-class="list-group-flush p-0 rounded text-center">
  472. <div class="list-group-item rounded cursor-pointer border-top-0">Email</div>
  473. <div class="list-group-item rounded cursor-pointer">Facebook</div>
  474. <div class="list-group-item rounded cursor-pointer">Mastodon</div>
  475. <div class="list-group-item rounded cursor-pointer">Pinterest</div>
  476. <div class="list-group-item rounded cursor-pointer">Pixelfed</div>
  477. <div class="list-group-item rounded cursor-pointer">Twitter</div>
  478. <div class="list-group-item rounded cursor-pointer">VK</div>
  479. <div class="list-group-item rounded cursor-pointer text-lighter" @click="closeCtxShareMenu()">Cancel</div>
  480. </b-modal>
  481. <b-modal ref="ctxEmbedModal"
  482. id="ctx-embed-modal"
  483. hide-header
  484. hide-footer
  485. centered
  486. rounded
  487. size="md"
  488. body-class="p-2 rounded">
  489. <div>
  490. <div class="form-group">
  491. <textarea class="form-control disabled text-monospace" rows="8" style="overflow-y:hidden;border: 1px solid #efefef; font-size: 12px; line-height: 18px; margin: 0 0 7px;resize:none;" v-model="ctxEmbedPayload" disabled=""></textarea>
  492. </div>
  493. <div class="form-group pl-2 d-flex justify-content-center">
  494. <div class="form-check mr-3">
  495. <input class="form-check-input" type="checkbox" v-model="ctxEmbedShowCaption" :disabled="ctxEmbedCompactMode == true">
  496. <label class="form-check-label font-weight-light">
  497. Show Caption
  498. </label>
  499. </div>
  500. <div class="form-check mr-3">
  501. <input class="form-check-input" type="checkbox" v-model="ctxEmbedShowLikes" :disabled="ctxEmbedCompactMode == true">
  502. <label class="form-check-label font-weight-light">
  503. Show Likes
  504. </label>
  505. </div>
  506. <div class="form-check">
  507. <input class="form-check-input" type="checkbox" v-model="ctxEmbedCompactMode">
  508. <label class="form-check-label font-weight-light">
  509. Compact Mode
  510. </label>
  511. </div>
  512. </div>
  513. <hr>
  514. <button :class="copiedEmbed ? 'btn btn-primary btn-block btn-sm py-1 font-weight-bold disabed': 'btn btn-primary btn-block btn-sm py-1 font-weight-bold'" @click="ctxCopyEmbed" :disabled="copiedEmbed">{{copiedEmbed ? 'Embed Code Copied!' : 'Copy Embed Code'}}</button>
  515. <p class="mb-0 px-2 small text-muted">By using this embed, you agree to our <a href="/site/terms">Terms of Use</a></p>
  516. </div>
  517. </b-modal>
  518. <b-modal
  519. id="lightbox"
  520. ref="lightboxModal"
  521. hide-header
  522. hide-footer
  523. centered
  524. size="lg"
  525. body-class="p-0"
  526. >
  527. <div v-if="lightboxMedia" :class="lightboxMedia.filter_class" class="w-100 h-100">
  528. <img :src="lightboxMedia.url" style="max-height: 100%; max-width: 100%" alt="lightbox media">
  529. </div>
  530. </b-modal>
  531. <b-modal ref="replyModal"
  532. id="ctx-reply-modal"
  533. hide-footer
  534. centered
  535. rounded
  536. :title-html="replyStatus.account ? 'Reply to <span class=text-dark>' + replyStatus.account.username + '</span>' : ''"
  537. title-tag="p"
  538. title-class="font-weight-bold text-muted"
  539. size="md"
  540. body-class="p-2 rounded">
  541. <div>
  542. <textarea class="form-control" rows="4" style="border: none; font-size: 18px; resize: none; white-space: pre-wrap;outline: none;" placeholder="Reply here ..." v-model="replyText">
  543. </textarea>
  544. <div class="border-top border-bottom my-2">
  545. <ul class="nav align-items-center emoji-reactions" style="overflow-x: scroll;flex-wrap: unset;">
  546. <li class="nav-item" v-on:click="emojiReaction(status)" v-for="e in emoji">{{e}}</li>
  547. </ul>
  548. </div>
  549. <div class="d-flex justify-content-between align-items-center">
  550. <div>
  551. <span class="pl-2 small text-muted font-weight-bold text-monospace">
  552. <span :class="[replyText.length > config.uploader.max_caption_length ? 'text-danger':'text-dark']">{{replyText.length > config.uploader.max_caption_length ? config.uploader.max_caption_length - replyText.length : replyText.length}}</span>/{{config.uploader.max_caption_length}}
  553. </span>
  554. </div>
  555. <div class="d-flex align-items-center">
  556. <div class="custom-control custom-switch mr-3">
  557. <input type="checkbox" class="custom-control-input" id="replyModalCWSwitch" v-model="replyNsfw">
  558. <label :class="[replyNsfw ? 'custom-control-label font-weight-bold text-dark':'custom-control-label text-lighter']" for="replyModalCWSwitch">Mark as NSFW</label>
  559. </div>
  560. <!-- <select class="custom-select custom-select-sm my-0 mr-2">
  561. <option value="public" selected="">Public</option>
  562. <option value="unlisted">Unlisted</option>
  563. <option value="followers">Followers Only</option>
  564. </select> -->
  565. <button class="btn btn-primary btn-sm py-2 px-4 lead text-uppercase font-weight-bold" v-on:click.prevent="commentSubmit(status, $event)" :disabled="replyText.length == 0">
  566. {{replySending == true ? 'POSTING' : 'POST'}}
  567. </button>
  568. </div>
  569. </div>
  570. </div>
  571. </b-modal>
  572. </div>
  573. </template>
  574. <style type="text/css" scoped>
  575. .postPresenterContainer {
  576. display: flex;
  577. align-items: center;
  578. background: #fff;
  579. }
  580. .word-break {
  581. word-break: break-all;
  582. }
  583. .small .custom-control-label {
  584. padding-top: 3px;
  585. }
  586. .reply-btn {
  587. position: absolute;
  588. bottom: 12px;
  589. right: 20px;
  590. width: 60px;
  591. text-align: center;
  592. border-radius: 0 3px 3px 0;
  593. }
  594. .emoji-reactions .nav-item {
  595. font-size: 1.2rem;
  596. padding: 9px;
  597. cursor: pointer;
  598. }
  599. .emoji-reactions::-webkit-scrollbar {
  600. width: 0px;
  601. height: 0px;
  602. background: transparent;
  603. }
  604. .reply-btn[disabled] {
  605. opacity: .3;
  606. color: #3897f0;
  607. }
  608. .has-story {
  609. width: 64px;
  610. height: 64px;
  611. border-radius: 50%;
  612. padding: 2px;
  613. background: radial-gradient(ellipse at 70% 70%, #ee583f 8%, #d92d77 42%, #bd3381 58%);
  614. }
  615. .has-story img {
  616. width: 60px;
  617. height: 60px;
  618. border-radius: 50%;
  619. padding: 3px;
  620. background: #fff;
  621. }
  622. .has-story.has-story-sm {
  623. width: 32px;
  624. height: 32px;
  625. border-radius: 50%;
  626. padding: 2px;
  627. background: radial-gradient(ellipse at 70% 70%, #ee583f 8%, #d92d77 42%, #bd3381 58%);
  628. }
  629. .has-story.has-story-sm img {
  630. width: 28px;
  631. height: 28px;
  632. border-radius: 50%;
  633. padding: 3px;
  634. background: #fff;
  635. }
  636. #ctx-reply-modal .form-control:focus {
  637. border: none;
  638. outline: 0;
  639. box-shadow: none;
  640. }
  641. </style>
  642. <script type="text/javascript">
  643. export default {
  644. props: ['scope', 'layout'],
  645. data() {
  646. return {
  647. ids: [],
  648. config: window.App.config,
  649. page: 2,
  650. feed: [],
  651. profile: {},
  652. min_id: 0,
  653. max_id: 0,
  654. suggestions: {},
  655. loading: true,
  656. replies: [],
  657. replyId: null,
  658. modes: {
  659. 'mod': false,
  660. 'dark': false,
  661. 'notify': true,
  662. 'distractionFree': false
  663. },
  664. followers: [],
  665. followerCursor: 1,
  666. followerMore: true,
  667. following: [],
  668. followingCursor: 1,
  669. followingMore: true,
  670. lightboxMedia: false,
  671. showSuggestions: true,
  672. showReadMore: true,
  673. replyStatus: {},
  674. replyText: '',
  675. replyNsfw: false,
  676. emoji: window.App.util.emoji,
  677. showHashtagPosts: false,
  678. hashtagPosts: [],
  679. hashtagPostsName: '',
  680. ctxMenuStatus: false,
  681. ctxMenuRelationship: false,
  682. ctxEmbedPayload: false,
  683. copiedEmbed: false,
  684. showTips: true,
  685. userStory: false,
  686. replySending: false,
  687. ctxEmbedShowCaption: true,
  688. ctxEmbedShowLikes: false,
  689. ctxEmbedCompactMode: false,
  690. morePostsAvailable: false,
  691. mpCount: 0,
  692. mpData: false,
  693. mpInterval: 15000,
  694. mpEnabled: false,
  695. mpPoller: null
  696. }
  697. },
  698. watch: {
  699. ctxEmbedShowCaption: function (n,o) {
  700. if(n == true) {
  701. this.ctxEmbedCompactMode = false;
  702. }
  703. let mode = this.ctxEmbedCompactMode ? 'compact' : 'full';
  704. this.ctxEmbedPayload = window.App.util.embed.post(this.ctxMenuStatus.url, this.ctxEmbedShowCaption, this.ctxEmbedShowLikes, mode);
  705. },
  706. ctxEmbedShowLikes: function (n,o) {
  707. if(n == true) {
  708. this.ctxEmbedCompactMode = false;
  709. }
  710. let mode = this.ctxEmbedCompactMode ? 'compact' : 'full';
  711. this.ctxEmbedPayload = window.App.util.embed.post(this.ctxMenuStatus.url, this.ctxEmbedShowCaption, this.ctxEmbedShowLikes, mode);
  712. },
  713. ctxEmbedCompactMode: function (n,o) {
  714. if(n == true) {
  715. this.ctxEmbedShowCaption = false;
  716. this.ctxEmbedShowLikes = false;
  717. }
  718. let mode = this.ctxEmbedCompactMode ? 'compact' : 'full';
  719. this.ctxEmbedPayload = window.App.util.embed.post(this.ctxMenuStatus.url, this.ctxEmbedShowCaption, this.ctxEmbedShowLikes, mode);
  720. }
  721. },
  722. beforeMount() {
  723. this.fetchProfile();
  724. this.fetchTimelineApi();
  725. },
  726. mounted() {
  727. // todo: release after dark mode updates
  728. /* if(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches || $('link[data-stylesheet="dark"]').length != 0) {
  729. this.modes.dark = true;
  730. let el = document.querySelector('link[data-stylesheet="light"]');
  731. el.setAttribute('href', '/css/appdark.css?id=' + Date.now());
  732. el.setAttribute('data-stylesheet', 'dark');
  733. }*/
  734. if(localStorage.getItem('pf_metro_ui.exp.rec') == 'false') {
  735. this.showSuggestions = false;
  736. } else {
  737. this.showSuggestions = true;
  738. }
  739. if(localStorage.getItem('pf_metro_ui.exp.rm') == 'false') {
  740. this.showReadMore = false;
  741. } else {
  742. this.showReadMore = true;
  743. }
  744. if(localStorage.getItem('metro-tips') == 'false') {
  745. this.showTips = false;
  746. }
  747. this.$nextTick(function () {
  748. $('[data-toggle="tooltip"]').tooltip();
  749. let u = new URLSearchParams(window.location.search);
  750. if(u.has('a') && u.get('a') == 'co') {
  751. $('#composeModal').modal('show');
  752. }
  753. });
  754. },
  755. updated() {
  756. if(this.showReadMore == true) {
  757. pixelfed.readmore();
  758. }
  759. },
  760. methods: {
  761. fetchProfile() {
  762. axios.get('/api/pixelfed/v1/accounts/verify_credentials').then(res => {
  763. this.profile = res.data;
  764. if(this.profile.is_admin == true) {
  765. this.modes.mod = true;
  766. }
  767. window._sharedData.curUser = res.data;
  768. window.App.util.navatar();
  769. this.hasStory();
  770. // this.expRec();
  771. }).catch(err => {
  772. swal(
  773. 'Oops, something went wrong',
  774. 'Please reload the page.',
  775. 'error'
  776. );
  777. });
  778. },
  779. fetchTimelineApi() {
  780. let apiUrl = false;
  781. switch(this.scope) {
  782. case 'home':
  783. apiUrl = '/api/pixelfed/v1/timelines/home';
  784. break;
  785. case 'local':
  786. apiUrl = '/api/pixelfed/v1/timelines/public';
  787. break;
  788. case 'network':
  789. apiUrl = '/api/pixelfed/v1/timelines/network';
  790. break;
  791. }
  792. axios.get(apiUrl, {
  793. params: {
  794. max_id: this.max_id,
  795. limit: 3
  796. }
  797. }).then(res => {
  798. let data = res.data;
  799. this.feed.push(...data);
  800. let ids = data.map(status => status.id);
  801. this.ids = ids;
  802. this.min_id = Math.max(...ids).toString();
  803. this.max_id = Math.min(...ids).toString();
  804. this.loading = false;
  805. $('.timeline .pagination').removeClass('d-none');
  806. // if(this.feed.length == 4) {
  807. // this.fetchTimelineApi();
  808. // }
  809. if(this.hashtagPosts.length == 0) {
  810. this.fetchHashtagPosts();
  811. }
  812. // this.fetchStories();
  813. this.rtw();
  814. setTimeout(function() {
  815. document.querySelectorAll('.timeline .card-body .comments .comment-body a').forEach(function(i, e) {
  816. i.href = App.util.format.rewriteLinks(i);
  817. });
  818. }, 500);
  819. }).catch(err => {
  820. swal(
  821. 'Oops, something went wrong',
  822. 'Please reload the page.',
  823. 'error'
  824. );
  825. });
  826. },
  827. infiniteTimeline($state) {
  828. if(this.loading) {
  829. $state.complete();
  830. return;
  831. }
  832. if(this.page > 40) {
  833. this.loading = false;
  834. $state.complete();
  835. }
  836. let apiUrl = false;
  837. switch(this.scope) {
  838. case 'home':
  839. apiUrl = '/api/pixelfed/v1/timelines/home';
  840. break;
  841. case 'local':
  842. apiUrl = '/api/pixelfed/v1/timelines/public';
  843. break;
  844. case 'network':
  845. apiUrl = '/api/pixelfed/v1/timelines/network';
  846. break;
  847. }
  848. axios.get(apiUrl, {
  849. params: {
  850. max_id: this.max_id,
  851. limit: 6
  852. },
  853. }).then(res => {
  854. if (res.data.length && this.loading == false) {
  855. let data = res.data;
  856. let self = this;
  857. data.forEach((d, index) => {
  858. if(self.ids.indexOf(d.id) == -1) {
  859. self.feed.push(d);
  860. self.ids.push(d.id);
  861. axios.post('/api/status/view', {
  862. 'status_id': d.id,
  863. 'profile_id': d.account.id
  864. });
  865. }
  866. });
  867. this.min_id = Math.max(...this.ids).toString();
  868. this.max_id = Math.min(...this.ids).toString();
  869. this.page += 1;
  870. $state.loaded();
  871. this.loading = false;
  872. } else {
  873. $state.complete();
  874. }
  875. }).catch(err => {
  876. this.loading = false;
  877. $state.complete();
  878. });
  879. },
  880. reportUrl(status) {
  881. let type = status.in_reply_to ? 'comment' : 'post';
  882. let id = status.id;
  883. return '/i/report?type=' + type + '&id=' + id;
  884. },
  885. commentFocus(status, $event) {
  886. if(status.comments_disabled) {
  887. return;
  888. }
  889. if(this.status && this.status.id == status.id) {
  890. this.$refs.replyModal.show();
  891. return;
  892. }
  893. this.status = status;
  894. this.replies = {};
  895. this.replyStatus = {};
  896. this.replyText = '';
  897. this.replyId = status.id;
  898. this.replyStatus = status;
  899. this.$refs.replyModal.show();
  900. this.fetchStatusComments(status, '');
  901. return;
  902. },
  903. likeStatus(status, event) {
  904. if($('body').hasClass('loggedIn') == false) {
  905. return;
  906. }
  907. let count = status.favourites_count;
  908. status.favourited = !status.favourited;
  909. axios.post('/i/like', {
  910. item: status.id
  911. }).then(res => {
  912. status.favourites_count = res.data.count;
  913. }).catch(err => {
  914. status.favourited = !status.favourited;
  915. status.favourites_count = count;
  916. swal('Error', 'Something went wrong, please try again later.', 'error');
  917. });
  918. window.navigator.vibrate(200);
  919. if(status.favourited) {
  920. setTimeout(function() {
  921. event.target.classList.add('animate__animated', 'animate__bounce');
  922. },100);
  923. }
  924. },
  925. shareStatus(status, $event) {
  926. if($('body').hasClass('loggedIn') == false) {
  927. return;
  928. }
  929. axios.post('/i/share', {
  930. item: status.id
  931. }).then(res => {
  932. status.reblogs_count = res.data.count;
  933. status.reblogged = !status.reblogged;
  934. }).catch(err => {
  935. swal('Error', 'Something went wrong, please try again later.', 'error');
  936. });
  937. },
  938. timestampFormat(timestamp) {
  939. let ts = new Date(timestamp);
  940. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  941. },
  942. redirect(url) {
  943. window.location.href = url;
  944. return;
  945. },
  946. statusOwner(status) {
  947. let sid = status.account.id;
  948. let uid = this.profile.id;
  949. if(sid == uid) {
  950. return true;
  951. } else {
  952. return false;
  953. }
  954. },
  955. fetchStatusComments(status, card) {
  956. axios.get('/api/v2/status/'+status.id+'/replies')
  957. .then(res => {
  958. let data = res.data.filter(res => {
  959. return res.sensitive == false;
  960. });
  961. this.replies = _.reverse(data);
  962. setTimeout(function() {
  963. document.querySelectorAll('.timeline .card-body .comments .comment-body a').forEach(function(i, e) {
  964. i.href = App.util.format.rewriteLinks(i);
  965. });
  966. }, 500);
  967. }).catch(err => {
  968. })
  969. },
  970. muteProfile(status) {
  971. if($('body').hasClass('loggedIn') == false) {
  972. return;
  973. }
  974. axios.post('/i/mute', {
  975. type: 'user',
  976. item: status.account.id
  977. }).then(res => {
  978. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  979. swal('Success', 'You have successfully muted ' + status.account.acct, 'success');
  980. }).catch(err => {
  981. swal('Error', 'Something went wrong. Please try again later.', 'error');
  982. });
  983. },
  984. blockProfile(status) {
  985. if($('body').hasClass('loggedIn') == false) {
  986. return;
  987. }
  988. axios.post('/i/block', {
  989. type: 'user',
  990. item: status.account.id
  991. }).then(res => {
  992. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  993. swal('Success', 'You have successfully blocked ' + status.account.acct, 'success');
  994. }).catch(err => {
  995. swal('Error', 'Something went wrong. Please try again later.', 'error');
  996. });
  997. },
  998. deletePost(status) {
  999. if($('body').hasClass('loggedIn') == false || this.ownerOrAdmin(status) == false) {
  1000. return;
  1001. }
  1002. if(window.confirm('Are you sure you want to delete this post?') == false) {
  1003. return;
  1004. }
  1005. axios.post('/i/delete', {
  1006. type: 'status',
  1007. item: status.id
  1008. }).then(res => {
  1009. this.feed = this.feed.filter(s => {
  1010. return s.id != status.id;
  1011. });
  1012. this.$refs.ctxModal.hide();
  1013. }).catch(err => {
  1014. swal('Error', 'Something went wrong. Please try again later.', 'error');
  1015. });
  1016. },
  1017. commentSubmit(status, $event) {
  1018. this.replySending = true;
  1019. let id = status.id;
  1020. let comment = this.replyText;
  1021. let limit = this.config.uploader.max_caption_length;
  1022. if(comment.length > limit) {
  1023. this.replySending = false;
  1024. swal('Comment Too Long', 'Please make sure your comment is '+limit+' characters or less.', 'error');
  1025. return;
  1026. }
  1027. axios.post('/i/comment', {
  1028. item: id,
  1029. comment: comment,
  1030. sensitive: this.replyNsfw
  1031. }).then(res => {
  1032. this.replyText = '';
  1033. this.replies.unshift(res.data.entity);
  1034. this.$refs.replyModal.hide();
  1035. });
  1036. this.replySending = false;
  1037. },
  1038. moderatePost(status, action, $event) {
  1039. let username = status.account.username;
  1040. let msg = '';
  1041. let self = this;
  1042. switch(action) {
  1043. case 'addcw':
  1044. msg = 'Are you sure you want to add a content warning to this post?';
  1045. swal({
  1046. title: 'Confirm',
  1047. text: msg,
  1048. icon: 'warning',
  1049. buttons: true,
  1050. dangerMode: true
  1051. }).then(res => {
  1052. if(res) {
  1053. axios.post('/api/v2/moderator/action', {
  1054. action: action,
  1055. item_id: status.id,
  1056. item_type: 'status'
  1057. }).then(res => {
  1058. swal('Success', 'Successfully added content warning', 'success');
  1059. status.sensitive = true;
  1060. self.ctxModMenuClose();
  1061. }).catch(err => {
  1062. swal(
  1063. 'Error',
  1064. 'Something went wrong, please try again later.',
  1065. 'error'
  1066. );
  1067. self.ctxModMenuClose();
  1068. });
  1069. }
  1070. });
  1071. break;
  1072. case 'remcw':
  1073. msg = 'Are you sure you want to remove the content warning on this post?';
  1074. swal({
  1075. title: 'Confirm',
  1076. text: msg,
  1077. icon: 'warning',
  1078. buttons: true,
  1079. dangerMode: true
  1080. }).then(res => {
  1081. if(res) {
  1082. axios.post('/api/v2/moderator/action', {
  1083. action: action,
  1084. item_id: status.id,
  1085. item_type: 'status'
  1086. }).then(res => {
  1087. swal('Success', 'Successfully added content warning', 'success');
  1088. status.sensitive = false;
  1089. self.ctxModMenuClose();
  1090. }).catch(err => {
  1091. swal(
  1092. 'Error',
  1093. 'Something went wrong, please try again later.',
  1094. 'error'
  1095. );
  1096. self.ctxModMenuClose();
  1097. });
  1098. }
  1099. });
  1100. break;
  1101. case 'unlist':
  1102. msg = 'Are you sure you want to unlist this post?';
  1103. swal({
  1104. title: 'Confirm',
  1105. text: msg,
  1106. icon: 'warning',
  1107. buttons: true,
  1108. dangerMode: true
  1109. }).then(res => {
  1110. if(res) {
  1111. axios.post('/api/v2/moderator/action', {
  1112. action: action,
  1113. item_id: status.id,
  1114. item_type: 'status'
  1115. }).then(res => {
  1116. this.feed = this.feed.filter(f => {
  1117. return f.id != status.id;
  1118. });
  1119. swal('Success', 'Successfully unlisted post', 'success');
  1120. self.ctxModMenuClose();
  1121. }).catch(err => {
  1122. self.ctxModMenuClose();
  1123. swal(
  1124. 'Error',
  1125. 'Something went wrong, please try again later.',
  1126. 'error'
  1127. );
  1128. });
  1129. }
  1130. });
  1131. break;
  1132. }
  1133. },
  1134. followingModal() {
  1135. if(this.following.length > 0) {
  1136. this.$refs.followingModal.show();
  1137. return;
  1138. }
  1139. axios.get('/api/pixelfed/v1/accounts/'+this.profile.id+'/following', {
  1140. params: {
  1141. page: this.followingCursor
  1142. }
  1143. })
  1144. .then(res => {
  1145. this.following = res.data;
  1146. this.followingCursor++;
  1147. });
  1148. if(res.data.length < 10) {
  1149. this.followingMore = false;
  1150. }
  1151. this.$refs.followingModal.show();
  1152. },
  1153. followersModal() {
  1154. if(this.followers.length > 0) {
  1155. this.$refs.followerModal.show();
  1156. return;
  1157. }
  1158. axios.get('/api/pixelfed/v1/accounts/'+this.profile.id+'/followers', {
  1159. params: {
  1160. page: this.followerCursor
  1161. }
  1162. })
  1163. .then(res => {
  1164. this.followers = res.data;
  1165. this.followerCursor++;
  1166. })
  1167. if(res.data.length < 10) {
  1168. this.followerMore = false;
  1169. }
  1170. this.$refs.followerModal.show();
  1171. },
  1172. followingLoadMore() {
  1173. axios.get('/api/pixelfed/v1/accounts/'+this.profile.id+'/following', {
  1174. params: {
  1175. page: this.followingCursor
  1176. }
  1177. })
  1178. .then(res => {
  1179. if(res.data.length > 0) {
  1180. this.following.push(...res.data);
  1181. this.followingCursor++;
  1182. }
  1183. if(res.data.length < 10) {
  1184. this.followingMore = false;
  1185. }
  1186. });
  1187. },
  1188. followersLoadMore() {
  1189. axios.get('/api/pixelfed/v1/accounts/'+this.profile.id+'/followers', {
  1190. params: {
  1191. page: this.followerCursor
  1192. }
  1193. })
  1194. .then(res => {
  1195. if(res.data.length > 0) {
  1196. this.followers.push(...res.data);
  1197. this.followerCursor++;
  1198. }
  1199. if(res.data.length < 10) {
  1200. this.followerMore = false;
  1201. }
  1202. });
  1203. },
  1204. lightbox(status) {
  1205. window.location.href = status.media_attachments[0].url;
  1206. return;
  1207. this.lightboxMedia = status.media_attachments[0];
  1208. this.$refs.lightboxModal.show();
  1209. },
  1210. expLc(status) {
  1211. if(this.config.ab.lc == false) {
  1212. return true;
  1213. }
  1214. if(this.statusOwner(status) == true) {
  1215. return true;
  1216. }
  1217. return false;
  1218. },
  1219. expRec() {
  1220. //return;
  1221. if(this.config.ab.rec == false) {
  1222. return;
  1223. }
  1224. axios.get('/api/local/exp/rec')
  1225. .then(res => {
  1226. this.suggestions = res.data;
  1227. })
  1228. },
  1229. expRecFollow(id, index) {
  1230. return;
  1231. if(this.config.ab.rec == false) {
  1232. return;
  1233. }
  1234. axios.post('/i/follow', {
  1235. item: id
  1236. }).then(res => {
  1237. this.suggestions.splice(index, 1);
  1238. }).catch(err => {
  1239. if(err.response.data.message) {
  1240. swal('Error', err.response.data.message, 'error');
  1241. }
  1242. });
  1243. },
  1244. followAction(status) {
  1245. let id = status.account.id;
  1246. axios.post('/i/follow', {
  1247. item: id
  1248. }).then(res => {
  1249. this.feed.forEach(s => {
  1250. if(s.account.id == id) {
  1251. s.account.relationship.following = !s.account.relationship.following;
  1252. }
  1253. });
  1254. let username = status.account.acct;
  1255. if(status.account.relationship.following) {
  1256. swal('Follow successful!', 'You are now following ' + username, 'success');
  1257. } else {
  1258. swal('Unfollow successful!', 'You are no longer following ' + username, 'success');
  1259. }
  1260. }).catch(err => {
  1261. if(err.response.data.message) {
  1262. swal('Error', err.response.data.message, 'error');
  1263. }
  1264. });
  1265. },
  1266. owner(status) {
  1267. return this.profile.id === status.account.id;
  1268. },
  1269. admin() {
  1270. return this.profile.is_admin == true;
  1271. },
  1272. ownerOrAdmin(status) {
  1273. return this.owner(status) || this.admin();
  1274. },
  1275. hideSuggestions() {
  1276. localStorage.setItem('pf_metro_ui.exp.rec', false);
  1277. this.showSuggestions = false;
  1278. },
  1279. emojiReaction(status) {
  1280. let em = event.target.innerText;
  1281. if(this.replyText.length == 0) {
  1282. this.replyText = em + ' ';
  1283. $('textarea[name="comment"]').focus();
  1284. } else {
  1285. this.replyText += em + ' ';
  1286. $('textarea[name="comment"]').focus();
  1287. }
  1288. },
  1289. refreshSuggestions() {
  1290. return;
  1291. let el = event.target.parentNode;
  1292. if(el.classList.contains('disabled') == true) {
  1293. return;
  1294. }
  1295. axios.get('/api/local/exp/rec', {
  1296. params: {
  1297. refresh: true
  1298. }
  1299. })
  1300. .then(res => {
  1301. this.suggestions = res.data;
  1302. if (el.classList) {
  1303. el.classList.add('disabled');
  1304. el.classList.add('text-light');
  1305. }
  1306. else {
  1307. el.className += ' ' + 'disabled text-light';
  1308. }
  1309. setTimeout(function() {
  1310. el.setAttribute('href', '#');
  1311. if (el.classList) {
  1312. el.classList.remove('disabled');
  1313. el.classList.remove('text-light');
  1314. }
  1315. else {
  1316. el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), 'disabled text-light');
  1317. }
  1318. }, 10000);
  1319. });
  1320. },
  1321. fetchHashtagPosts() {
  1322. axios.get('/api/local/discover/tag/list')
  1323. .then(res => {
  1324. let tags = res.data;
  1325. if(tags.length == 0) {
  1326. return;
  1327. }
  1328. let hashtag = tags[Math.floor(Math.random(), tags.length)];
  1329. this.hashtagPostsName = hashtag;
  1330. axios.get('/api/v2/discover/tag', {
  1331. params: {
  1332. hashtag: hashtag
  1333. }
  1334. }).then(res => {
  1335. if(res.data.tags.length > 3) {
  1336. this.showHashtagPosts = true;
  1337. this.hashtagPosts = res.data.tags.splice(0,3);
  1338. }
  1339. })
  1340. })
  1341. },
  1342. ctxMenu(status) {
  1343. this.ctxMenuStatus = status;
  1344. this.ctxEmbedPayload = window.App.util.embed.post(status.url);
  1345. if(status.account.id == this.profile.id) {
  1346. this.ctxMenuRelationship = false;
  1347. this.$refs.ctxModal.show();
  1348. } else {
  1349. axios.get('/api/pixelfed/v1/accounts/relationships', {
  1350. params: {
  1351. 'id[]': status.account.id
  1352. }
  1353. }).then(res => {
  1354. this.ctxMenuRelationship = res.data[0];
  1355. this.$refs.ctxModal.show();
  1356. });
  1357. }
  1358. },
  1359. closeCtxMenu(truncate) {
  1360. this.copiedEmbed = false;
  1361. this.ctxMenuStatus = false;
  1362. this.ctxMenuRelationship = false;
  1363. this.$refs.ctxModal.hide();
  1364. },
  1365. ctxMenuCopyLink() {
  1366. let status = this.ctxMenuStatus;
  1367. navigator.clipboard.writeText(status.url);
  1368. this.closeCtxMenu();
  1369. return;
  1370. },
  1371. ctxMenuGoToPost() {
  1372. let status = this.ctxMenuStatus;
  1373. window.location.href = this.statusUrl(status);
  1374. this.closeCtxMenu();
  1375. return;
  1376. },
  1377. ctxMenuFollow() {
  1378. let id = this.ctxMenuStatus.account.id;
  1379. axios.post('/i/follow', {
  1380. item: id
  1381. }).then(res => {
  1382. let username = this.ctxMenuStatus.account.acct;
  1383. this.closeCtxMenu();
  1384. setTimeout(function() {
  1385. swal('Follow successful!', 'You are now following ' + username, 'success');
  1386. }, 500);
  1387. });
  1388. },
  1389. ctxMenuUnfollow() {
  1390. let id = this.ctxMenuStatus.account.id;
  1391. axios.post('/i/follow', {
  1392. item: id
  1393. }).then(res => {
  1394. let username = this.ctxMenuStatus.account.acct;
  1395. if(this.scope == 'home') {
  1396. this.feed = this.feed.filter(s => {
  1397. return s.account.id != this.ctxMenuStatus.account.id;
  1398. });
  1399. }
  1400. this.closeCtxMenu();
  1401. setTimeout(function() {
  1402. swal('Unfollow successful!', 'You are no longer following ' + username, 'success');
  1403. }, 500);
  1404. });
  1405. },
  1406. ctxMenuReportPost() {
  1407. window.location.href = '/i/report?type=post&id=' + this.ctxMenuStatus.id;
  1408. },
  1409. ctxMenuEmbed() {
  1410. this.$refs.ctxModal.hide();
  1411. this.$refs.ctxEmbedModal.show();
  1412. },
  1413. ctxMenuShare() {
  1414. this.$refs.ctxModal.hide();
  1415. this.$refs.ctxShareModal.show();
  1416. },
  1417. closeCtxShareMenu() {
  1418. this.$refs.ctxShareModal.hide();
  1419. this.$refs.ctxModal.show();
  1420. },
  1421. ctxCopyEmbed() {
  1422. navigator.clipboard.writeText(this.ctxEmbedPayload);
  1423. this.ctxEmbedShowCaption = true;
  1424. this.ctxEmbedShowLikes = false;
  1425. this.ctxEmbedCompactMode = false;
  1426. this.$refs.ctxEmbedModal.hide();
  1427. },
  1428. ctxModMenuShow() {
  1429. this.$refs.ctxModal.hide();
  1430. this.$refs.ctxModModal.show();
  1431. },
  1432. ctxModMenu() {
  1433. this.$refs.ctxModal.hide();
  1434. },
  1435. ctxModMenuClose() {
  1436. this.$refs.ctxModal.hide();
  1437. this.$refs.ctxModModal.hide();
  1438. },
  1439. formatCount(count) {
  1440. return App.util.format.count(count);
  1441. },
  1442. statusUrl(status) {
  1443. if(status.local == true) {
  1444. return status.url;
  1445. }
  1446. return '/i/web/post/_/' + status.account.id + '/' + status.id;
  1447. },
  1448. profileUrl(status) {
  1449. if(status.local == true) {
  1450. return status.account.url;
  1451. }
  1452. return '/i/web/profile/_/' + status.account.id;
  1453. },
  1454. statusCardUsernameFormat(status) {
  1455. if(status.account.local == true) {
  1456. return status.account.username;
  1457. }
  1458. let fmt = window.App.config.username.remote.format;
  1459. let txt = window.App.config.username.remote.custom;
  1460. let usr = status.account.username;
  1461. let dom = document.createElement('a');
  1462. dom.href = status.account.url;
  1463. dom = dom.hostname;
  1464. switch(fmt) {
  1465. case '@':
  1466. return usr + '<span class="text-lighter font-weight-bold">@' + dom + '</span>';
  1467. break;
  1468. case 'from':
  1469. return usr + '<span class="text-lighter font-weight-bold"> <span class="font-weight-normal">from</span> ' + dom + '</span>';
  1470. break;
  1471. case 'custom':
  1472. return usr + '<span class="text-lighter font-weight-bold"> ' + txt + ' ' + dom + '</span>';
  1473. break;
  1474. default:
  1475. return usr + '<span class="text-lighter font-weight-bold">@' + dom + '</span>';
  1476. break;
  1477. }
  1478. },
  1479. previewUrl(status) {
  1480. return status.sensitive ? '/storage/no-preview.png?v=' + new Date().getTime() : status.media_attachments[0].preview_url;
  1481. },
  1482. previewBackground(status) {
  1483. let preview = this.previewUrl(status);
  1484. return 'background-image: url(' + preview + ');';
  1485. },
  1486. trimCaption(caption, len = 60) {
  1487. return _.truncate(caption, {
  1488. length: len
  1489. });
  1490. },
  1491. hasStory() {
  1492. axios.get('/api/stories/v0/exists/'+this.profile.id)
  1493. .then(res => {
  1494. this.userStory = res.data;
  1495. })
  1496. },
  1497. // real time watcher
  1498. rtw() {
  1499. this.mpPoller = setInterval(() => {
  1500. let apiUrl = false;
  1501. this.mpCount++;
  1502. if(this.mpCount > 10) {
  1503. this.mpInterval = 30000;
  1504. }
  1505. if(this.mpCount > 50) {
  1506. this.mpInterval = (5 * 60 * 1000);
  1507. }
  1508. switch(this.scope) {
  1509. case 'home':
  1510. apiUrl = '/api/pixelfed/v1/timelines/home';
  1511. break;
  1512. case 'local':
  1513. apiUrl = '/api/pixelfed/v1/timelines/public';
  1514. break;
  1515. case 'network':
  1516. apiUrl = '/api/pixelfed/v1/timelines/network';
  1517. break;
  1518. }
  1519. axios.get(apiUrl, {
  1520. params: {
  1521. max_id: 0,
  1522. limit: 20
  1523. }
  1524. }).then(res => {
  1525. let self = this;
  1526. let tids = this.feed.map(status => status.id);
  1527. let data = res.data.filter(d => {
  1528. return d.id > self.min_id && tids.indexOf(d.id) == -1;
  1529. });
  1530. let ids = data.map(status => status.id);
  1531. let max = Math.max(...ids).toString();
  1532. let newer = max > this.min_id;
  1533. if(newer) {
  1534. this.morePostsAvailable = true;
  1535. this.mpData = data;
  1536. }
  1537. });
  1538. }, this.mpInterval);
  1539. },
  1540. syncNewPosts() {
  1541. let self = this;
  1542. let data = this.mpData;
  1543. let ids = data.map(s => s.id);
  1544. this.min_id = Math.max(...ids).toString();
  1545. this.max_id = Math.min(...ids).toString();
  1546. this.feed.unshift(...data);
  1547. this.morePostsAvailable = false;
  1548. this.mpData = null;
  1549. },
  1550. switchFeedLayout(toggle) {
  1551. this.loading = true;
  1552. this.layout = toggle;
  1553. let self = this;
  1554. setTimeout(function() {
  1555. self.loading = false;
  1556. }, 500);
  1557. },
  1558. labelRedirect(type) {
  1559. let url = '/i/redirect?url=' + encodeURI(this.config.features.label.covid.url);
  1560. window.location.href = url;
  1561. }
  1562. },
  1563. beforeDestroy () {
  1564. clearInterval(this.mpInterval);
  1565. },
  1566. }
  1567. </script>