PostComponent.vue 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  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">
  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. <div class="postCommentsLoader text-center">
  110. <div class="spinner-border" role="status">
  111. <span class="sr-only">Loading...</span>
  112. </div>
  113. </div>
  114. <div class="postCommentsContainer d-none pt-3">
  115. <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>
  116. <div class="comments">
  117. <div v-for="(reply, index) in results" class="pb-3" :key="'tl' + reply.id + '_' + index">
  118. <p class="d-flex justify-content-between align-items-top read-more" style="overflow-y: hidden;">
  119. <span>
  120. <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>
  121. <span class="text-break" v-html="reply.content"></span>
  122. </span>
  123. <span class="pl-2" style="min-width:38px">
  124. <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>
  125. <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>
  126. </span>
  127. </p>
  128. <p class="">
  129. <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>
  130. <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>
  131. <span class="text-muted comment-reaction font-weight-bold cursor-pointer" v-on:click="replyFocus(reply, index)">Reply</span>
  132. </p>
  133. <div v-if="reply.reply_count > 0" class="cursor-pointer" style="margin-left:30px;" v-on:click="toggleReplies(reply)">
  134. <span class="show-reply-bar"></span>
  135. <span class="comment-reaction font-weight-bold text-muted">{{reply.thread ? 'Hide' : 'View'}} Replies ({{reply.reply_count}})</span>
  136. </div>
  137. <div v-if="reply.thread == true" class="comment-thread">
  138. <div v-for="(s, sindex) in reply.replies" class="pb-3" :key="'cr' + s.id + '_' + index">
  139. <p class="d-flex justify-content-between align-items-top read-more" style="overflow-y: hidden;">
  140. <span>
  141. <a class="text-dark font-weight-bold mr-1" :href="s.account.url" :title="s.account.username">{{s.account.username}}</a>
  142. <span class="text-break" v-html="s.content"></span>
  143. </span>
  144. <span class="pl-2" style="min-width:38px">
  145. <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>
  146. <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>
  147. </span>
  148. </p>
  149. <p class="">
  150. <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>
  151. <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>
  152. </p>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. </div>
  158. </div>
  159. </div>
  160. </div>
  161. <div class="card-body flex-grow-0 py-1">
  162. <div class="reactions my-1">
  163. <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>
  164. <h3 v-if="!status.comments_disabled" class="far fa-comment pr-3 m-0 cursor-pointer" title="Comment" v-on:click="replyFocus(status)"></h3>
  165. <h3 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>
  166. <h3 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>
  167. </div>
  168. <div class="reaction-counts font-weight-bold mb-0">
  169. <span style="cursor:pointer;" v-on:click="likesModal">
  170. <span class="like-count">{{status.favourites_count || 0}}</span> likes
  171. </span>
  172. <span class="float-right" style="cursor:pointer;" v-on:click="sharesModal">
  173. <span class="share-count pl-4">{{status.reblogs_count || 0}}</span> shares
  174. </span>
  175. </div>
  176. <div class="timestamp pt-2 d-flex align-items-bottom justify-content-between">
  177. <a v-bind:href="statusUrl" class="small text-muted">
  178. {{timestampFormat()}}
  179. </a>
  180. <span class="small text-muted text-capitalize cursor-pointer" v-on:click="visibilityModal">{{status.visibility}}</span>
  181. </div>
  182. </div>
  183. </div>
  184. <div v-if="showComments && user.length !== 0" class="card-footer bg-white px-2 py-0">
  185. <ul class="nav align-items-center emoji-reactions" style="overflow-x: scroll;flex-wrap: unset;">
  186. <li class="nav-item" v-on:click="emojiReaction">😂</li>
  187. <li class="nav-item" v-on:click="emojiReaction">💯</li>
  188. <li class="nav-item" v-on:click="emojiReaction">❤️</li>
  189. <li class="nav-item" v-on:click="emojiReaction">🙌</li>
  190. <li class="nav-item" v-on:click="emojiReaction">👏</li>
  191. <li class="nav-item" v-on:click="emojiReaction">😍</li>
  192. <li class="nav-item" v-on:click="emojiReaction">😯</li>
  193. <li class="nav-item" v-on:click="emojiReaction">😢</li>
  194. <li class="nav-item" v-on:click="emojiReaction">😅</li>
  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. </ul>
  199. </div>
  200. <div v-if="showComments" class="card-footer bg-white sticky-md-bottom p-0">
  201. <div v-if="user.length == 0" class="comment-form-guest p-3">
  202. <a href="/login">Login</a> to like or comment.
  203. </div>
  204. <form v-else class="border-0 rounded-0 align-middle" method="post" action="/i/comment" :data-id="statusId" data-truncate="false">
  205. <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>
  206. <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"/>
  207. </form>
  208. </div>
  209. </div>
  210. </div>
  211. </div>
  212. </div>
  213. <div v-if="profileLayout == 'moment'" class="momentui">
  214. <div class="bg-dark mt-md-n4">
  215. <div class="container" v-on:dblclick="likeStatus">
  216. <div class="postPresenterContainer d-none d-flex justify-content-center align-items-center bg-dark">
  217. <div v-if="status.pf_type === 'photo'" class="w-100">
  218. <photo-presenter :status="status" v-on:lightbox="lightbox"></photo-presenter>
  219. </div>
  220. <div v-else-if="status.pf_type === 'video'" class="w-100">
  221. <video-presenter :status="status"></video-presenter>
  222. </div>
  223. <div v-else-if="status.pf_type === 'photo:album'" class="w-100">
  224. <photo-album-presenter :status="status" v-on:lightbox="lightbox"></photo-album-presenter>
  225. </div>
  226. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  227. <video-album-presenter :status="status"></video-album-presenter>
  228. </div>
  229. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  230. <mixed-album-presenter :status="status" v-on:lightbox="lightbox"></mixed-album-presenter>
  231. </div>
  232. <div v-else class="w-100">
  233. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  234. </div>
  235. </div>
  236. </div>
  237. </div>
  238. <div class="bg-white">
  239. <div class="container">
  240. <div class="row py-5">
  241. <div class="col-12 col-md-8">
  242. <div class="reactions py-2">
  243. <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>
  244. <h3 v-if="!status.comments_disabled" class="far fa-comment pr-3 m-0 cursor-pointer" title="Comment" v-on:click="replyFocus(status)"></h3>
  245. <h3 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>
  246. </div>
  247. <div class="reaction-counts font-weight-bold mb-0">
  248. <span style="cursor:pointer;" v-on:click="likesModal">
  249. <span class="like-count">{{status.favourites_count || 0}}</span> likes
  250. </span>
  251. <span class="float-right" style="cursor:pointer;" v-on:click="sharesModal">
  252. <span class="share-count pl-4">{{status.reblogs_count || 0}}</span> shares
  253. </span>
  254. </div>
  255. <hr>
  256. <div class="media align-items-center">
  257. <img :src="statusAvatar" class="rounded-circle shadow-lg mr-3" alt="avatar" width="72px" height="72px">
  258. <div class="media-body lead">
  259. by <a :href="statusProfileUrl">{{statusUsername}}</a>
  260. </div>
  261. </div>
  262. <hr>
  263. <div>
  264. <p class="lead"><i class="far fa-clock"></i> {{timestampFormat()}}</p>
  265. <div class="lead" v-html="status.content"></div>
  266. </div>
  267. </div>
  268. <div class="col-12 col-md-4">
  269. <div v-if="status.comments_disabled" class="bg-light p-5 text-center lead">
  270. <p class="mb-0">Comments have been disabled on this post.</p>
  271. </div>
  272. </div>
  273. </div>
  274. </div>
  275. </div>
  276. </div>
  277. </div>
  278. <b-modal ref="likesModal"
  279. id="l-modal"
  280. hide-footer
  281. centered
  282. title="Likes"
  283. body-class="list-group-flush p-0">
  284. <div class="list-group">
  285. <div class="list-group-item border-0" v-for="(user, index) in likes" :key="'modal_likes_'+index">
  286. <div class="media">
  287. <a :href="user.url">
  288. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  289. </a>
  290. <div class="media-body">
  291. <p class="mb-0" style="font-size: 14px">
  292. <a :href="user.url" class="font-weight-bold text-dark">
  293. {{user.username}}
  294. </a>
  295. </p>
  296. <p class="text-muted mb-0" style="font-size: 14px">
  297. {{user.display_name}}
  298. </a>
  299. </p>
  300. </div>
  301. </div>
  302. </div>
  303. <infinite-loading @infinite="infiniteLikesHandler" spinner="spiral">
  304. <div slot="no-more"></div>
  305. <div slot="no-results"></div>
  306. </infinite-loading>
  307. </div>
  308. </b-modal>
  309. <b-modal ref="sharesModal"
  310. id="s-modal"
  311. hide-footer
  312. centered
  313. title="Shares"
  314. body-class="list-group-flush p-0">
  315. <div class="list-group">
  316. <div class="list-group-item border-0" v-for="(user, index) in shares" :key="'modal_shares_'+index">
  317. <div class="media">
  318. <a :href="user.url">
  319. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  320. </a>
  321. <div class="media-body">
  322. <div class="d-inline-block">
  323. <p class="mb-0" style="font-size: 14px">
  324. <a :href="user.url" class="font-weight-bold text-dark">
  325. {{user.username}}
  326. </a>
  327. </p>
  328. <p class="text-muted mb-0" style="font-size: 14px">
  329. {{user.display_name}}
  330. </a>
  331. </p>
  332. </div>
  333. <p class="float-right"><!-- <a class="btn btn-primary font-weight-bold py-1" href="#">Follow</a> --></p>
  334. </div>
  335. </div>
  336. </div>
  337. <infinite-loading @infinite="infiniteSharesHandler" spinner="spiral">
  338. <div slot="no-more"></div>
  339. <div slot="no-results"></div>
  340. </infinite-loading>
  341. </div>
  342. </b-modal>
  343. <b-modal
  344. id="lightbox"
  345. ref="lightboxModal"
  346. :hide-header="true"
  347. :hide-footer="true"
  348. centered
  349. size="lg"
  350. body-class="p-0"
  351. >
  352. <div v-if="lightboxMedia" :class="lightboxMedia.filter_class">
  353. <img :src="lightboxMedia.url" class="img-fluid" style="min-height: 100%; min-width: 100%">
  354. </div>
  355. </b-modal>
  356. </div>
  357. </template>
  358. <style type="text/css" scoped>
  359. .status-comments,
  360. .reactions {
  361. background: #fff;
  362. }
  363. .postPresenterContainer {
  364. background: #fff;
  365. }
  366. @media(min-width: 720px) {
  367. .postPresenterContainer {
  368. min-height: 600px;
  369. }
  370. }
  371. ::-webkit-scrollbar {
  372. width: 0px;
  373. background: transparent;
  374. }
  375. .reply-btn {
  376. position: absolute;
  377. bottom: 12px;
  378. right: 20px;
  379. width: 60px;
  380. text-align: center;
  381. border-radius: 0 3px 3px 0;
  382. }
  383. .text-lighter {
  384. color:#B8C2CC !important;
  385. }
  386. .text-break {
  387. overflow-wrap: break-word;
  388. }
  389. .comments p {
  390. margin-bottom: 0;
  391. }
  392. .comment-reaction {
  393. font-size: 80%;
  394. }
  395. .show-reply-bar {
  396. display: inline-block;
  397. border-bottom: 1px solid #999;
  398. height: 0;
  399. margin-right: 16px;
  400. vertical-align: middle;
  401. width: 24px;
  402. }
  403. .comment-thread {
  404. margin: 4px 0 0 40px;
  405. width: calc(100% - 40px);
  406. }
  407. .emoji-reactions .nav-item {
  408. font-size: 1.2rem;
  409. padding: 9px;
  410. cursor: pointer;
  411. }
  412. .emoji-reactions::-webkit-scrollbar {
  413. width: 0px;
  414. height: 0px;
  415. background: transparent;
  416. }
  417. </style>
  418. <style type="text/css">
  419. .momentui .bg-dark {
  420. background: #000 !important;
  421. }
  422. .momentui .carousel.slide,
  423. .momentui .carousel-item {
  424. background: #000 !important;
  425. }
  426. </style>
  427. <script>
  428. pixelfed.postComponent = {};
  429. export default {
  430. props: [
  431. 'status-id',
  432. 'status-username',
  433. 'status-template',
  434. 'status-url',
  435. 'status-profile-url',
  436. 'status-avatar',
  437. 'status-profile-id',
  438. 'profile-layout'
  439. ],
  440. data() {
  441. return {
  442. status: false,
  443. media: {},
  444. user: false,
  445. reactions: {
  446. liked: false,
  447. shared: false
  448. },
  449. likes: [],
  450. likesPage: 1,
  451. shares: [],
  452. sharesPage: 1,
  453. lightboxMedia: false,
  454. replyText: '',
  455. relationship: {},
  456. results: [],
  457. pagination: {},
  458. min_id: 0,
  459. max_id: 0,
  460. reply_to_profile_id: 0,
  461. thread: false,
  462. showComments: false,
  463. warning: false,
  464. loaded: false,
  465. loading: null,
  466. replyingToId: this.statusId,
  467. replyToIndex: 0,
  468. emoji: ['😀','😁','😂','🤣','😃','😄','😅','😆','😉','😊','😋','😎','😍','😘','😗','😙','😚','☺️','🙂','🤗','🤩','🤔','🤨','😐','😑','😶','🙄','😏','😣','😥','😮','🤐','😯','😪','😫','😴','😌','😛','😜','😝','🤤','😒','😓','😔','😕','🙃','🤑','😲','☹️','🙁','😖','😞','😟','😤','😢','😭','😦','😧','😨','😩','🤯','😬','😰','😱','😳','🤪','😵','😡','😠','🤬','😷','🤒','🤕','🤢','🤮','🤧','😇','🤠','🤡','🤥','🤫','🤭','🧐','🤓','😈','👿','👹','👺','💀','👻','👽','🤖','💩','😺','😸','😹','😻','😼','😽','🙀','😿','😾','🤲','👐','🙌','👏','🤝','👍','👎','👊','✊','🤛','🤜','🤞','✌️','🤟','🤘','👌','👈','👉','👆','👇','☝️','✋','🤚','🖐','🖖','👋','🤙','💪','🖕','✍️','🙏','💍','💄','💋','👄','👅','👂','👃','👣','👁','👀','🧠','🗣','👤','👥'],
  469. }
  470. },
  471. mounted() {
  472. this.fetchRelationships();
  473. },
  474. updated() {
  475. $('.carousel').carousel();
  476. window.pixelfed.readmore();
  477. },
  478. methods: {
  479. showMuteBlock() {
  480. let sid = this.status.account.id;
  481. let uid = this.user.id;
  482. if(sid == uid) {
  483. $('.post-actions .menu-author').removeClass('d-none');
  484. } else {
  485. $('.post-actions .menu-user').removeClass('d-none');
  486. }
  487. },
  488. reportUrl() {
  489. return '/i/report?type=post&id=' + this.status.id;
  490. },
  491. editUrl() {
  492. return this.status.url + '/edit';
  493. },
  494. timestampFormat() {
  495. let ts = new Date(this.status.created_at);
  496. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  497. },
  498. fetchData() {
  499. axios.get('/api/v2/profile/'+this.statusUsername+'/status/'+this.statusId)
  500. .then(response => {
  501. let self = this;
  502. self.status = response.data.status;
  503. self.user = response.data.user;
  504. self.media = self.status.media_attachments;
  505. self.reactions = response.data.reactions;
  506. self.likes = response.data.likes;
  507. self.shares = response.data.shares;
  508. self.likesPage = 2;
  509. self.sharesPage = 2;
  510. this.showMuteBlock();
  511. if(self.status.comments_disabled == false) {
  512. self.showComments = true;
  513. this.fetchComments();
  514. }
  515. this.loaded = true;
  516. $('head title').text(this.status.account.username + ' posted a photo: ' + this.status.favourites_count + ' likes');
  517. }).catch(error => {
  518. if(!error.response) {
  519. } else {
  520. switch(error.response.status) {
  521. case 401:
  522. break;
  523. default:
  524. break;
  525. }
  526. }
  527. });
  528. },
  529. likesModal() {
  530. if(this.status.favourites_count == 0 || $('body').hasClass('loggedIn') == false) {
  531. return;
  532. }
  533. this.$refs.likesModal.show();
  534. },
  535. sharesModal() {
  536. if(this.status.reblogs_count == 0 || $('body').hasClass('loggedIn') == false) {
  537. return;
  538. }
  539. this.$refs.sharesModal.show();
  540. },
  541. infiniteLikesHandler($state) {
  542. let api = '/api/v2/likes/profile/'+this.statusUsername+'/status/'+this.statusId;
  543. axios.get(api, {
  544. params: {
  545. page: this.likesPage,
  546. },
  547. }).then(({ data }) => {
  548. if (data.data.length > 0) {
  549. this.likes.push(...data.data);
  550. this.likesPage++;
  551. $state.loaded();
  552. } else {
  553. $state.complete();
  554. }
  555. });
  556. },
  557. infiniteSharesHandler($state) {
  558. axios.get('/api/v2/shares/profile/'+this.statusUsername+'/status/'+this.statusId, {
  559. params: {
  560. page: this.sharesPage,
  561. },
  562. }).then(({ data }) => {
  563. if (data.data.length > 0) {
  564. this.shares.push(...data.data);
  565. this.sharesPage++;
  566. $state.loaded();
  567. } else {
  568. $state.complete();
  569. }
  570. });
  571. },
  572. likeStatus(event) {
  573. if($('body').hasClass('loggedIn') == false) {
  574. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  575. return;
  576. }
  577. axios.post('/i/like', {
  578. item: this.status.id
  579. }).then(res => {
  580. this.status.favourites_count = res.data.count;
  581. if(this.reactions.liked == true) {
  582. this.reactions.liked = false;
  583. let user = this.user.id;
  584. this.likes = this.likes.filter(function(like) {
  585. return like.id !== user;
  586. });
  587. } else {
  588. this.reactions.liked = true;
  589. let user = this.user;
  590. this.likes.push(user);
  591. }
  592. }).catch(err => {
  593. console.error(err);
  594. swal('Error', 'Something went wrong, please try again later.', 'error');
  595. });
  596. },
  597. shareStatus() {
  598. if($('body').hasClass('loggedIn') == false) {
  599. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  600. return;
  601. }
  602. axios.post('/i/share', {
  603. item: this.status.id
  604. }).then(res => {
  605. this.status.reblogs_count = res.data.count;
  606. if(this.reactions.shared == true) {
  607. this.reactions.shared = false;
  608. let user = this.user.id;
  609. this.shares = this.shares.filter(function(reaction) {
  610. return reaction.id !== user;
  611. });
  612. } else {
  613. this.reactions.shared = true;
  614. let user = this.user;
  615. this.shares.push(user);
  616. }
  617. }).catch(err => {
  618. console.error(err);
  619. swal('Error', 'Something went wrong, please try again later.', 'error');
  620. });
  621. },
  622. bookmarkStatus() {
  623. if($('body').hasClass('loggedIn') == false) {
  624. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  625. return;
  626. }
  627. axios.post('/i/bookmark', {
  628. item: this.status.id
  629. }).then(res => {
  630. if(this.reactions.bookmarked == true) {
  631. this.reactions.bookmarked = false;
  632. } else {
  633. this.reactions.bookmarked = true;
  634. }
  635. }).catch(err => {
  636. swal('Error', 'Something went wrong, please try again later.', 'error');
  637. });
  638. },
  639. muteProfile() {
  640. if($('body').hasClass('loggedIn') == false) {
  641. return;
  642. }
  643. axios.post('/i/mute', {
  644. type: 'user',
  645. item: this.status.account.id
  646. }).then(res => {
  647. swal('Success', 'You have successfully muted ' + this.status.account.acct, 'success');
  648. }).catch(err => {
  649. swal('Error', 'Something went wrong. Please try again later.', 'error');
  650. });
  651. },
  652. blockProfile() {
  653. if($('body').hasClass('loggedIn') == false) {
  654. return;
  655. }
  656. axios.post('/i/block', {
  657. type: 'user',
  658. item: this.status.account.id
  659. }).then(res => {
  660. swal('Success', 'You have successfully blocked ' + this.status.account.acct, 'success');
  661. }).catch(err => {
  662. swal('Error', 'Something went wrong. Please try again later.', 'error');
  663. });
  664. },
  665. deletePost(status) {
  666. if(!this.ownerOrAdmin()) {
  667. return;
  668. }
  669. var result = confirm('Are you sure you want to delete this post?');
  670. if (result) {
  671. if($('body').hasClass('loggedIn') == false) {
  672. return;
  673. }
  674. axios.post('/i/delete', {
  675. type: 'status',
  676. item: this.status.id
  677. }).then(res => {
  678. swal('Success', 'You have successfully deleted this post', 'success');
  679. window.location.href = '/';
  680. }).catch(err => {
  681. swal('Error', 'Something went wrong. Please try again later.', 'error');
  682. });
  683. }
  684. },
  685. owner() {
  686. return this.user.id === this.status.account.id;
  687. },
  688. admin() {
  689. return this.user.is_admin == true;
  690. },
  691. ownerOrAdmin() {
  692. return this.owner() || this.admin();
  693. },
  694. lightbox(src) {
  695. this.lightboxMedia = src;
  696. this.$refs.lightboxModal.show();
  697. },
  698. postReply() {
  699. let self = this;
  700. if(this.replyText.length == 0 ||
  701. this.replyText.trim() == '@'+this.status.account.acct) {
  702. self.replyText = null;
  703. $('textarea[name="comment"]').blur();
  704. return;
  705. }
  706. let data = {
  707. item: this.replyingToId,
  708. comment: this.replyText
  709. }
  710. axios.post('/i/comment', data)
  711. .then(function(res) {
  712. let entity = res.data.entity;
  713. if(entity.in_reply_to_id == self.status.id) {
  714. self.results.push(entity);
  715. let elem = $('.status-comments')[0];
  716. elem.scrollTop = elem.clientHeight;
  717. } else {
  718. if(self.replyToIndex >= 0) {
  719. let el = self.results[self.replyToIndex];
  720. el.replies.push(entity);
  721. el.reply_count = el.reply_count + 1;
  722. }
  723. }
  724. self.replyText = '';
  725. });
  726. },
  727. deleteComment(id, i) {
  728. axios.post('/i/delete', {
  729. type: 'comment',
  730. item: id
  731. }).then(res => {
  732. this.results.splice(i, 1);
  733. }).catch(err => {
  734. swal('Something went wrong!', 'Please try again later', 'error');
  735. });
  736. },
  737. deleteCommentReply(id, i, pi) {
  738. axios.post('/i/delete', {
  739. type: 'comment',
  740. item: id
  741. }).then(res => {
  742. this.results[pi].replies.splice(i, 1);
  743. --this.results[pi].reply_count;
  744. }).catch(err => {
  745. swal('Something went wrong!', 'Please try again later', 'error');
  746. });
  747. },
  748. l(e) {
  749. let len = e.length;
  750. if(len < 10) { return e; }
  751. return e.substr(0, 10)+'...';
  752. },
  753. replyFocus(e, index) {
  754. this.replyToIndex = index;
  755. this.replyingToId = e.id;
  756. this.reply_to_profile_id = e.account.id;
  757. this.replyText = '@' + e.account.username + ' ';
  758. $('textarea[name="comment"]').focus();
  759. },
  760. fetchComments() {
  761. let url = '/api/v2/comments/'+this.statusUsername+'/status/'+this.statusId;
  762. axios.get(url)
  763. .then(response => {
  764. let self = this;
  765. this.results = _.reverse(response.data.data);
  766. this.pagination = response.data.meta.pagination;
  767. if(this.results.length > 0) {
  768. $('.load-more-link').removeClass('d-none');
  769. }
  770. $('.postCommentsLoader').addClass('d-none');
  771. $('.postCommentsContainer').removeClass('d-none');
  772. }).catch(error => {
  773. if(!error.response) {
  774. $('.postCommentsLoader .lds-ring')
  775. .attr('style','width:100%')
  776. .addClass('pt-4 font-weight-bold text-muted')
  777. .text('An error occurred, cannot fetch comments. Please try again later.');
  778. } else {
  779. switch(error.response.status) {
  780. case 401:
  781. $('.postCommentsLoader .lds-ring')
  782. .attr('style','width:100%')
  783. .addClass('pt-4 font-weight-bold text-muted')
  784. .text('Please login to view.');
  785. break;
  786. default:
  787. $('.postCommentsLoader .lds-ring')
  788. .attr('style','width:100%')
  789. .addClass('pt-4 font-weight-bold text-muted')
  790. .text('An error occurred, cannot fetch comments. Please try again later.');
  791. break;
  792. }
  793. }
  794. });
  795. },
  796. loadMore(e) {
  797. e.preventDefault();
  798. if(this.pagination.total_pages == 1 || this.pagination.current_page == this.pagination.total_pages) {
  799. $('.load-more-link').addClass('d-none');
  800. return;
  801. }
  802. $('.postCommentsLoader').removeClass('d-none');
  803. let next = this.pagination.links.next;
  804. axios.get(next)
  805. .then(response => {
  806. let self = this;
  807. let res = response.data.data;
  808. $('.postCommentsLoader').addClass('d-none');
  809. for(let i=0; i < res.length; i++) {
  810. this.results.unshift(res[i]);
  811. }
  812. this.pagination = response.data.meta.pagination;
  813. });
  814. },
  815. likeReply(status, $event) {
  816. if($('body').hasClass('loggedIn') == false) {
  817. return;
  818. }
  819. axios.post('/i/like', {
  820. item: status.id
  821. }).then(res => {
  822. status.favourites_count = res.data.count;
  823. if(status.favourited == true) {
  824. status.favourited = false;
  825. } else {
  826. status.favourited = true;
  827. }
  828. }).catch(err => {
  829. swal('Error', 'Something went wrong, please try again later.', 'error');
  830. });
  831. },
  832. truncate(str,lim) {
  833. return _.truncate(str,{
  834. length: lim
  835. });
  836. },
  837. timeAgo(ts) {
  838. let date = Date.parse(ts);
  839. let seconds = Math.floor((new Date() - date) / 1000);
  840. let interval = Math.floor(seconds / 31536000);
  841. if (interval >= 1) {
  842. return interval + "y";
  843. }
  844. interval = Math.floor(seconds / 604800);
  845. if (interval >= 1) {
  846. return interval + "w";
  847. }
  848. interval = Math.floor(seconds / 86400);
  849. if (interval >= 1) {
  850. return interval + "d";
  851. }
  852. interval = Math.floor(seconds / 3600);
  853. if (interval >= 1) {
  854. return interval + "h";
  855. }
  856. interval = Math.floor(seconds / 60);
  857. if (interval >= 1) {
  858. return interval + "m";
  859. }
  860. return Math.floor(seconds) + "s";
  861. },
  862. emojiReaction() {
  863. let em = event.target.innerText;
  864. if(this.replyText.length == 0) {
  865. this.reply_to_profile_id = this.status.account.id;
  866. this.replyText = em + ' ';
  867. $('textarea[name="comment"]').focus();
  868. } else {
  869. this.reply_to_profile_id = this.status.account.id;
  870. this.replyText += em + ' ';
  871. $('textarea[name="comment"]').focus();
  872. }
  873. },
  874. toggleCommentVisibility() {
  875. if(this.ownerOrAdmin() == false) {
  876. return;
  877. }
  878. let state = this.status.comments_disabled;
  879. let self = this;
  880. if(state == true) {
  881. // re-enable comments
  882. axios.post('/i/visibility', {
  883. item: self.status.id,
  884. disableComments: false
  885. }).then(function(res) {
  886. window.location.href = self.status.url;
  887. }).catch(function(err) {
  888. return;
  889. });
  890. } else {
  891. // disable comments
  892. axios.post('/i/visibility', {
  893. item: self.status.id,
  894. disableComments: true
  895. }).then(function(res) {
  896. self.status.comments_disabled = false;
  897. self.showComments = false;
  898. }).catch(function(err) {
  899. return;
  900. });
  901. }
  902. },
  903. fetchRelationships() {
  904. if(document.querySelectorAll('body')[0].classList.contains('loggedIn') == false) {
  905. this.fetchData();
  906. return;
  907. } else {
  908. axios.get('/api/v1/accounts/relationships', {
  909. params: {
  910. 'id[]': this.statusProfileId
  911. }
  912. }).then(res => {
  913. if(res.data[0] == null) {
  914. this.fetchData();
  915. return;
  916. }
  917. this.relationship = res.data[0];
  918. if(res.data[0].blocking == true) {
  919. this.loaded = true;
  920. this.warning = true;
  921. return;
  922. } else {
  923. this.fetchData();
  924. return;
  925. }
  926. });
  927. }
  928. },
  929. visibilityModal() {
  930. switch(this.status.visibility) {
  931. case 'public':
  932. swal('Public Post', 'This post is visible to everyone.', 'info');
  933. break;
  934. case 'unlisted':
  935. swal('Unlisted Post', 'This post is visible on profiles and with a direct links. It is not displayed on timelines.', 'info');
  936. break;
  937. case 'private':
  938. swal('Private Post', 'This post is only visible to followers.', 'info');
  939. break;
  940. }
  941. },
  942. toggleReplies(reply) {
  943. if(reply.thread) {
  944. reply.thread = false;
  945. } else {
  946. if(reply.replies.length > 0) {
  947. reply.thread = true;
  948. return;
  949. }
  950. let url = '/api/v2/comments/'+reply.account.username+'/status/'+reply.id;
  951. axios.get(url)
  952. .then(response => {
  953. reply.replies = _.reverse(response.data.data);
  954. reply.thread = true;
  955. });
  956. }
  957. }
  958. },
  959. }
  960. </script>