1
0

PostComponent.vue 54 KB

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