PostComponent.vue 64 KB

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