PostComponent.vue 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  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 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">Click <a href="#" class="cursor-pointer" @click.prevent="warning = false; fetchData()">here</a> to view this status</p>
  10. </div>
  11. </div>
  12. <div v-if="loaded && warning == false" class="postComponent">
  13. <div v-if="profileLayout == 'metro'" class="container px-0">
  14. <div class="card card-md-rounded-0 status-container orientation-unknown">
  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. <a :href="statusProfileUrl" class="d-flex align-items-center status-username text-truncate" data-toggle="tooltip" data-placement="bottom" :title="statusUsername">
  18. <div class="status-avatar mr-2">
  19. <img :src="statusAvatar" width="24px" height="24px" style="border-radius:12px;">
  20. </div>
  21. <div class="username">
  22. <span class="username-link font-weight-bold text-dark">{{ statusUsername }}</span>
  23. </div>
  24. </a>
  25. <div v-if="user != false" class="float-right">
  26. <div class="post-actions">
  27. <div class="dropdown">
  28. <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">
  29. <span class="fas fa-ellipsis-v text-muted"></span>
  30. </button>
  31. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
  32. <div v-if="!owner()">
  33. <a class="dropdown-item font-weight-bold" :href="reportUrl()">Report</a>
  34. <a class="dropdown-item font-weight-bold" v-on:click="muteProfile()">Mute Profile</a>
  35. <a class="dropdown-item font-weight-bold" v-on:click="blockProfile()">Block Profile</a>
  36. </div>
  37. <div v-if="ownerOrAdmin()">
  38. <a class="dropdown-item font-weight-bold" href="#" v-on:click.prevent="toggleCommentVisibility">{{ showComments ? 'Disable' : 'Enable'}} Comments</a>
  39. <a class="dropdown-item font-weight-bold" :href="editUrl()">Edit</a>
  40. <a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost(status)">Delete</a>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. <div class="col-12 col-md-8 px-0 mx-0">
  48. <div class="postPresenterContainer d-none d-flex justify-content-center align-items-center" v-on:dblclick="likeStatus">
  49. <div v-if="status.pf_type === 'photo'" class="w-100">
  50. <photo-presenter :status="status" v-on:lightbox="lightbox"></photo-presenter>
  51. </div>
  52. <div v-else-if="status.pf_type === 'video'" class="w-100">
  53. <video-presenter :status="status"></video-presenter>
  54. </div>
  55. <div v-else-if="status.pf_type === 'photo:album'" class="w-100">
  56. <photo-album-presenter :status="status" v-on:lightbox="lightbox"></photo-album-presenter>
  57. </div>
  58. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  59. <video-album-presenter :status="status"></video-album-presenter>
  60. </div>
  61. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  62. <mixed-album-presenter :status="status" v-on:lightbox="lightbox"></mixed-album-presenter>
  63. </div>
  64. <div v-else class="w-100">
  65. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  66. </div>
  67. </div>
  68. </div>
  69. <div class="col-12 col-md-4 px-0 d-flex flex-column border-left border-md-left-0">
  70. <div class="d-md-flex d-none align-items-center justify-content-between card-header py-3 bg-white">
  71. <a :href="statusProfileUrl" class="d-flex align-items-center status-username text-truncate" data-toggle="tooltip" data-placement="bottom" :title="statusUsername">
  72. <div class="status-avatar mr-2">
  73. <img :src="statusAvatar" width="24px" height="24px" style="border-radius:12px;">
  74. </div>
  75. <div class="username">
  76. <span class="username-link font-weight-bold text-dark">{{ statusUsername }}</span>
  77. </div>
  78. </a>
  79. <div class="float-right">
  80. <div class="post-actions">
  81. <div v-if="user != false" class="dropdown">
  82. <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">
  83. <span class="fas fa-ellipsis-v text-muted"></span>
  84. </button>
  85. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
  86. <span v-if="!owner()">
  87. <a class="dropdown-item font-weight-bold" :href="reportUrl()">Report</a>
  88. <a class="dropdown-item font-weight-bold" v-on:click="muteProfile">Mute Profile</a>
  89. <a class="dropdown-item font-weight-bold" v-on:click="blockProfile">Block Profile</a>
  90. </span>
  91. <span v-if="ownerOrAdmin()">
  92. <a class="dropdown-item font-weight-bold" href="#" v-on:click.prevent="toggleCommentVisibility">{{ showComments ? 'Disable' : 'Enable'}} Comments</a>
  93. <a class="dropdown-item font-weight-bold" :href="editUrl()">Edit</a>
  94. <a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost">Delete</a>
  95. </span>
  96. </div>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. <div class="d-flex flex-md-column flex-column-reverse h-100" style="overflow-y: auto;">
  102. <div class="card-body status-comments pb-5">
  103. <div class="status-comment">
  104. <p :class="[status.content.length > 420 ? 'mb-1 read-more' : 'mb-1']" style="overflow: hidden;">
  105. <span class="font-weight-bold pr-1">{{statusUsername}}</span>
  106. <span class="comment-text" :id="status.id + '-status-readmore'" v-html="status.content"></span>
  107. </p>
  108. <div v-if="showComments">
  109. <hr>
  110. <div class="postCommentsLoader text-center">
  111. <div class="spinner-border" role="status">
  112. <span class="sr-only">Loading...</span>
  113. </div>
  114. </div>
  115. <div class="postCommentsContainer d-none">
  116. <p v-if="status.reply_count > 10"class="mb-1 text-center load-more-link d-none"><a href="#" class="text-muted" v-on:click="loadMore">Load more comments</a></p>
  117. <div class="comments">
  118. <div v-for="(reply, index) in results" class="pb-3" :key="'tl' + reply.id + '_' + index">
  119. <div v-if="reply.sensitive == true">
  120. <div class="card card-body shadow-none border border-left-blue py-3 px-1 text-center small">
  121. <p class="mb-0">This comment may contain sensitive material</p>
  122. <p class="font-weight-bold text-primary cursor-pointer mb-0" @click="reply.sensitive = false;">Show</p>
  123. </div>
  124. </div>
  125. <div v-else>
  126. <p class="d-flex justify-content-between align-items-top read-more" style="overflow-y: hidden;">
  127. <span>
  128. <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>
  129. <span class="text-break" v-html="reply.content"></span>
  130. </span>
  131. <span class="pl-2" style="min-width:38px">
  132. <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>
  133. <post-menu :status="reply" :profile="user" :size="'sm'" :modal="'true'" class="d-inline-block pl-2" v-on:deletePost="deleteComment(reply.id, index)"></post-menu>
  134. </span>
  135. </p>
  136. <p class="">
  137. <a v-once class="text-muted mr-3 text-decoration-none small" style="width: 20px;" v-text="timeAgo(reply.created_at)" :href="reply.url"></a>
  138. <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>
  139. <span class="text-muted comment-reaction font-weight-bold cursor-pointer" v-on:click="replyFocus(reply, index)">Reply</span>
  140. </p>
  141. <div v-if="reply.reply_count > 0" class="cursor-pointer" style="margin-left:30px;" v-on:click="toggleReplies(reply)">
  142. <span class="show-reply-bar"></span>
  143. <span class="comment-reaction font-weight-bold text-muted">{{reply.thread ? 'Hide' : 'View'}} Replies ({{reply.reply_count}})</span>
  144. </div>
  145. <div v-if="reply.thread == true" class="comment-thread">
  146. <div v-for="(s, sindex) in reply.replies" class="pb-3" :key="'cr' + s.id + '_' + index">
  147. <p class="d-flex justify-content-between align-items-top read-more" style="overflow-y: hidden;">
  148. <span>
  149. <a class="text-dark font-weight-bold mr-1" :href="s.account.url" :title="s.account.username">{{s.account.username}}</a>
  150. <span class="text-break" v-html="s.content"></span>
  151. </span>
  152. <span class="pl-2" style="min-width:38px">
  153. <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>
  154. <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>
  155. </span>
  156. </p>
  157. <p class="">
  158. <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>
  159. <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>
  160. </p>
  161. </div>
  162. </div>
  163. </div>
  164. </div>
  165. </div>
  166. </div>
  167. </div>
  168. </div>
  169. </div>
  170. <div class="card-body flex-grow-0 py-1">
  171. <div class="reactions my-1">
  172. <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>
  173. <h3 v-if="!status.comments_disabled" class="far fa-comment pr-3 m-0 cursor-pointer" title="Comment" v-on:click="replyFocus(status)"></h3>
  174. <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>
  175. <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>
  176. </div>
  177. <div class="reaction-counts font-weight-bold mb-0">
  178. <span style="cursor:pointer;" v-on:click="likesModal">
  179. <span class="like-count">{{status.favourites_count || 0}}</span> likes
  180. </span>
  181. <span v-if="status.visibility == 'public'" class="float-right" style="cursor:pointer;" v-on:click="sharesModal">
  182. <span class="share-count pl-4">{{status.reblogs_count || 0}}</span> shares
  183. </span>
  184. </div>
  185. <div class="timestamp pt-2 d-flex align-items-bottom justify-content-between">
  186. <a v-bind:href="statusUrl" class="small text-muted">
  187. {{timestampFormat()}}
  188. </a>
  189. <span class="small text-muted text-capitalize cursor-pointer" v-on:click="visibilityModal">{{status.visibility}}</span>
  190. </div>
  191. </div>
  192. </div>
  193. <div v-if="showComments && user.length !== 0" class="card-footer bg-white px-2 py-0">
  194. <ul class="nav align-items-center emoji-reactions" style="overflow-x: scroll;flex-wrap: unset;">
  195. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜‚</li>
  196. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ’ฏ</li>
  197. <li class="nav-item" v-on:click="emojiReaction">โค๏ธ</li>
  198. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ™Œ</li>
  199. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ‘</li>
  200. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ‘Œ</li>
  201. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜</li>
  202. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜ฏ</li>
  203. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜ข</li>
  204. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜…</li>
  205. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜</li>
  206. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ™‚</li>
  207. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜Ž</li>
  208. <li class="nav-item" v-on:click="emojiReaction" v-for="e in emoji">{{e}}</li>
  209. </ul>
  210. </div>
  211. <div v-if="showComments" class="card-footer bg-white sticky-md-bottom p-0">
  212. <div v-if="user.length == 0" class="comment-form-guest p-3">
  213. <a href="/login">Login</a> to like or comment.
  214. </div>
  215. <form v-else class="border-0 rounded-0 align-middle" method="post" action="/i/comment" :data-id="statusId" data-truncate="false">
  216. <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>
  217. <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"/>
  218. </form>
  219. </div>
  220. </div>
  221. </div>
  222. </div>
  223. </div>
  224. <div v-if="profileLayout == 'moment'" class="momentui">
  225. <div class="bg-dark mt-md-n4">
  226. <div class="container" v-on:dblclick="likeStatus">
  227. <div class="postPresenterContainer d-none d-flex justify-content-center align-items-center bg-dark">
  228. <div v-if="status.pf_type === 'photo'" class="w-100">
  229. <photo-presenter :status="status" v-on:lightbox="lightbox"></photo-presenter>
  230. </div>
  231. <div v-else-if="status.pf_type === 'video'" class="w-100">
  232. <video-presenter :status="status"></video-presenter>
  233. </div>
  234. <div v-else-if="status.pf_type === 'photo:album'" class="w-100">
  235. <photo-album-presenter :status="status" v-on:lightbox="lightbox"></photo-album-presenter>
  236. </div>
  237. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  238. <video-album-presenter :status="status"></video-album-presenter>
  239. </div>
  240. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  241. <mixed-album-presenter :status="status" v-on:lightbox="lightbox"></mixed-album-presenter>
  242. </div>
  243. <div v-else class="w-100">
  244. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  245. </div>
  246. </div>
  247. </div>
  248. </div>
  249. <div class="bg-white">
  250. <div class="container">
  251. <div class="row py-5">
  252. <div class="col-12 col-md-8">
  253. <div class="reactions py-2">
  254. <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>
  255. <h3 v-if="!status.comments_disabled" class="far fa-comment pr-3 m-0 cursor-pointer" title="Comment" v-on:click="replyFocus(status)"></h3>
  256. <h3 v-if="status.visibility == 'public'" v-bind:class="[reactions.shared ? 'far fa-share-square pr-3 m-0 text-primary float-right cursor-pointer' : 'far fa-share-square pr-3 m-0 share-btn float-right cursor-pointer']" title="Share" v-on:click="shareStatus"></h3>
  257. </div>
  258. <div class="reaction-counts font-weight-bold mb-0">
  259. <span style="cursor:pointer;" v-on:click="likesModal">
  260. <span class="like-count">{{status.favourites_count || 0}}</span> likes
  261. </span>
  262. <span v-if="status.visibility == 'public'" class="float-right" style="cursor:pointer;" v-on:click="sharesModal">
  263. <span class="share-count pl-4">{{status.reblogs_count || 0}}</span> shares
  264. </span>
  265. </div>
  266. <hr>
  267. <div class="media align-items-center">
  268. <img :src="statusAvatar" class="rounded-circle shadow-lg mr-3" alt="avatar" width="72px" height="72px">
  269. <div class="media-body lead">
  270. by <a :href="statusProfileUrl">{{statusUsername}}</a>
  271. </div>
  272. </div>
  273. <hr>
  274. <div>
  275. <p class="lead"><i class="far fa-clock"></i> {{timestampFormat()}}</p>
  276. <div class="lead" v-html="status.content"></div>
  277. </div>
  278. </div>
  279. <div class="col-12 col-md-4">
  280. <div v-if="status.comments_disabled" class="bg-light p-5 text-center lead">
  281. <p class="mb-0">Comments have been disabled on this post.</p>
  282. </div>
  283. </div>
  284. </div>
  285. </div>
  286. </div>
  287. </div>
  288. </div>
  289. <b-modal ref="likesModal"
  290. id="l-modal"
  291. hide-footer
  292. centered
  293. title="Likes"
  294. body-class="list-group-flush p-0">
  295. <div class="list-group">
  296. <div class="list-group-item border-0" v-for="(user, index) in likes" :key="'modal_likes_'+index">
  297. <div class="media">
  298. <a :href="user.url">
  299. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + 'โ€™s avatar'" width="30px">
  300. </a>
  301. <div class="media-body">
  302. <p class="mb-0" style="font-size: 14px">
  303. <a :href="user.url" class="font-weight-bold text-dark">
  304. {{user.username}}
  305. </a>
  306. </p>
  307. <p class="text-muted mb-0" style="font-size: 14px">
  308. {{user.display_name}}
  309. </a>
  310. </p>
  311. </div>
  312. </div>
  313. </div>
  314. <infinite-loading @infinite="infiniteLikesHandler" spinner="spiral">
  315. <div slot="no-more"></div>
  316. <div slot="no-results"></div>
  317. </infinite-loading>
  318. </div>
  319. </b-modal>
  320. <b-modal ref="sharesModal"
  321. id="s-modal"
  322. hide-footer
  323. centered
  324. title="Shares"
  325. body-class="list-group-flush p-0">
  326. <div class="list-group">
  327. <div class="list-group-item border-0" v-for="(user, index) in shares" :key="'modal_shares_'+index">
  328. <div class="media">
  329. <a :href="user.url">
  330. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + 'โ€™s avatar'" width="30px">
  331. </a>
  332. <div class="media-body">
  333. <div class="d-inline-block">
  334. <p class="mb-0" style="font-size: 14px">
  335. <a :href="user.url" class="font-weight-bold text-dark">
  336. {{user.username}}
  337. </a>
  338. </p>
  339. <p class="text-muted mb-0" style="font-size: 14px">
  340. {{user.display_name}}
  341. </a>
  342. </p>
  343. </div>
  344. <p class="float-right"><!-- <a class="btn btn-primary font-weight-bold py-1" href="#">Follow</a> --></p>
  345. </div>
  346. </div>
  347. </div>
  348. <infinite-loading @infinite="infiniteSharesHandler" spinner="spiral">
  349. <div slot="no-more"></div>
  350. <div slot="no-results"></div>
  351. </infinite-loading>
  352. </div>
  353. </b-modal>
  354. <b-modal
  355. id="lightbox"
  356. ref="lightboxModal"
  357. :hide-header="true"
  358. :hide-footer="true"
  359. centered
  360. size="lg"
  361. body-class="p-0"
  362. >
  363. <div v-if="lightboxMedia" :class="lightboxMedia.filter_class">
  364. <img :src="lightboxMedia.url" class="img-fluid" style="min-height: 100%; min-width: 100%">
  365. </div>
  366. </b-modal>
  367. </div>
  368. </template>
  369. <style type="text/css" scoped>
  370. .status-comments,
  371. .reactions {
  372. background: #fff;
  373. }
  374. .postPresenterContainer {
  375. background: #fff;
  376. }
  377. ::-webkit-scrollbar {
  378. width: 0px;
  379. background: transparent;
  380. }
  381. .reply-btn {
  382. position: absolute;
  383. bottom: 12px;
  384. right: 20px;
  385. width: 60px;
  386. text-align: center;
  387. border-radius: 0 3px 3px 0;
  388. }
  389. .text-lighter {
  390. color:#B8C2CC !important;
  391. }
  392. .text-break {
  393. overflow-wrap: break-word;
  394. }
  395. .comments p {
  396. margin-bottom: 0;
  397. }
  398. .comment-reaction {
  399. font-size: 80%;
  400. }
  401. .show-reply-bar {
  402. display: inline-block;
  403. border-bottom: 1px solid #999;
  404. height: 0;
  405. margin-right: 16px;
  406. vertical-align: middle;
  407. width: 24px;
  408. }
  409. .comment-thread {
  410. margin: 4px 0 0 40px;
  411. width: calc(100% - 40px);
  412. }
  413. .emoji-reactions .nav-item {
  414. font-size: 1.2rem;
  415. padding: 9px;
  416. cursor: pointer;
  417. }
  418. .emoji-reactions::-webkit-scrollbar {
  419. width: 0px;
  420. height: 0px;
  421. background: transparent;
  422. }
  423. </style>
  424. <style type="text/css" scoped>
  425. .momentui .bg-dark {
  426. background: #000 !important;
  427. }
  428. .momentui .carousel.slide,
  429. .momentui .carousel-item {
  430. background: #000 !important;
  431. }
  432. </style>
  433. <script>
  434. pixelfed.postComponent = {};
  435. export default {
  436. props: [
  437. 'status-id',
  438. 'status-username',
  439. 'status-template',
  440. 'status-url',
  441. 'status-profile-url',
  442. 'status-avatar',
  443. 'status-profile-id',
  444. 'profile-layout'
  445. ],
  446. data() {
  447. return {
  448. status: false,
  449. media: {},
  450. user: false,
  451. reactions: {
  452. liked: false,
  453. shared: false
  454. },
  455. likes: [],
  456. likesPage: 1,
  457. shares: [],
  458. sharesPage: 1,
  459. lightboxMedia: false,
  460. replyText: '',
  461. relationship: {},
  462. results: [],
  463. pagination: {},
  464. min_id: 0,
  465. max_id: 0,
  466. reply_to_profile_id: 0,
  467. thread: false,
  468. showComments: false,
  469. warning: false,
  470. loaded: false,
  471. loading: null,
  472. replyingToId: this.statusId,
  473. replyToIndex: 0,
  474. emoji: ['๐Ÿ˜€','๐Ÿคฃ','๐Ÿ˜ƒ','๐Ÿ˜„','๐Ÿ˜†','๐Ÿ˜‰','๐Ÿ˜Š','๐Ÿ˜‹','๐Ÿ˜˜','๐Ÿ˜—','๐Ÿ˜™','๐Ÿ˜š','๐Ÿค—','๐Ÿคฉ','๐Ÿค”','๐Ÿคจ','๐Ÿ˜','๐Ÿ˜‘','๐Ÿ˜ถ','๐Ÿ™„','๐Ÿ˜','๐Ÿ˜ฃ','๐Ÿ˜ฅ','๐Ÿ˜ฎ','๐Ÿค','๐Ÿ˜ช','๐Ÿ˜ซ','๐Ÿ˜ด','๐Ÿ˜Œ','๐Ÿ˜›','๐Ÿ˜œ','๐Ÿ˜','๐Ÿคค','๐Ÿ˜’','๐Ÿ˜“','๐Ÿ˜”','๐Ÿ˜•','๐Ÿ™ƒ','๐Ÿค‘','๐Ÿ˜ฒ','๐Ÿ™','๐Ÿ˜–','๐Ÿ˜ž','๐Ÿ˜Ÿ','๐Ÿ˜ค','๐Ÿ˜ญ','๐Ÿ˜ฆ','๐Ÿ˜ง','๐Ÿ˜จ','๐Ÿ˜ฉ','๐Ÿคฏ','๐Ÿ˜ฌ','๐Ÿ˜ฐ','๐Ÿ˜ฑ','๐Ÿ˜ณ','๐Ÿคช','๐Ÿ˜ต','๐Ÿ˜ก','๐Ÿ˜ ','๐Ÿคฌ','๐Ÿ˜ท','๐Ÿค’','๐Ÿค•','๐Ÿคข','๐Ÿคฎ','๐Ÿคง','๐Ÿ˜‡','๐Ÿค ','๐Ÿคก','๐Ÿคฅ','๐Ÿคซ','๐Ÿคญ','๐Ÿง','๐Ÿค“','๐Ÿ˜ˆ','๐Ÿ‘ฟ','๐Ÿ‘น','๐Ÿ‘บ','๐Ÿ’€','๐Ÿ‘ป','๐Ÿ‘ฝ','๐Ÿค–','๐Ÿ’ฉ','๐Ÿ˜บ','๐Ÿ˜ธ','๐Ÿ˜น','๐Ÿ˜ป','๐Ÿ˜ผ','๐Ÿ˜ฝ','๐Ÿ™€','๐Ÿ˜ฟ','๐Ÿ˜พ','๐Ÿคฒ','๐Ÿ‘','๐Ÿค','๐Ÿ‘','๐Ÿ‘Ž','๐Ÿ‘Š','โœŠ','๐Ÿค›','๐Ÿคœ','๐Ÿคž','โœŒ๏ธ','๐ŸคŸ','๐Ÿค˜','๐Ÿ‘ˆ','๐Ÿ‘‰','๐Ÿ‘†','๐Ÿ‘‡','โ˜๏ธ','โœ‹','๐Ÿคš','๐Ÿ–','๐Ÿ––','๐Ÿ‘‹','๐Ÿค™','๐Ÿ’ช','๐Ÿ–•','โœ๏ธ','๐Ÿ™','๐Ÿ’','๐Ÿ’„','๐Ÿ’‹','๐Ÿ‘„','๐Ÿ‘…','๐Ÿ‘‚','๐Ÿ‘ƒ','๐Ÿ‘ฃ','๐Ÿ‘','๐Ÿ‘€','๐Ÿง ','๐Ÿ—ฃ','๐Ÿ‘ค','๐Ÿ‘ฅ'],
  475. }
  476. },
  477. beforeMount() {
  478. let u = new URLSearchParams(window.location.search);
  479. if(u.has('ui') && u.get('ui') == 'moment' && this.profileLayout != 'moment') {
  480. this.profileLayout = 'moment';
  481. }
  482. if(u.has('ui') && u.get('ui') == 'metro' && this.profileLayout != 'metro') {
  483. this.profileLayout = 'metro';
  484. }
  485. },
  486. mounted() {
  487. this.fetchRelationships();
  488. },
  489. updated() {
  490. $('.carousel').carousel();
  491. window.pixelfed.readmore();
  492. },
  493. methods: {
  494. showMuteBlock() {
  495. let sid = this.status.account.id;
  496. let uid = this.user.id;
  497. if(sid == uid) {
  498. $('.post-actions .menu-author').removeClass('d-none');
  499. } else {
  500. $('.post-actions .menu-user').removeClass('d-none');
  501. }
  502. },
  503. reportUrl() {
  504. return '/i/report?type=post&id=' + this.status.id;
  505. },
  506. editUrl() {
  507. return this.status.url + '/edit';
  508. },
  509. timestampFormat() {
  510. let ts = new Date(this.status.created_at);
  511. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  512. },
  513. fetchData() {
  514. axios.get('/api/v2/profile/'+this.statusUsername+'/status/'+this.statusId)
  515. .then(response => {
  516. let self = this;
  517. self.status = response.data.status;
  518. self.user = response.data.user;
  519. self.media = self.status.media_attachments;
  520. self.reactions = response.data.reactions;
  521. self.likes = response.data.likes;
  522. self.shares = response.data.shares;
  523. self.likesPage = 2;
  524. self.sharesPage = 2;
  525. this.showMuteBlock();
  526. if(self.status.comments_disabled == false) {
  527. self.showComments = true;
  528. this.fetchComments();
  529. }
  530. this.loaded = true;
  531. $('head title').text(this.status.account.username + ' posted a photo: ' + this.status.favourites_count + ' likes');
  532. }).catch(error => {
  533. if(!error.response) {
  534. } else {
  535. switch(error.response.status) {
  536. case 401:
  537. break;
  538. default:
  539. break;
  540. }
  541. }
  542. });
  543. },
  544. likesModal() {
  545. if(this.status.favourites_count == 0 || $('body').hasClass('loggedIn') == false) {
  546. return;
  547. }
  548. this.$refs.likesModal.show();
  549. },
  550. sharesModal() {
  551. if(this.status.reblogs_count == 0 || $('body').hasClass('loggedIn') == false) {
  552. return;
  553. }
  554. this.$refs.sharesModal.show();
  555. },
  556. infiniteLikesHandler($state) {
  557. let api = '/api/v2/likes/profile/'+this.statusUsername+'/status/'+this.statusId;
  558. axios.get(api, {
  559. params: {
  560. page: this.likesPage,
  561. },
  562. }).then(({ data }) => {
  563. if (data.data.length > 0) {
  564. this.likes.push(...data.data);
  565. this.likesPage++;
  566. $state.loaded();
  567. } else {
  568. $state.complete();
  569. }
  570. });
  571. },
  572. infiniteSharesHandler($state) {
  573. axios.get('/api/v2/shares/profile/'+this.statusUsername+'/status/'+this.statusId, {
  574. params: {
  575. page: this.sharesPage,
  576. },
  577. }).then(({ data }) => {
  578. if (data.data.length > 0) {
  579. this.shares.push(...data.data);
  580. this.sharesPage++;
  581. $state.loaded();
  582. } else {
  583. $state.complete();
  584. }
  585. });
  586. },
  587. likeStatus(event) {
  588. if($('body').hasClass('loggedIn') == false) {
  589. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  590. return;
  591. }
  592. axios.post('/i/like', {
  593. item: this.status.id
  594. }).then(res => {
  595. this.status.favourites_count = res.data.count;
  596. if(this.reactions.liked == true) {
  597. this.reactions.liked = false;
  598. let user = this.user.id;
  599. this.likes = this.likes.filter(function(like) {
  600. return like.id !== user;
  601. });
  602. } else {
  603. this.reactions.liked = true;
  604. let user = this.user;
  605. this.likes.push(user);
  606. }
  607. }).catch(err => {
  608. console.error(err);
  609. swal('Error', 'Something went wrong, please try again later.', 'error');
  610. });
  611. },
  612. shareStatus() {
  613. if($('body').hasClass('loggedIn') == false) {
  614. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  615. return;
  616. }
  617. axios.post('/i/share', {
  618. item: this.status.id
  619. }).then(res => {
  620. this.status.reblogs_count = res.data.count;
  621. if(this.reactions.shared == true) {
  622. this.reactions.shared = false;
  623. let user = this.user.id;
  624. this.shares = this.shares.filter(function(reaction) {
  625. return reaction.id !== user;
  626. });
  627. } else {
  628. this.reactions.shared = true;
  629. let user = this.user;
  630. this.shares.push(user);
  631. }
  632. }).catch(err => {
  633. console.error(err);
  634. swal('Error', 'Something went wrong, please try again later.', 'error');
  635. });
  636. },
  637. bookmarkStatus() {
  638. if($('body').hasClass('loggedIn') == false) {
  639. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  640. return;
  641. }
  642. axios.post('/i/bookmark', {
  643. item: this.status.id
  644. }).then(res => {
  645. if(this.reactions.bookmarked == true) {
  646. this.reactions.bookmarked = false;
  647. } else {
  648. this.reactions.bookmarked = true;
  649. }
  650. }).catch(err => {
  651. swal('Error', 'Something went wrong, please try again later.', 'error');
  652. });
  653. },
  654. muteProfile() {
  655. if($('body').hasClass('loggedIn') == false) {
  656. return;
  657. }
  658. axios.post('/i/mute', {
  659. type: 'user',
  660. item: this.status.account.id
  661. }).then(res => {
  662. swal('Success', 'You have successfully muted ' + this.status.account.acct, 'success');
  663. }).catch(err => {
  664. swal('Error', 'Something went wrong. Please try again later.', 'error');
  665. });
  666. },
  667. blockProfile() {
  668. if($('body').hasClass('loggedIn') == false) {
  669. return;
  670. }
  671. axios.post('/i/block', {
  672. type: 'user',
  673. item: this.status.account.id
  674. }).then(res => {
  675. swal('Success', 'You have successfully blocked ' + this.status.account.acct, 'success');
  676. }).catch(err => {
  677. swal('Error', 'Something went wrong. Please try again later.', 'error');
  678. });
  679. },
  680. deletePost(status) {
  681. if(!this.ownerOrAdmin()) {
  682. return;
  683. }
  684. var result = confirm('Are you sure you want to delete this post?');
  685. if (result) {
  686. if($('body').hasClass('loggedIn') == false) {
  687. return;
  688. }
  689. axios.post('/i/delete', {
  690. type: 'status',
  691. item: this.status.id
  692. }).then(res => {
  693. swal('Success', 'You have successfully deleted this post', 'success');
  694. setTimeout(function() {
  695. window.location.href = '/';
  696. }, 3000);
  697. }).catch(err => {
  698. swal('Error', 'Something went wrong. Please try again later.', 'error');
  699. });
  700. }
  701. },
  702. owner() {
  703. return this.user.id === this.status.account.id;
  704. },
  705. admin() {
  706. return this.user.is_admin == true;
  707. },
  708. ownerOrAdmin() {
  709. return this.owner() || this.admin();
  710. },
  711. lightbox(src) {
  712. this.lightboxMedia = src;
  713. this.$refs.lightboxModal.show();
  714. },
  715. postReply() {
  716. let self = this;
  717. if(this.replyText.length == 0 ||
  718. this.replyText.trim() == '@'+this.status.account.acct) {
  719. self.replyText = null;
  720. $('textarea[name="comment"]').blur();
  721. return;
  722. }
  723. let data = {
  724. item: this.replyingToId,
  725. comment: this.replyText
  726. }
  727. axios.post('/i/comment', data)
  728. .then(function(res) {
  729. let entity = res.data.entity;
  730. if(entity.in_reply_to_id == self.status.id) {
  731. self.results.push(entity);
  732. let elem = $('.status-comments')[0];
  733. elem.scrollTop = elem.clientHeight;
  734. } else {
  735. if(self.replyToIndex >= 0) {
  736. let el = self.results[self.replyToIndex];
  737. el.replies.push(entity);
  738. el.reply_count = el.reply_count + 1;
  739. }
  740. }
  741. self.replyText = '';
  742. });
  743. },
  744. deleteComment(id, i) {
  745. axios.post('/i/delete', {
  746. type: 'comment',
  747. item: id
  748. }).then(res => {
  749. this.results.splice(i, 1);
  750. }).catch(err => {
  751. swal('Something went wrong!', 'Please try again later', 'error');
  752. });
  753. },
  754. deleteCommentReply(id, i, pi) {
  755. axios.post('/i/delete', {
  756. type: 'comment',
  757. item: id
  758. }).then(res => {
  759. this.results[pi].replies.splice(i, 1);
  760. --this.results[pi].reply_count;
  761. }).catch(err => {
  762. swal('Something went wrong!', 'Please try again later', 'error');
  763. });
  764. },
  765. l(e) {
  766. let len = e.length;
  767. if(len < 10) { return e; }
  768. return e.substr(0, 10)+'...';
  769. },
  770. replyFocus(e, index) {
  771. this.replyToIndex = index;
  772. this.replyingToId = e.id;
  773. this.reply_to_profile_id = e.account.id;
  774. this.replyText = '@' + e.account.username + ' ';
  775. $('textarea[name="comment"]').focus();
  776. },
  777. fetchComments() {
  778. let url = '/api/v2/comments/'+this.statusUsername+'/status/'+this.statusId;
  779. axios.get(url)
  780. .then(response => {
  781. let self = this;
  782. this.results = _.reverse(response.data.data);
  783. this.pagination = response.data.meta.pagination;
  784. if(this.results.length > 0) {
  785. $('.load-more-link').removeClass('d-none');
  786. }
  787. $('.postCommentsLoader').addClass('d-none');
  788. $('.postCommentsContainer').removeClass('d-none');
  789. }).catch(error => {
  790. if(!error.response) {
  791. $('.postCommentsLoader .lds-ring')
  792. .attr('style','width:100%')
  793. .addClass('pt-4 font-weight-bold text-muted')
  794. .text('An error occurred, cannot fetch comments. Please try again later.');
  795. } else {
  796. switch(error.response.status) {
  797. case 401:
  798. $('.postCommentsLoader .lds-ring')
  799. .attr('style','width:100%')
  800. .addClass('pt-4 font-weight-bold text-muted')
  801. .text('Please login to view.');
  802. break;
  803. default:
  804. $('.postCommentsLoader .lds-ring')
  805. .attr('style','width:100%')
  806. .addClass('pt-4 font-weight-bold text-muted')
  807. .text('An error occurred, cannot fetch comments. Please try again later.');
  808. break;
  809. }
  810. }
  811. });
  812. },
  813. loadMore(e) {
  814. e.preventDefault();
  815. if(this.pagination.total_pages == 1 || this.pagination.current_page == this.pagination.total_pages) {
  816. $('.load-more-link').addClass('d-none');
  817. return;
  818. }
  819. $('.postCommentsLoader').removeClass('d-none');
  820. let next = this.pagination.links.next;
  821. axios.get(next)
  822. .then(response => {
  823. let self = this;
  824. let res = response.data.data;
  825. $('.postCommentsLoader').addClass('d-none');
  826. for(let i=0; i < res.length; i++) {
  827. this.results.unshift(res[i]);
  828. }
  829. this.pagination = response.data.meta.pagination;
  830. });
  831. },
  832. likeReply(status, $event) {
  833. if($('body').hasClass('loggedIn') == false) {
  834. return;
  835. }
  836. axios.post('/i/like', {
  837. item: status.id
  838. }).then(res => {
  839. status.favourites_count = res.data.count;
  840. if(status.favourited == true) {
  841. status.favourited = false;
  842. } else {
  843. status.favourited = true;
  844. }
  845. }).catch(err => {
  846. swal('Error', 'Something went wrong, please try again later.', 'error');
  847. });
  848. },
  849. truncate(str,lim) {
  850. return _.truncate(str,{
  851. length: lim
  852. });
  853. },
  854. timeAgo(ts) {
  855. let date = Date.parse(ts);
  856. let seconds = Math.floor((new Date() - date) / 1000);
  857. let interval = Math.floor(seconds / 31536000);
  858. if (interval >= 1) {
  859. return interval + "y";
  860. }
  861. interval = Math.floor(seconds / 604800);
  862. if (interval >= 1) {
  863. return interval + "w";
  864. }
  865. interval = Math.floor(seconds / 86400);
  866. if (interval >= 1) {
  867. return interval + "d";
  868. }
  869. interval = Math.floor(seconds / 3600);
  870. if (interval >= 1) {
  871. return interval + "h";
  872. }
  873. interval = Math.floor(seconds / 60);
  874. if (interval >= 1) {
  875. return interval + "m";
  876. }
  877. return Math.floor(seconds) + "s";
  878. },
  879. emojiReaction() {
  880. let em = event.target.innerText;
  881. if(this.replyText.length == 0) {
  882. this.reply_to_profile_id = this.status.account.id;
  883. this.replyText = em + ' ';
  884. $('textarea[name="comment"]').focus();
  885. } else {
  886. this.reply_to_profile_id = this.status.account.id;
  887. this.replyText += em + ' ';
  888. $('textarea[name="comment"]').focus();
  889. }
  890. },
  891. toggleCommentVisibility() {
  892. if(this.ownerOrAdmin() == false) {
  893. return;
  894. }
  895. let state = this.status.comments_disabled;
  896. let self = this;
  897. if(state == true) {
  898. // re-enable comments
  899. axios.post('/i/visibility', {
  900. item: self.status.id,
  901. disableComments: false
  902. }).then(function(res) {
  903. window.location.href = self.status.url;
  904. }).catch(function(err) {
  905. return;
  906. });
  907. } else {
  908. // disable comments
  909. axios.post('/i/visibility', {
  910. item: self.status.id,
  911. disableComments: true
  912. }).then(function(res) {
  913. self.status.comments_disabled = false;
  914. self.showComments = false;
  915. }).catch(function(err) {
  916. return;
  917. });
  918. }
  919. },
  920. fetchRelationships() {
  921. if(document.querySelectorAll('body')[0].classList.contains('loggedIn') == false) {
  922. this.fetchData();
  923. return;
  924. } else {
  925. axios.get('/api/v1/accounts/relationships', {
  926. params: {
  927. 'id[]': this.statusProfileId
  928. }
  929. }).then(res => {
  930. if(res.data[0] == null) {
  931. this.fetchData();
  932. return;
  933. }
  934. this.relationship = res.data[0];
  935. if(res.data[0].blocking == true) {
  936. this.loaded = true;
  937. this.warning = true;
  938. return;
  939. } else {
  940. this.fetchData();
  941. return;
  942. }
  943. });
  944. }
  945. },
  946. visibilityModal() {
  947. switch(this.status.visibility) {
  948. case 'public':
  949. swal('Public Post', 'This post is visible to everyone.', 'info');
  950. break;
  951. case 'unlisted':
  952. swal('Unlisted Post', 'This post is visible on profiles and with a direct links. It is not displayed on timelines.', 'info');
  953. break;
  954. case 'private':
  955. swal('Private Post', 'This post is only visible to followers.', 'info');
  956. break;
  957. }
  958. },
  959. toggleReplies(reply) {
  960. if(reply.thread) {
  961. reply.thread = false;
  962. } else {
  963. if(reply.replies.length > 0) {
  964. reply.thread = true;
  965. return;
  966. }
  967. let url = '/api/v2/comments/'+reply.account.username+'/status/'+reply.id;
  968. axios.get(url)
  969. .then(response => {
  970. reply.replies = _.reverse(response.data.data);
  971. reply.thread = true;
  972. });
  973. }
  974. }
  975. },
  976. }
  977. </script>