PostComponent.vue 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461
  1. <template>
  2. <div>
  3. <div v-if="!loaded" style="height: 80vh;" class="d-flex justify-content-center align-items-center">
  4. <img src="/img/pixelfed-icon-grey.svg" class="">
  5. </div>
  6. <div v-if="loaded && warning" class="bg-white mt-n4 pt-3 border-bottom">
  7. <div class="container">
  8. <p class="text-center font-weight-bold">You are blocking this account</p>
  9. <p class="text-center font-weight-bold"><a href="#" class="btn btn-primary font-weight-bold px-5" @click.prevent="warning = false; fetchData()">View Status</a></p>
  10. </div>
  11. </div>
  12. <div v-if="loaded && warning == false" class="postComponent">
  13. <div v-if="layout == 'metro'" class="container px-0">
  14. <div class="card card-md-rounded-0 status-container orientation-unknown shadow-none border">
  15. <div class="row px-0 mx-0">
  16. <div class="d-flex d-md-none align-items-center justify-content-between card-header bg-white w-100">
  17. <div class="d-flex">
  18. <div class="status-avatar mr-2" @click="redirect(statusProfileUrl)">
  19. <img :src="statusAvatar" width="24px" height="24px" style="border-radius:12px;" class="cursor-pointer">
  20. </div>
  21. <div class="username">
  22. <span class="username-link font-weight-bold text-dark cursor-pointer" @click="redirect(statusProfileUrl)">{{ statusUsername }}</span>
  23. <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;">
  24. <i class="fas fa-certificate text-danger fa-stack-1x"></i>
  25. <i class="fas fa-crown text-white fa-sm fa-stack-1x" style="font-size:7px;"></i>
  26. </span>
  27. <p class="mb-0" style="font-size: 10px;">
  28. <span v-if="loaded && status.taggedPeople.length" class="mb-0">
  29. <span class="font-weight-light cursor-pointer" style="color:#718096" title="Tagged People" data-toggle="tooltip" data-placement="bottom" @click="showTaggedPeopleModal()"><i class="fas fa-tag text-lighter"></i> <span class="font-weight-bold">{{status.taggedPeople.length}} Tagged People</span></span>
  30. </span>
  31. <span v-if="loaded && status.place != null && status.taggedPeople.length" class="px-2 font-weight-bold text-lighter">&#8226;</span>
  32. <span v-if="loaded && status.place != null" class="mb-0 cursor-pointer text-truncate" style="color:#718096" @click="redirect('/discover/places/' + status.place.id + '/' + status.place.slug)"><i class="fas fa-map-marked-alt text-lighter"></i> <span class="font-weight-bold">{{status.place.name}}, {{status.place.country}}</span></span>
  33. </p>
  34. </div>
  35. </div>
  36. <div v-if="user != false" class="float-right">
  37. <div class="post-actions">
  38. <div class="dropdown">
  39. <button class="btn btn-link text-dark no-caret dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="Post options">
  40. <span class="fas fa-ellipsis-v text-muted"></span>
  41. </button>
  42. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
  43. <a class="dropdown-item font-weight-bold" @click="showEmbedPostModal()">Embed</a>
  44. <div v-if="!owner()">
  45. <a class="dropdown-item font-weight-bold" :href="reportUrl()">Report</a>
  46. <a class="dropdown-item font-weight-bold" v-on:click="muteProfile()">Mute Profile</a>
  47. <a class="dropdown-item font-weight-bold" v-on:click="blockProfile()">Block Profile</a>
  48. </div>
  49. <div v-if="ownerOrAdmin()">
  50. <a class="dropdown-item font-weight-bold" href="#" v-on:click.prevent="toggleCommentVisibility">{{ showComments ? 'Disable' : 'Enable'}} Comments</a>
  51. <a v-if="canEdit" class="dropdown-item font-weight-bold" :href="editUrl()">Edit</a>
  52. <a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost(status)">Delete</a>
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. </div>
  58. </div>
  59. <div class="col-12 col-md-8 px-0 mx-0">
  60. <div class="postPresenterContainer d-none d-flex justify-content-center align-items-center" style="background: #000;">
  61. <div v-if="status.pf_type === 'photo'" class="w-100">
  62. <photo-presenter :status="status" v-on:lightbox="lightbox"></photo-presenter>
  63. </div>
  64. <div v-else-if="status.pf_type === 'video'" class="w-100">
  65. <video-presenter :status="status"></video-presenter>
  66. </div>
  67. <div v-else-if="status.pf_type === 'photo:album'" class="w-100">
  68. <photo-album-presenter :status="status" v-on:lightbox="lightbox"></photo-album-presenter>
  69. </div>
  70. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  71. <video-album-presenter :status="status"></video-album-presenter>
  72. </div>
  73. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  74. <mixed-album-presenter :status="status" v-on:lightbox="lightbox"></mixed-album-presenter>
  75. </div>
  76. <div v-else class="w-100">
  77. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  78. </div>
  79. </div>
  80. </div>
  81. <div class="col-12 col-md-4 px-0 d-flex flex-column border-left border-md-left-0">
  82. <div class="d-md-flex d-none align-items-center justify-content-between card-header py-3 bg-white">
  83. <div class="d-flex align-items-center status-username text-truncate">
  84. <div class="status-avatar mr-2" @click="redirect(statusProfileUrl)">
  85. <img :src="statusAvatar" width="24px" height="24px" style="border-radius:12px;" class="cursor-pointer">
  86. </div>
  87. <div class="username">
  88. <span class="username-link font-weight-bold text-dark cursor-pointer" @click="redirect(statusProfileUrl)">{{ statusUsername }}</span>
  89. <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;">
  90. <i class="fas fa-certificate text-danger fa-stack-1x"></i>
  91. <i class="fas fa-crown text-white fa-sm fa-stack-1x" style="font-size:7px;"></i>
  92. </span>
  93. <p class="mb-0" style="font-size: 10px;">
  94. <span v-if="loaded && status.taggedPeople.length" class="mb-0">
  95. <span class="font-weight-light cursor-pointer" style="color:#718096" title="Tagged People" data-toggle="tooltip" data-placement="bottom" @click="showTaggedPeopleModal()"><i class="fas fa-tag text-lighter"></i> <span class="font-weight-bold">{{status.taggedPeople.length}} Tagged People</span></span>
  96. </span>
  97. <span v-if="loaded && status.place != null && status.taggedPeople.length" class="px-2 font-weight-bold text-lighter">&#8226;</span>
  98. <span v-if="loaded && status.place != null" class="mb-0 cursor-pointer text-truncate" style="color:#718096" @click="redirect('/discover/places/' + status.place.id + '/' + status.place.slug)"><i class="fas fa-map-marked-alt text-lighter"></i> <span class="font-weight-bold">{{status.place.name}}, {{status.place.country}}</span></span>
  99. </p>
  100. </div>
  101. </div>
  102. <div class="float-right">
  103. <div class="post-actions">
  104. <div v-if="user != false" class="dropdown">
  105. <button class="btn btn-link text-dark no-caret dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="Post options">
  106. <span class="fas fa-ellipsis-v text-muted"></span>
  107. </button>
  108. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
  109. <a class="dropdown-item font-weight-bold" @click="showEmbedPostModal()">Embed</a>
  110. <span v-if="!owner()">
  111. <a class="dropdown-item font-weight-bold" :href="reportUrl()">Report</a>
  112. <a class="dropdown-item font-weight-bold" v-on:click="muteProfile">Mute Profile</a>
  113. <a class="dropdown-item font-weight-bold" v-on:click="blockProfile">Block Profile</a>
  114. </span>
  115. <span v-if="ownerOrAdmin()">
  116. <a class="dropdown-item font-weight-bold" href="#" v-on:click.prevent="toggleCommentVisibility">{{ showComments ? 'Disable' : 'Enable'}} Comments</a>
  117. <a v-if="canEdit" class="dropdown-item font-weight-bold" :href="editUrl()">Edit</a>
  118. <a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost">Delete</a>
  119. </span>
  120. </div>
  121. </div>
  122. </div>
  123. </div>
  124. </div>
  125. <div class="d-flex flex-md-column flex-column-reverse h-100" style="overflow-y: auto;">
  126. <div class="card-body status-comments pb-5 pt-0">
  127. <div class="status-comment">
  128. <div v-if="status.content.length" class="pt-3">
  129. <div v-if="showCaption != true">
  130. <span class="py-3">
  131. <a class="text-dark font-weight-bold mr-1" :href="status.account.url" v-bind:title="status.account.username">{{truncate(status.account.username,15)}}</a>
  132. <span class="text-break">
  133. <span class="font-italic text-muted">This comment may contain sensitive material</span>
  134. <span class="text-primary cursor-pointer pl-1" @click="showCaption = true">Show</span>
  135. </span>
  136. </span>
  137. </div>
  138. <div v-else>
  139. <p :class="[status.content.length > 620 ? 'mb-1 read-more' : 'mb-1']" style="overflow: hidden;">
  140. <a class="font-weight-bold pr-1 text-dark text-decoration-none" :href="statusProfileUrl">{{statusUsername}}</a>
  141. <span class="comment-text" style="word-break: break-all;" :id="status.id + '-status-readmore'" v-html="status.content"></span>
  142. </p>
  143. </div>
  144. <hr>
  145. </div>
  146. <div v-if="showComments">
  147. <div class="postCommentsLoader text-center py-2">
  148. <div class="spinner-border" role="status">
  149. <span class="sr-only">Loading...</span>
  150. </div>
  151. </div>
  152. <div class="postCommentsContainer d-none">
  153. <p class="mb-1 text-center load-more-link d-none my-4">
  154. <a href="#" class="text-dark" v-on:click="loadMore" title="Load more comments" data-toggle="tooltip" data-placement="bottom">
  155. <svg class="bi bi-plus-circle" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg" style="font-size:2em;"> <path fill-rule="evenodd" d="M8 3.5a.5.5 0 01.5.5v4a.5.5 0 01-.5.5H4a.5.5 0 010-1h3.5V4a.5.5 0 01.5-.5z" clip-rule="evenodd"/> <path fill-rule="evenodd" d="M7.5 8a.5.5 0 01.5-.5h4a.5.5 0 010 1H8.5V12a.5.5 0 01-1 0V8z" clip-rule="evenodd"/> <path fill-rule="evenodd" d="M8 15A7 7 0 108 1a7 7 0 000 14zm0 1A8 8 0 108 0a8 8 0 000 16z" clip-rule="evenodd"/></svg>
  156. </a>
  157. </p>
  158. <div class="comments mt-3">
  159. <div v-for="(reply, index) in results" class="pb-4 media" :key="'tl' + reply.id + '_' + index">
  160. <img :src="reply.account.avatar" class="rounded-circle border mr-3" width="42px" height="42px">
  161. <div class="media-body">
  162. <div v-if="reply.sensitive == true">
  163. <span class="py-3">
  164. <a class="text-dark font-weight-bold mr-1" :href="reply.account.url" v-bind:title="reply.account.username">{{truncate(reply.account.username,15)}}</a>
  165. <span class="text-break">
  166. <span class="font-italic text-muted">This comment may contain sensitive material</span>
  167. <span class="text-primary cursor-pointer pl-1" @click="reply.sensitive = false;">Show</span>
  168. </span>
  169. </span>
  170. </div>
  171. <div v-else>
  172. <p class="d-flex justify-content-between align-items-top read-more" style="overflow-y: hidden;">
  173. <span>
  174. <a class="text-dark font-weight-bold mr-1 text-break" :href="reply.account.url" v-bind:title="reply.account.username">{{truncate(reply.account.username,15)}}</a>
  175. <span class="text-break comment-body" style="word-break: break-all;" v-html="reply.content"></span>
  176. </span>
  177. <span style="min-width:38px;">
  178. <span v-on:click="likeReply(reply, $event)"><i v-bind:class="[reply.favourited ? 'fas fa-heart fa-sm text-danger':'far fa-heart fa-sm text-lighter']"></i></span>
  179. <post-menu :status="reply" :profile="user" :size="'sm'" :modal="'true'" class="d-inline-block px-2" v-on:deletePost="deleteComment(reply.id, index)"></post-menu>
  180. </span>
  181. </p>
  182. <p class="">
  183. <a v-once class="text-muted mr-3 text-decoration-none small" style="width: 20px;" v-text="timeAgo(reply.created_at)" :href="permalinkUrl(reply)"></a>
  184. <span v-if="reply.favourites_count" class="text-muted comment-reaction font-weight-bold mr-3">{{reply.favourites_count == 1 ? '1 like' : reply.favourites_count + ' likes'}}</span>
  185. <span class="text-muted comment-reaction font-weight-bold cursor-pointer" v-on:click="replyFocus(reply, index, true)">Reply</span>
  186. </p>
  187. <div v-if="reply.reply_count > 0" class="cursor-pointer" v-on:click="toggleReplies(reply)">
  188. <span class="show-reply-bar"></span>
  189. <span class="comment-reaction font-weight-bold text-muted">{{reply.thread ? 'Hide' : 'View'}} Replies ({{reply.reply_count}})</span>
  190. </div>
  191. <div v-if="reply.thread == true" class="comment-thread">
  192. <div v-for="(s, sindex) in reply.replies" class="pb-3 media" :key="'cr' + s.id + '_' + index">
  193. <img :src="s.account.avatar" class="rounded-circle border mr-3" width="25px" height="25px">
  194. <div class="media-body">
  195. <p class="d-flex justify-content-between align-items-top read-more" style="overflow-y: hidden;">
  196. <span>
  197. <a class="text-dark font-weight-bold mr-1" :href="s.account.url" :title="s.account.username">{{s.account.username}}</a>
  198. <span class="text-break comment-body" style="word-break: break-all;" v-html="s.content"></span>
  199. </span>
  200. <span class="pl-2" style="min-width:38px">
  201. <span v-on:click="likeReply(s, $event)"><i v-bind:class="[s.favourited ? 'fas fa-heart fa-sm text-danger':'far fa-heart fa-sm text-lighter']"></i></span>
  202. <post-menu :status="s" :profile="user" :size="'sm'" :modal="'true'" class="d-inline-block pl-2" v-on:deletePost="deleteCommentReply(s.id, sindex, index) "></post-menu>
  203. </span>
  204. </p>
  205. <p class="">
  206. <a v-once class="text-muted mr-3 text-decoration-none small" style="width: 20px;" v-text="timeAgo(s.created_at)" :href="s.url"></a>
  207. <span v-if="s.favourites_count" class="text-muted comment-reaction font-weight-bold mr-3">{{s.favourites_count == 1 ? '1 like' : s.favourites_count + ' likes'}}</span>
  208. </p>
  209. </div>
  210. </div>
  211. </div>
  212. </div>
  213. </div>
  214. </div>
  215. </div>
  216. </div>
  217. </div>
  218. </div>
  219. </div>
  220. <div class="card-body flex-grow-0 py-1">
  221. <div v-if="loaded && user.hasOwnProperty('id')" class="reactions my-2 pb-1 d-flex justify-content-between">
  222. <h3 v-bind:class="[reactions.liked ? 'fas fa-heart text-danger mr-3 m-0 cursor-pointer' : 'far fa-heart pr-3 m-0 like-btn cursor-pointer']" title="Like" v-on:click="likeStatus"></h3>
  223. <h3 v-if="!status.comments_disabled" class="far fa-comment mr-3 m-0 cursor-pointer" title="Comment" v-on:click="replyFocus(status)"></h3>
  224. <h3 @click="redirect(status.media_attachments[0].url)" class="fas fa-expand m-0 mr-3 cursor-pointer"></h3>
  225. <!-- <h3 v-if="status.visibility == 'public'" v-bind:class="[reactions.bookmarked ? 'fas fa-bookmark text-warning m-0 float-right cursor-pointer' : 'far fa-bookmark m-0 float-right cursor-pointer']" title="Bookmark" v-on:click="bookmarkStatus"></h3> -->
  226. <h3 v-if="status.visibility == 'public'" v-bind:class="[reactions.bookmarked ? 'fas fa-bookmark text-warning m-0 mr-3 cursor-pointer' : 'far fa-bookmark m-0 mr-3 cursor-pointer']" title="Bookmark" v-on:click="bookmarkStatus"></h3>
  227. <h3 v-if="status.visibility == 'public'" v-bind:class="[reactions.shared ? 'fas fa-retweet m-0 text-primary cursor-pointer' : 'fas fa-retweet m-0 share-btn cursor-pointer']" title="Share" v-on:click="shareStatus"></h3>
  228. </div>
  229. <div class="reaction-counts font-weight-bold mb-0">
  230. <span style="cursor:pointer;" v-on:click="likesModal">
  231. <span class="like-count">{{status.favourites_count || 0}}</span> likes
  232. </span>
  233. <span v-if="status.visibility == 'public'" class="float-right" style="cursor:pointer;" v-on:click="sharesModal">
  234. <span class="share-count pl-4">{{status.reblogs_count || 0}}</span> shares
  235. </span>
  236. </div>
  237. <div class="timestamp pt-2 d-flex align-items-bottom justify-content-between">
  238. <a v-bind:href="statusUrl" class="small text-muted">
  239. {{timestampFormat()}}
  240. </a>
  241. <span class="small text-muted text-capitalize cursor-pointer" v-on:click="visibilityModal">{{status.visibility}}</span>
  242. </div>
  243. </div>
  244. </div>
  245. <!-- <div v-if="showComments && user.length !== 0" class="card-footer bg-white px-2 py-0">
  246. <ul class="nav align-items-center emoji-reactions" style="overflow-x: scroll;flex-wrap: unset;">
  247. <li class="nav-item" v-on:click="emojiReaction" v-for="e in emoji">{{e}}</li>
  248. </ul>
  249. </div> -->
  250. <div v-if="showComments" class="card-footer bg-white sticky-md-bottom p-0">
  251. <div v-if="user.length == 0" class="comment-form-guest p-3">
  252. <a href="/login">Login</a> to like or comment.
  253. </div>
  254. <form v-else class="border-0 rounded-0 align-middle" method="post" action="/i/comment" :data-id="statusId" data-truncate="false">
  255. <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>
  256. <input type="button" value="Post" class="d-inline-block btn btn-link font-weight-bold reply-btn text-decoration-none" v-on:click.prevent="postReply" :disabled="replyText.length == 0" />
  257. </form>
  258. </div>
  259. </div>
  260. </div>
  261. </div>
  262. <div class="container" v-if="showProfileMorePosts">
  263. <!-- <div class="py-4">
  264. <hr>
  265. </div> -->
  266. <p class="text-lighter px-3 mt-5" style="font-weight: 600;font-size: 15px;">More posts from <a :href="'/'+statusUsername" class="text-dark">{{this.statusUsername}}</a></p>
  267. <div class="profile-timeline mt-md-4">
  268. <div class="row">
  269. <div class="col-4 p-1 p-md-3" v-for="(s, index) in profileMorePosts" :key="'tlob:'+index">
  270. <a class="card info-overlay card-md-border-0" :href="getStatusUrl(s)" v-once>
  271. <div :class="[s.sensitive ? 'square' : 'square ' + s.media_attachments[0].filter_class]">
  272. <span v-if="s.pf_type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  273. <span v-if="s.pf_type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  274. <span v-if="s.pf_type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  275. <div class="square-content" v-bind:style="previewBackground(s)">
  276. </div>
  277. <div class="info-overlay-text">
  278. <h5 class="text-white m-auto font-weight-bold">
  279. <span>
  280. <span class="far fa-heart fa-lg p-2 d-flex-inline"></span>
  281. <span class="d-flex-inline">{{s.favourites_count}}</span>
  282. </span>
  283. <span>
  284. <span class="fas fa-retweet fa-lg p-2 d-flex-inline"></span>
  285. <span class="d-flex-inline">{{s.reblogs_count}}</span>
  286. </span>
  287. </h5>
  288. </div>
  289. </div>
  290. </a>
  291. </div>
  292. </div>
  293. </div>
  294. </div>
  295. </div>
  296. <div v-if="layout == 'moment'" class="momentui">
  297. <div class="bg-dark mt-md-n4">
  298. <div class="container" style="max-width: 700px;">
  299. <div class="postPresenterContainer d-none d-flex justify-content-center align-items-center bg-dark">
  300. <div v-if="status.pf_type === 'photo'" class="w-100">
  301. <photo-presenter :status="status" v-on:lightbox="lightbox"></photo-presenter>
  302. </div>
  303. <div v-else-if="status.pf_type === 'video'" class="w-100">
  304. <video-presenter :status="status"></video-presenter>
  305. </div>
  306. <div v-else-if="status.pf_type === 'photo:album'" class="w-100">
  307. <photo-album-presenter :status="status" v-on:lightbox="lightbox"></photo-album-presenter>
  308. </div>
  309. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  310. <video-album-presenter :status="status"></video-album-presenter>
  311. </div>
  312. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  313. <mixed-album-presenter :status="status" v-on:lightbox="lightbox"></mixed-album-presenter>
  314. </div>
  315. <div v-else class="w-100">
  316. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  317. </div>
  318. </div>
  319. </div>
  320. </div>
  321. <div class="bg-white">
  322. <div class="container">
  323. <div class="row pb-5">
  324. <div class="col-12 col-md-8 py-4">
  325. <div class="reactions d-flex align-items-center">
  326. <div class="text-center mr-5">
  327. <div v-bind:class="[reactions.liked ? 'fas fa-heart text-danger m-0 cursor-pointer' : 'far fa-heart m-0 like-btn cursor-pointer']" title="Like" v-on:click="likeStatus" style="font-size:1.575rem">
  328. </div>
  329. <div class="like-count font-weight-bold mt-2 rounded border" style="cursor:pointer;" v-on:click="likesModal">{{status.favourites_count || 0}}</div>
  330. </div>
  331. <div class="text-center">
  332. <div v-if="status.visibility == 'public'" v-bind:class="[reactions.shared ? 'h3 far fa-share-square m-0 text-primary cursor-pointer' : 'h3 far fa-share-square m-0 share-btn cursor-pointer']" title="Share" v-on:click="shareStatus">
  333. </div>
  334. <div class="share-count font-weight-bold mt-2 rounded border" v-if="status.visibility == 'public'" style="cursor:pointer;" v-on:click="sharesModal">{{status.reblogs_count || 0}}</div>
  335. </div>
  336. </div>
  337. <div v-if="status.length && status.content_text.includes('#') || status.content_text.includes('https://') || status.content_text.includes('@') || status.content_text.length > 45" class="media align-items-center mt-3">
  338. <div class="media-body">
  339. <p class="lead mr-2" v-html="status.content">
  340. </p>
  341. <p class="lead mb-0">
  342. by <a :href="statusProfileUrl">{{statusUsername}}</a>
  343. <span v-if="relationship && profile && user && !relationship.following && profile.id != user.id">
  344. <span class="px-1 text-lighter">•</span>
  345. <a class="font-weight-bold small" href="#">Follow</a>
  346. </span>
  347. </p>
  348. </div>
  349. <a :href="statusProfileUrl" :title="statusUsername"><img :src="statusAvatar" class="rounded-circle border mr-3" alt="avatar" width="72px" height="72px"></a>
  350. </div>
  351. <div v-else class="media align-items-center mt-3">
  352. <div class="media-body">
  353. <h2 class="font-weight-bold mr-2">
  354. {{status.content_text.length ? status.content_text : 'Untitled Post'}}
  355. </h2>
  356. <p class="lead mb-0">
  357. by <a :href="statusProfileUrl">{{statusUsername}}</a>
  358. <!-- <span class="px-1 text-lighter">•</span>
  359. <a class="font-weight-bold small" href="#">Follow</a> -->
  360. </p>
  361. </div>
  362. <a :href="statusProfileUrl" :title="statusUsername"><img :src="statusAvatar" class="rounded-circle border mr-3" alt="avatar" width="72px" height="72px"></a>
  363. </div>
  364. <hr>
  365. <div>
  366. <p class="lead">
  367. <span v-if="status.place" class="text-truncate">
  368. <i class="fas fa-map-marker-alt text-lighter mr-3"></i> {{status.place.name}}, {{status.place.country}}
  369. </span>
  370. <span v-once class="float-right">
  371. <i class="far fa-clock text-lighter mr-3"></i> {{timeAgo(status.created_at)}} ago
  372. </span>
  373. </p>
  374. <!-- <div class="">
  375. <p class="lead">
  376. <span class="mr-3"><i class="fas fa-camera text-lighter"></i></span>
  377. <span>Nikon D850</span>
  378. </p>
  379. <p class="lead">
  380. <span class="mr-3"><i class="fas fa-ruler-horizontal text-lighter"></i></span>
  381. <span>200-500mm</span>
  382. </p>
  383. <p class="lead">
  384. <span class="mr-3"><i class="fas fa-stream text-lighter"></i></span>
  385. <span>500mm <span class="px-1"></span> ƒ/7.1 <span class="px-1"></span> 1/1600s <span class="px-1"></span> ISO 800</span>
  386. </p>
  387. </div> -->
  388. <div v-if="status.tags" class="pt-4">
  389. <p class="lead">
  390. <a v-for="(tag, index) in status.tags" class="btn btn-outline-dark mr-1 mb-1" :href="tag.url + '?src=mp'">{{tag.name}}</a>
  391. </p>
  392. </div>
  393. </div>
  394. </div>
  395. <div class="col-12 col-md-4 pt-4 pl-md-3">
  396. <p class="lead font-weight-bold">Comments</p>
  397. <div v-if="user != false" class="moment-comments">
  398. <div class="form-group">
  399. <textarea class="form-control" rows="3" placeholder="Add a comment ..." v-model="replyText"></textarea>
  400. <p class="d-flex justify-content-between align-items-center mt-3">
  401. <span class="small text-lighter font-weight-bold">
  402. {{replyText.length}}/{{config.uploader.max_caption_length}}
  403. </span>
  404. <span v-if="replyText.length > 2">
  405. <div class="custom-control custom-switch">
  406. <input type="checkbox" class="custom-control-input" @click="!!replySensitive" v-model="replySensitive" id="sensitiveReply">
  407. <label class="custom-control-label small font-weight-bold text-muted" style="padding-top: 3px" for="sensitiveReply">Add Content Warning</label>
  408. </div>
  409. </span>
  410. <button class="btn btn-sm font-weight-bold btn-outline-primary py-1"
  411. v-if="replyText.length > 2" @click="postReply">Post</button>
  412. </p>
  413. </div>
  414. </div>
  415. <div class="comment mt-4" style="max-height: 500px; overflow-y: auto;">
  416. <div v-for="(reply, index) in results" :key="'tl' + reply.id + '_' + index" class="media mb-3 mt-2">
  417. <a :href="reply.account.url" :title="reply.account.username"><img :src="reply.account.avatar" class="rounded-circle border mr-3" alt="avatar" width="32px" height="32px"></a>
  418. <div class="media-body">
  419. <div class="d-flex justify-content-between">
  420. <span>
  421. <a class="font-weight-bold text-dark" :href="reply.account.url">{{reply.account.username}}</a>
  422. </span>
  423. <span class="text-lighter">
  424. <span v-if="reply.favourited" class="cursor-pointer mr-2" @click="likeReply(reply)">
  425. <i class="fas fa-heart text-danger"></i>
  426. </span>
  427. <span v-else class="cursor-pointer mr-2" @click="likeReply(reply)">
  428. <i class="far fa-heart"></i>
  429. </span>
  430. <span class="">
  431. <post-menu :status="reply" :profile="user" :size="'sm'" :modal="'true'" class="d-inline-block px-2" v-on:deletePost="deleteComment(reply.id, index)"></post-menu>
  432. </span>
  433. </span>
  434. </div>
  435. <div v-if="reply.sensitive == true">
  436. <span class="py-3">
  437. <span class="text-break">
  438. <span class="font-italic text-muted">This comment may contain sensitive material</span>
  439. <span class="badge badge-primary cursor-pointer ml-2 py-1" @click="reply.sensitive = false;">Show</span>
  440. </span>
  441. </span>
  442. </div>
  443. <div v-else class="read-more" style="overflow-y: hidden;">
  444. <p v-html="reply.content" class="mb-0">loading ...</p>
  445. </div>
  446. <p>
  447. <span class="small">
  448. <a class="text-lighter text-decoration-none" :href="reply.url">{{timeAgo(reply.created_at)}}</a>
  449. </span>
  450. </p>
  451. </div>
  452. </div>
  453. </div>
  454. </div>
  455. </div>
  456. </div>
  457. </div>
  458. </div>
  459. </div>
  460. <b-modal ref="likesModal"
  461. id="l-modal"
  462. hide-footer
  463. centered
  464. title="Likes"
  465. body-class="list-group-flush py-3 px-0">
  466. <div class="list-group">
  467. <div class="list-group-item border-0 py-1" v-for="(user, index) in likes" :key="'modal_likes_'+index">
  468. <div class="media">
  469. <a :href="user.url">
  470. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  471. </a>
  472. <div class="media-body">
  473. <p class="mb-0" style="font-size: 14px">
  474. <a :href="user.url" class="font-weight-bold text-dark">
  475. {{user.username}}
  476. </a>
  477. </p>
  478. <p v-if="!user.local" class="text-muted mb-0 text-truncate mr-3" style="font-size: 14px" :title="user.acct" data-toggle="dropdown" data-placement="bottom">
  479. <span class="font-weight-bold">{{user.acct.split('@')[0]}}</span><span class="text-lighter">&commat;{{user.acct.split('@')[1]}}</span>
  480. </p>
  481. <p v-else class="text-muted mb-0 text-truncate" style="font-size: 14px">
  482. {{user.display_name}}
  483. </p>
  484. </div>
  485. </div>
  486. </div>
  487. <infinite-loading @infinite="infiniteLikesHandler" spinner="spiral">
  488. <div slot="no-more"></div>
  489. <div slot="no-results"></div>
  490. </infinite-loading>
  491. </div>
  492. </b-modal>
  493. <b-modal ref="sharesModal"
  494. id="s-modal"
  495. hide-footer
  496. centered
  497. title="Shares"
  498. body-class="list-group-flush p-0">
  499. <div class="list-group">
  500. <div class="list-group-item border-0" v-for="(user, index) in shares" :key="'modal_shares_'+index">
  501. <div class="media">
  502. <a :href="user.url">
  503. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  504. </a>
  505. <div class="media-body">
  506. <div class="d-inline-block">
  507. <p class="mb-0" style="font-size: 14px">
  508. <a :href="user.url" class="font-weight-bold text-dark">
  509. {{user.username}}
  510. </a>
  511. </p>
  512. <p class="text-muted mb-0" style="font-size: 14px">
  513. {{user.display_name}}
  514. </a>
  515. </p>
  516. </div>
  517. <p class="float-right"><!-- <a class="btn btn-primary font-weight-bold py-1" href="#">Follow</a> --></p>
  518. </div>
  519. </div>
  520. </div>
  521. <infinite-loading @infinite="infiniteSharesHandler" spinner="spiral">
  522. <div slot="no-more"></div>
  523. <div slot="no-results"></div>
  524. </infinite-loading>
  525. </div>
  526. </b-modal>
  527. <b-modal ref="lightboxModal"
  528. id="lightbox"
  529. :hide-header="true"
  530. :hide-footer="true"
  531. centered
  532. size="lg"
  533. body-class="p-0"
  534. >
  535. <div v-if="lightboxMedia" >
  536. <img :src="lightboxMedia.url" :class="lightboxMedia.filter_class + ' img-fluid'" style="min-height: 100%; min-width: 100%">
  537. </div>
  538. </b-modal>
  539. <b-modal ref="embedModal"
  540. id="ctx-embed-modal"
  541. hide-header
  542. hide-footer
  543. centered
  544. rounded
  545. size="md"
  546. body-class="p-2 rounded">
  547. <div>
  548. <div class="form-group">
  549. <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>
  550. </div>
  551. <div class="form-group pl-2 d-flex justify-content-center">
  552. <div class="form-check mr-3">
  553. <input class="form-check-input" type="checkbox" v-model="ctxEmbedShowCaption" :disabled="ctxEmbedCompactMode == true">
  554. <label class="form-check-label font-weight-light">
  555. Show Caption
  556. </label>
  557. </div>
  558. <div class="form-check mr-3">
  559. <input class="form-check-input" type="checkbox" v-model="ctxEmbedShowLikes" :disabled="ctxEmbedCompactMode == true">
  560. <label class="form-check-label font-weight-light">
  561. Show Likes
  562. </label>
  563. </div>
  564. <div class="form-check">
  565. <input class="form-check-input" type="checkbox" v-model="ctxEmbedCompactMode">
  566. <label class="form-check-label font-weight-light">
  567. Compact Mode
  568. </label>
  569. </div>
  570. </div>
  571. <hr>
  572. <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>
  573. <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>
  574. </div>
  575. </b-modal>
  576. <b-modal ref="taggedModal"
  577. id="tagged-modal"
  578. hide-footer
  579. centered
  580. title="Tagged People"
  581. body-class="list-group-flush py-3 px-0">
  582. <div class="list-group">
  583. <div class="list-group-item border-0 py-1" v-for="(taguser, index) in status.taggedPeople" :key="'modal_taggedpeople_'+index">
  584. <div class="media">
  585. <a :href="'/'+taguser.username">
  586. <img class="mr-3 rounded-circle box-shadow" :src="taguser.avatar" :alt="taguser.username + '’s avatar'" width="30px">
  587. </a>
  588. <div class="media-body">
  589. <p class="pt-1 d-flex justify-content-between" style="font-size: 14px">
  590. <a :href="'/'+taguser.username" class="font-weight-bold text-dark">
  591. {{taguser.username}}
  592. </a>
  593. <button v-if="taguser.id == user.id" class="btn btn-outline-primary btn-sm py-1 px-3" @click="untagMe()">Untag Me</button>
  594. </p>
  595. </div>
  596. </div>
  597. </div>
  598. </div>
  599. <p class="mb-0 text-center small text-muted font-weight-bold"><a href="/site/kb/tagging-people">Learn more</a> about Tagging People.</p>
  600. </b-modal>
  601. </div>
  602. </template>
  603. <style type="text/css" scoped>
  604. .status-comments,
  605. .reactions {
  606. background: #fff;
  607. }
  608. .postPresenterContainer {
  609. background: #fff;
  610. }
  611. @media(min-width: 720px) {
  612. .postPresenterContainer {
  613. min-height: 600px;
  614. }
  615. }
  616. ::-webkit-scrollbar {
  617. width: 0px;
  618. background: transparent;
  619. }
  620. .reply-btn {
  621. position: absolute;
  622. bottom: 12px;
  623. right: 20px;
  624. width: 60px;
  625. text-align: center;
  626. border-radius: 0 3px 3px 0;
  627. }
  628. .text-lighter {
  629. color:#B8C2CC !important;
  630. }
  631. .text-break {
  632. overflow-wrap: break-word;
  633. }
  634. .comments p {
  635. margin-bottom: 0;
  636. }
  637. .comment-reaction {
  638. font-size: 80%;
  639. }
  640. .show-reply-bar {
  641. display: inline-block;
  642. border-bottom: 1px solid #999;
  643. height: 0;
  644. margin-right: 16px;
  645. vertical-align: middle;
  646. width: 24px;
  647. }
  648. .comment-thread {
  649. margin-top: 1rem;
  650. }
  651. .emoji-reactions .nav-item {
  652. font-size: 1.2rem;
  653. padding: 9px;
  654. cursor: pointer;
  655. }
  656. .emoji-reactions::-webkit-scrollbar {
  657. width: 0px;
  658. height: 0px;
  659. background: transparent;
  660. }
  661. @media (min-width: 1200px) {
  662. .container {
  663. max-width: 1100px;
  664. }
  665. }
  666. </style>
  667. <style type="text/css" scoped>
  668. .momentui .bg-dark {
  669. background: #000 !important;
  670. }
  671. .momentui .carousel.slide,
  672. .momentui .carousel-item {
  673. background: #000 !important;
  674. }
  675. .reply-btn[disabled] {
  676. opacity: .3;
  677. color: #3897f0;
  678. }
  679. </style>
  680. <script>
  681. pixelfed.postComponent = {};
  682. export default {
  683. props: [
  684. 'status-id',
  685. 'status-username',
  686. 'status-template',
  687. 'status-url',
  688. 'status-profile-url',
  689. 'status-avatar',
  690. 'status-profile-id',
  691. 'profile-layout'
  692. ],
  693. data() {
  694. return {
  695. config: window.App.config,
  696. status: false,
  697. media: {},
  698. user: false,
  699. reactions: {
  700. liked: false,
  701. shared: false
  702. },
  703. likes: [],
  704. likesPage: 1,
  705. shares: [],
  706. sharesPage: 1,
  707. lightboxMedia: false,
  708. replyText: '',
  709. replyStatus: {},
  710. replySensitive: false,
  711. relationship: {},
  712. results: [],
  713. pagination: {},
  714. min_id: 0,
  715. max_id: 0,
  716. reply_to_profile_id: 0,
  717. thread: false,
  718. showComments: false,
  719. warning: false,
  720. loaded: false,
  721. loading: null,
  722. replyingToId: this.statusId,
  723. replyToIndex: 0,
  724. replySending: false,
  725. emoji: window.App.util.emoji,
  726. showReadMore: true,
  727. showCaption: true,
  728. ctxEmbedPayload: false,
  729. copiedEmbed: false,
  730. ctxEmbedShowCaption: true,
  731. ctxEmbedShowLikes: false,
  732. ctxEmbedCompactMode: false,
  733. layout: this.profileLayout,
  734. canEdit: false,
  735. showProfileMorePosts: false,
  736. profileMorePosts: []
  737. }
  738. },
  739. watch: {
  740. ctxEmbedShowCaption: function (n,o) {
  741. if(n == true) {
  742. this.ctxEmbedCompactMode = false;
  743. }
  744. let mode = this.ctxEmbedCompactMode ? 'compact' : 'full';
  745. this.ctxEmbedPayload = window.App.util.embed.post(this.status.url, this.ctxEmbedShowCaption, this.ctxEmbedShowLikes, mode);
  746. },
  747. ctxEmbedShowLikes: function (n,o) {
  748. if(n == true) {
  749. this.ctxEmbedCompactMode = false;
  750. }
  751. let mode = this.ctxEmbedCompactMode ? 'compact' : 'full';
  752. this.ctxEmbedPayload = window.App.util.embed.post(this.status.url, this.ctxEmbedShowCaption, this.ctxEmbedShowLikes, mode);
  753. },
  754. ctxEmbedCompactMode: function (n,o) {
  755. if(n == true) {
  756. this.ctxEmbedShowCaption = false;
  757. this.ctxEmbedShowLikes = false;
  758. }
  759. let mode = this.ctxEmbedCompactMode ? 'compact' : 'full';
  760. this.ctxEmbedPayload = window.App.util.embed.post(this.status.url, this.ctxEmbedShowCaption, this.ctxEmbedShowLikes, mode);
  761. }
  762. },
  763. beforeMount() {
  764. let u = new URLSearchParams(window.location.search);
  765. let forceMetro = localStorage.getItem('pf_metro_ui.exp.forceMetro') == 'true';
  766. if(forceMetro == true || u.has('ui') && u.get('ui') == 'metro' && this.layout != 'metro') {
  767. this.layout = 'metro';
  768. }
  769. if(u.has('ui') && u.get('ui') == 'moment' && this.layout != 'moment') {
  770. this.layout = 'moment';
  771. }
  772. },
  773. mounted() {
  774. this.fetchRelationships();
  775. if(localStorage.getItem('pf_metro_ui.exp.rm') == 'false') {
  776. this.showReadMore = false;
  777. } else {
  778. this.showReadMore = true;
  779. }
  780. },
  781. updated() {
  782. $('.carousel').carousel();
  783. $('[data-toggle="tooltip"]').tooltip();
  784. if(this.showReadMore == true) {
  785. window.pixelfed.readmore();
  786. }
  787. },
  788. methods: {
  789. showMuteBlock() {
  790. let sid = this.status.account.id;
  791. let uid = this.user.id;
  792. if(sid == uid) {
  793. $('.post-actions .menu-author').removeClass('d-none');
  794. } else {
  795. $('.post-actions .menu-user').removeClass('d-none');
  796. }
  797. },
  798. reportUrl() {
  799. return '/i/report?type=post&id=' + this.status.id;
  800. },
  801. editUrl() {
  802. return this.status.url + '/edit';
  803. },
  804. timestampFormat() {
  805. let ts = new Date(this.status.created_at);
  806. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  807. },
  808. fetchData() {
  809. let self = this;
  810. axios.get('/api/v2/profile/'+this.statusUsername+'/status/'+this.statusId)
  811. .then(response => {
  812. self.status = response.data.status;
  813. self.user = response.data.user;
  814. window._sharedData.curUser = self.user;
  815. self.media = self.status.media_attachments;
  816. self.reactions = response.data.reactions;
  817. self.likes = response.data.likes;
  818. self.shares = response.data.shares;
  819. self.likesPage = 2;
  820. self.sharesPage = 2;
  821. this.showMuteBlock();
  822. self.showCaption = !response.data.status.sensitive;
  823. if(self.status.comments_disabled == false) {
  824. self.showComments = true;
  825. this.fetchComments();
  826. }
  827. if(this.ownerOrAdmin()) {
  828. let od = new Date(this.status.created_at).getTime() + (1 * 24 * 60 * 60 * 1000);
  829. let now = new Date().getTime();
  830. if(od > now) {
  831. this.canEdit = true;
  832. }
  833. }
  834. this.loaded = true;
  835. setTimeout(function() {
  836. self.fetchProfilePosts();
  837. }, 3000);
  838. setTimeout(function() {
  839. document.querySelectorAll('.status-comment .comment-text a').forEach(function(i, e) {
  840. if(i.href.startsWith(window.location.origin)) {
  841. return;
  842. }
  843. let tag = i.innerText;
  844. if(tag.startsWith('#')) {
  845. tag = tag.substr(1);
  846. }
  847. i.href = '/discover/tags/'+tag+'?src=rph';
  848. });
  849. }, 500);
  850. }).catch(error => {
  851. swal('Oops!', 'An error occured, please try refreshing the page.', 'error');
  852. });
  853. },
  854. likesModal() {
  855. if($('body').hasClass('loggedIn') == false) {
  856. window.location.href = '/login?next=' + encodeURIComponent('/p/' + this.status.shortcode);
  857. return;
  858. }
  859. if(this.status.favourites_count == 0) {
  860. return;
  861. }
  862. this.$refs.likesModal.show();
  863. },
  864. sharesModal() {
  865. if(this.status.reblogs_count == 0 || $('body').hasClass('loggedIn') == false) {
  866. return;
  867. }
  868. this.$refs.sharesModal.show();
  869. },
  870. infiniteLikesHandler($state) {
  871. let api = '/api/v2/likes/profile/'+this.statusUsername+'/status/'+this.statusId;
  872. axios.get(api, {
  873. params: {
  874. page: this.likesPage,
  875. },
  876. }).then(({ data }) => {
  877. if (data.data.length > 0) {
  878. this.likes.push(...data.data);
  879. this.likesPage++;
  880. $state.loaded();
  881. } else {
  882. $state.complete();
  883. }
  884. });
  885. },
  886. infiniteSharesHandler($state) {
  887. axios.get('/api/v2/shares/profile/'+this.statusUsername+'/status/'+this.statusId, {
  888. params: {
  889. page: this.sharesPage,
  890. },
  891. }).then(({ data }) => {
  892. if (data.data.length > 0) {
  893. this.shares.push(...data.data);
  894. this.sharesPage++;
  895. $state.loaded();
  896. } else {
  897. $state.complete();
  898. }
  899. });
  900. },
  901. likeStatus(event) {
  902. if($('body').hasClass('loggedIn') == false) {
  903. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  904. return;
  905. }
  906. axios.post('/i/like', {
  907. item: this.status.id
  908. }).then(res => {
  909. this.status.favourites_count = res.data.count;
  910. if(this.reactions.liked == true) {
  911. this.reactions.liked = false;
  912. let user = this.user.id;
  913. this.likes = this.likes.filter(function(like) {
  914. return like.id !== user;
  915. });
  916. } else {
  917. this.reactions.liked = true;
  918. let user = this.user;
  919. this.likes.unshift(user);
  920. setTimeout(function() {
  921. event.target.classList.add('animate__animated', 'animate__bounce');
  922. },100);
  923. }
  924. }).catch(err => {
  925. console.error(err);
  926. swal('Error', 'Something went wrong, please try again later.', 'error');
  927. });
  928. window.navigator.vibrate(200);
  929. },
  930. shareStatus() {
  931. if($('body').hasClass('loggedIn') == false) {
  932. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  933. return;
  934. }
  935. axios.post('/i/share', {
  936. item: this.status.id
  937. }).then(res => {
  938. this.status.reblogs_count = res.data.count;
  939. if(this.reactions.shared == true) {
  940. this.reactions.shared = false;
  941. let user = this.user.id;
  942. this.shares = this.shares.filter(function(reaction) {
  943. return reaction.id !== user;
  944. });
  945. } else {
  946. this.reactions.shared = true;
  947. let user = this.user;
  948. this.shares.push(user);
  949. }
  950. }).catch(err => {
  951. console.error(err);
  952. swal('Error', 'Something went wrong, please try again later.', 'error');
  953. });
  954. },
  955. bookmarkStatus() {
  956. if($('body').hasClass('loggedIn') == false) {
  957. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  958. return;
  959. }
  960. axios.post('/i/bookmark', {
  961. item: this.status.id
  962. }).then(res => {
  963. if(this.reactions.bookmarked == true) {
  964. this.reactions.bookmarked = false;
  965. } else {
  966. this.reactions.bookmarked = true;
  967. }
  968. }).catch(err => {
  969. swal('Error', 'Something went wrong, please try again later.', 'error');
  970. });
  971. },
  972. muteProfile() {
  973. if($('body').hasClass('loggedIn') == false) {
  974. return;
  975. }
  976. axios.post('/i/mute', {
  977. type: 'user',
  978. item: this.status.account.id
  979. }).then(res => {
  980. swal('Success', 'You have successfully muted ' + this.status.account.acct, 'success');
  981. }).catch(err => {
  982. swal('Error', 'Something went wrong. Please try again later.', 'error');
  983. });
  984. },
  985. blockProfile() {
  986. if($('body').hasClass('loggedIn') == false) {
  987. return;
  988. }
  989. axios.post('/i/block', {
  990. type: 'user',
  991. item: this.status.account.id
  992. }).then(res => {
  993. swal('Success', 'You have successfully blocked ' + this.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(!this.ownerOrAdmin()) {
  1000. return;
  1001. }
  1002. var result = confirm('Are you sure you want to delete this post?');
  1003. if (result) {
  1004. if($('body').hasClass('loggedIn') == false) {
  1005. return;
  1006. }
  1007. axios.post('/i/delete', {
  1008. type: 'status',
  1009. item: this.status.id
  1010. }).then(res => {
  1011. swal('Success', 'You have successfully deleted this post', 'success');
  1012. setTimeout(function() {
  1013. window.location.href = '/';
  1014. }, 3000);
  1015. }).catch(err => {
  1016. swal('Error', 'Something went wrong. Please try again later.', 'error');
  1017. });
  1018. }
  1019. },
  1020. owner() {
  1021. return this.user.id === this.status.account.id;
  1022. },
  1023. admin() {
  1024. return this.user.is_admin == true;
  1025. },
  1026. ownerOrAdmin() {
  1027. return this.owner() || this.admin();
  1028. },
  1029. lightbox(src) {
  1030. this.lightboxMedia = src;
  1031. this.$refs.lightboxModal.show();
  1032. },
  1033. postReply() {
  1034. let self = this;
  1035. if(this.replyText.length == 0 ||
  1036. this.replyText.trim() == '@'+this.status.account.acct) {
  1037. self.replyText = null;
  1038. $('textarea[name="comment"]').blur();
  1039. return;
  1040. }
  1041. let data = {
  1042. item: this.replyingToId,
  1043. comment: this.replyText,
  1044. sensitive: this.replySensitive
  1045. }
  1046. this.replyText = '';
  1047. axios.post('/i/comment', data)
  1048. .then(function(res) {
  1049. let entity = res.data.entity;
  1050. if(entity.in_reply_to_id == self.status.id) {
  1051. if(self.layout == 'metro') {
  1052. self.results.push(entity);
  1053. } else {
  1054. self.results.unshift(entity);
  1055. }
  1056. let elem = $('.status-comments')[0];
  1057. elem.scrollTop = elem.clientHeight;
  1058. } else {
  1059. if(self.replyToIndex >= 0) {
  1060. let el = self.results[self.replyToIndex];
  1061. el.replies.push(entity);
  1062. el.reply_count = el.reply_count + 1;
  1063. }
  1064. }
  1065. });
  1066. },
  1067. deleteComment(id, i) {
  1068. axios.post('/i/delete', {
  1069. type: 'comment',
  1070. item: id
  1071. }).then(res => {
  1072. this.results.splice(i, 1);
  1073. }).catch(err => {
  1074. swal('Something went wrong!', 'Please try again later', 'error');
  1075. });
  1076. },
  1077. deleteCommentReply(id, i, pi) {
  1078. axios.post('/i/delete', {
  1079. type: 'comment',
  1080. item: id
  1081. }).then(res => {
  1082. this.results[pi].replies.splice(i, 1);
  1083. --this.results[pi].reply_count;
  1084. }).catch(err => {
  1085. swal('Something went wrong!', 'Please try again later', 'error');
  1086. });
  1087. },
  1088. l(e) {
  1089. let len = e.length;
  1090. if(len < 10) { return e; }
  1091. return e.substr(0, 10)+'...';
  1092. },
  1093. replyFocus(e, index, prependUsername = false) {
  1094. this.replyToIndex = index;
  1095. this.replyingToId = e.id;
  1096. this.reply_to_profile_id = e.account.id;
  1097. if(prependUsername == true) {
  1098. this.replyText = '@' + e.account.username + ' ';
  1099. }
  1100. $('textarea[name="comment"]').focus();
  1101. },
  1102. fetchComments() {
  1103. let url = '/api/v2/comments/'+this.statusProfileId+'/status/'+this.statusId;
  1104. axios.get(url)
  1105. .then(response => {
  1106. let self = this;
  1107. this.results = this.layout == 'metro' ?
  1108. _.reverse(response.data.data) :
  1109. response.data.data;
  1110. this.pagination = response.data.meta.pagination;
  1111. if(this.results.length > 0) {
  1112. $('.load-more-link').removeClass('d-none');
  1113. }
  1114. $('.postCommentsLoader').addClass('d-none');
  1115. $('.postCommentsContainer').removeClass('d-none');
  1116. setTimeout(function() {
  1117. document.querySelectorAll('.comments .comment-body a').forEach(function(i, e) {
  1118. if(i.href.startsWith(window.location.origin)) {
  1119. return;
  1120. }
  1121. let tag = i.innerText;
  1122. if(tag.startsWith('#')) {
  1123. tag = tag.substr(1);
  1124. }
  1125. i.href = '/discover/tags/'+tag+'?src=rph';
  1126. });
  1127. }, 500);
  1128. }).catch(error => {
  1129. if(!error.response) {
  1130. $('.postCommentsLoader .lds-ring')
  1131. .attr('style','width:100%')
  1132. .addClass('pt-4 font-weight-bold text-muted')
  1133. .text('An error occurred, cannot fetch comments. Please try again later.');
  1134. } else {
  1135. switch(error.response.status) {
  1136. case 401:
  1137. $('.postCommentsLoader .lds-ring')
  1138. .attr('style','width:100%')
  1139. .addClass('pt-4 font-weight-bold text-muted')
  1140. .text('Please login to view.');
  1141. break;
  1142. default:
  1143. $('.postCommentsLoader .lds-ring')
  1144. .attr('style','width:100%')
  1145. .addClass('pt-4 font-weight-bold text-muted')
  1146. .text('An error occurred, cannot fetch comments. Please try again later.');
  1147. break;
  1148. }
  1149. }
  1150. });
  1151. },
  1152. loadMore(e) {
  1153. e.preventDefault();
  1154. if(this.pagination.total_pages == 1 || this.pagination.current_page == this.pagination.total_pages) {
  1155. $('.load-more-link').addClass('d-none');
  1156. return;
  1157. }
  1158. $('.load-more-link').addClass('d-none');
  1159. $('.postCommentsLoader').removeClass('d-none');
  1160. let next = this.pagination.links.next;
  1161. axios.get(next)
  1162. .then(response => {
  1163. let self = this;
  1164. let res = response.data.data;
  1165. $('.postCommentsLoader').addClass('d-none');
  1166. for(let i=0; i < res.length; i++) {
  1167. this.results.unshift(res[i]);
  1168. }
  1169. this.pagination = response.data.meta.pagination;
  1170. $('.load-more-link').removeClass('d-none');
  1171. });
  1172. },
  1173. likeReply(status, $event) {
  1174. if($('body').hasClass('loggedIn') == false) {
  1175. swal('Login', 'Please login to perform this action.', 'info');
  1176. return;
  1177. }
  1178. axios.post('/i/like', {
  1179. item: status.id
  1180. }).then(res => {
  1181. status.favourites_count = res.data.count;
  1182. if(status.favourited == true) {
  1183. status.favourited = false;
  1184. } else {
  1185. status.favourited = true;
  1186. }
  1187. }).catch(err => {
  1188. swal('Error', 'Something went wrong, please try again later.', 'error');
  1189. });
  1190. },
  1191. truncate(str,lim) {
  1192. return _.truncate(str,{
  1193. length: lim
  1194. });
  1195. },
  1196. timeAgo(ts) {
  1197. return App.util.format.timeAgo(ts);
  1198. },
  1199. emojiReaction() {
  1200. let em = event.target.innerText;
  1201. if(this.replyText.length == 0) {
  1202. this.reply_to_profile_id = this.status.account.id;
  1203. this.replyText = em + ' ';
  1204. $('textarea[name="comment"]').focus();
  1205. } else {
  1206. this.reply_to_profile_id = this.status.account.id;
  1207. this.replyText += em + ' ';
  1208. $('textarea[name="comment"]').focus();
  1209. }
  1210. },
  1211. toggleCommentVisibility() {
  1212. if(this.ownerOrAdmin() == false) {
  1213. return;
  1214. }
  1215. let state = this.status.comments_disabled;
  1216. let self = this;
  1217. if(state == true) {
  1218. // re-enable comments
  1219. axios.post('/i/visibility', {
  1220. item: self.status.id,
  1221. disableComments: false
  1222. }).then(function(res) {
  1223. window.location.href = self.status.url;
  1224. }).catch(function(err) {
  1225. return;
  1226. });
  1227. } else {
  1228. // disable comments
  1229. axios.post('/i/visibility', {
  1230. item: self.status.id,
  1231. disableComments: true
  1232. }).then(function(res) {
  1233. self.status.comments_disabled = false;
  1234. self.showComments = false;
  1235. }).catch(function(err) {
  1236. return;
  1237. });
  1238. }
  1239. },
  1240. fetchRelationships() {
  1241. if(document.querySelectorAll('body')[0].classList.contains('loggedIn') == false) {
  1242. this.fetchData();
  1243. return;
  1244. } else {
  1245. axios.get('/api/pixelfed/v1/accounts/relationships', {
  1246. params: {
  1247. 'id[]': this.statusProfileId
  1248. }
  1249. }).then(res => {
  1250. if(res.data[0] == null) {
  1251. this.fetchData();
  1252. return;
  1253. }
  1254. this.relationship = res.data[0];
  1255. if(res.data[0].blocking == true) {
  1256. this.loaded = true;
  1257. this.warning = true;
  1258. return;
  1259. } else {
  1260. this.fetchData();
  1261. return;
  1262. }
  1263. });
  1264. }
  1265. },
  1266. visibilityModal() {
  1267. switch(this.status.visibility) {
  1268. case 'public':
  1269. swal('Public Post', 'This post is visible to everyone.', 'info');
  1270. break;
  1271. case 'unlisted':
  1272. swal('Unlisted Post', 'This post is visible on profiles and with a direct links. It is not displayed on timelines.', 'info');
  1273. break;
  1274. case 'private':
  1275. swal('Private Post', 'This post is only visible to followers.', 'info');
  1276. break;
  1277. }
  1278. },
  1279. toggleReplies(reply) {
  1280. if(reply.thread) {
  1281. reply.thread = false;
  1282. } else {
  1283. if(reply.replies.length > 0) {
  1284. reply.thread = true;
  1285. return;
  1286. }
  1287. let url = '/api/v2/comments/'+reply.account.id+'/status/'+reply.id;
  1288. axios.get(url)
  1289. .then(response => {
  1290. reply.replies = _.reverse(response.data.data);
  1291. reply.thread = true;
  1292. });
  1293. }
  1294. },
  1295. redirect(url) {
  1296. window.location.href = url;
  1297. },
  1298. showEmbedPostModal() {
  1299. let mode = this.ctxEmbedCompactMode ? 'compact' : 'full';
  1300. this.ctxEmbedPayload = window.App.util.embed.post(this.status.url, this.ctxEmbedShowCaption, this.ctxEmbedShowLikes, mode);
  1301. this.$refs.embedModal.show();
  1302. },
  1303. ctxCopyEmbed() {
  1304. navigator.clipboard.writeText(this.ctxEmbedPayload);
  1305. this.$refs.embedModal.hide();
  1306. },
  1307. permalinkUrl(reply, showOrigin = false) {
  1308. let profile = reply.account;
  1309. if(profile.local == true) {
  1310. return reply.url;
  1311. } else {
  1312. return showOrigin ?
  1313. reply.url :
  1314. '/i/web/post/_/' + profile.id + '/' + reply.id;
  1315. }
  1316. },
  1317. fetchProfilePosts() {
  1318. if(!$('body').hasClass('loggedIn') && this.loaded) {
  1319. return;
  1320. }
  1321. let self = this;
  1322. let apiUrl = '/api/pixelfed/v1/accounts/' + this.statusProfileId + '/statuses';
  1323. axios.get(apiUrl, {
  1324. params: {
  1325. only_media: true,
  1326. min_id: 1,
  1327. limit: 9
  1328. }
  1329. })
  1330. .then(res => {
  1331. let data = res.data.filter(function(status) {
  1332. return status.media_attachments.length > 0 &&
  1333. status.id != self.statusId &&
  1334. status.sensitive == false
  1335. });
  1336. let ids = data.map(status => status.id);
  1337. if(data.length >= 3) {
  1338. self.showProfileMorePosts = true;
  1339. }
  1340. self.profileMorePosts = data.slice(0,6);
  1341. })
  1342. },
  1343. previewUrl(status) {
  1344. return status.sensitive ? '/storage/no-preview.png?v=' + new Date().getTime() : status.media_attachments[0].preview_url;
  1345. },
  1346. previewBackground(status) {
  1347. let preview = this.previewUrl(status);
  1348. return 'background-image: url(' + preview + ');';
  1349. },
  1350. getStatusUrl(status) {
  1351. return status.url;
  1352. if(status.local == true) {
  1353. return status.url;
  1354. }
  1355. return '/i/web/post/_/' + status.account.id + '/' + status.id;
  1356. },
  1357. showTaggedPeopleModal() {
  1358. if(!$('body').hasClass('loggedIn') && this.loaded) {
  1359. return;
  1360. }
  1361. this.$refs.taggedModal.show();
  1362. },
  1363. untagMe() {
  1364. this.$refs.taggedModal.hide();
  1365. let id = this.user.id;
  1366. axios.post('/api/local/compose/tag/untagme', {
  1367. status_id: this.statusId,
  1368. profile_id: id
  1369. }).then(res => {
  1370. this.status.taggedPeople = this.status.taggedPeople.filter(t => {
  1371. return t.id != id;
  1372. });
  1373. swal('Untagged', 'You have been untagged from this post.', 'success');
  1374. }).catch(err => {
  1375. swal('An Error Occurred', 'Please try again later.', 'error');
  1376. });
  1377. }
  1378. },
  1379. }
  1380. </script>