PostComponent.vue 41 KB

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