PostComponent.vue 54 KB

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