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