RemotePost.vue 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523
  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 && currentLayout === 'status'" class="postComponent">
  13. <div class="container px-0">
  14. <div v-if="status.pf_type === 'text'" class="col-12 col-md-6 offset-md-3">
  15. <status-card
  16. class="border-top"
  17. :status="status"
  18. :recommended="false"
  19. v-on:comment-focus="commentFocus" />
  20. <comment-feed :status="status" class="mt-3" />
  21. </div>
  22. <div v-if="status.pf_type === 'poll'" class="col-12 col-md-6 offset-md-3">
  23. <poll-card :status="status" :profile="profile" :fetch-state="true"/>
  24. <comment-feed :status="status" class="mt-3" />
  25. </div>
  26. <div v-else class="card card-md-rounded-0 status-container orientation-unknown shadow-none border">
  27. <div class="row px-0 mx-0">
  28. <div class="d-flex d-md-none align-items-center justify-content-between card-header bg-white w-100">
  29. <div class="d-flex">
  30. <div class="status-avatar mr-2" @click="redirect(profileUrl)">
  31. <img :src="statusAvatar" width="24px" height="24px" style="border-radius:12px;" class="cursor-pointer" onerror="this.onerror=null;this.src='/storage/avatars/default.jpg?v=0';">
  32. </div>
  33. <div class="username">
  34. <span class="username-link font-weight-bold text-dark cursor-pointer" @click="redirect(profileUrl)">{{ statusUsername }}</span>
  35. <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;">
  36. <i class="fas fa-certificate text-danger fa-stack-1x"></i>
  37. <i class="fas fa-crown text-white fa-sm fa-stack-1x" style="font-size:7px;"></i>
  38. </span>
  39. <p class="mb-0" style="font-size: 10px;">
  40. <span v-if="loaded && status.taggedPeople.length" class="mb-0">
  41. <span class="font-weight-light cursor-pointer" style="color:#718096" title="Tagged People" data-toggle="tooltip" data-placement="bottom" @click="showTaggedPeopleModal()"><i class="fas fa-tag text-lighter"></i> <span class="font-weight-bold">{{status.taggedPeople.length}} Tagged People</span></span>
  42. </span>
  43. <span v-if="loaded && status.place != null && status.taggedPeople.length" class="px-2 font-weight-bold text-lighter">&#8226;</span>
  44. <span v-if="loaded && status.place != null" class="mb-0 cursor-pointer text-truncate" style="color:#718096" @click="redirect('/discover/places/' + status.place.id + '/' + status.place.slug)"><i class="fas fa-map-marked-alt text-lighter"></i> <span class="font-weight-bold">{{status.place.name}}, {{status.place.country}}</span></span>
  45. </p>
  46. </div>
  47. </div>
  48. <div v-if="user != false" class="float-right">
  49. <div class="post-actions">
  50. <div>
  51. <button class="btn btn-link text-dark no-caret" title="Post options" @click="ctxMenu()">
  52. <span class="fas fa-ellipsis-v text-muted"></span>
  53. </button>
  54. </div>
  55. </div>
  56. </div>
  57. </div>
  58. <div class="col-12 col-md-8 px-0 mx-0">
  59. <div class="postPresenterContainer d-none d-flex justify-content-center align-items-center" style="background: #000;">
  60. <div v-if="status.pf_type === 'photo'" class="w-100">
  61. <photo-presenter :status="status" v-on:togglecw="status.sensitive = false"></photo-presenter>
  62. </div>
  63. <div v-else-if="status.pf_type === 'video'" class="w-100">
  64. <video-presenter :status="status" v-on:togglecw="status.sensitive = false"></video-presenter>
  65. </div>
  66. <div v-else-if="status.pf_type === 'photo:album'" class="w-100">
  67. <photo-album-presenter :status="status" v-on:togglecw="status.sensitive = false"></photo-album-presenter>
  68. </div>
  69. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  70. <video-album-presenter :status="status" v-on:togglecw="status.sensitive = false"></video-album-presenter>
  71. </div>
  72. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  73. <mixed-album-presenter :status="status" v-on:togglecw="status.sensitive = false"></mixed-album-presenter>
  74. </div>
  75. <div v-else class="w-100">
  76. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  77. </div>
  78. </div>
  79. </div>
  80. <div class="col-12 col-md-4 px-0 d-flex flex-column border-left border-md-left-0">
  81. <div class="d-md-flex d-none align-items-center justify-content-between card-header py-3 bg-white">
  82. <div class="d-flex align-items-center status-username text-truncate">
  83. <div class="status-avatar mr-2" @click="redirect(profileUrl)">
  84. <img :src="statusAvatar" width="24px" height="24px" style="border-radius:12px;" class="cursor-pointer" onerror="this.onerror=null;this.src='/storage/avatars/default.jpg?v=0';">
  85. </div>
  86. <div class="username">
  87. <span class="username-link font-weight-bold text-dark cursor-pointer" @click="redirect(profileUrl)">{{ statusUsername }}</span>
  88. <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;">
  89. <i class="fas fa-certificate text-danger fa-stack-1x"></i>
  90. <i class="fas fa-crown text-white fa-sm fa-stack-1x" style="font-size:7px;"></i>
  91. </span>
  92. <p class="mb-0" style="font-size: 10px;">
  93. <span v-if="loaded && status.taggedPeople.length" class="mb-0">
  94. <span class="font-weight-light cursor-pointer" style="color:#718096" title="Tagged People" data-toggle="tooltip" data-placement="bottom" @click="showTaggedPeopleModal()"><i class="fas fa-tag text-lighter"></i> <span class="font-weight-bold">{{status.taggedPeople.length}} Tagged People</span></span>
  95. </span>
  96. <span v-if="loaded && status.place != null && status.taggedPeople.length" class="px-2 font-weight-bold text-lighter">&#8226;</span>
  97. <span v-if="loaded && status.place != null" class="mb-0 cursor-pointer text-truncate" style="color:#718096" @click="redirect('/discover/places/' + status.place.id + '/' + status.place.slug)"><i class="fas fa-map-marked-alt text-lighter"></i> <span class="font-weight-bold">{{status.place.name}}, {{status.place.country}}</span></span>
  98. </p>
  99. </div>
  100. </div>
  101. <div class="float-right">
  102. <div class="post-actions">
  103. <div v-if="user != false">
  104. <button class="btn btn-link text-dark no-caret" title="Post options" @click="ctxMenu()">
  105. <span class="fas fa-ellipsis-v text-muted"></span>
  106. </button>
  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 pt-0">
  113. <div class="status-comment">
  114. <div v-if="status.content.length" class="pt-3">
  115. <div v-if="status.sensitive">
  116. <span class="py-3">
  117. <a class="text-dark font-weight-bold mr-1" :href="profileUrl" v-bind:title="status.account.username">{{truncate(status.account.username,15)}}</a>
  118. <span class="text-break">
  119. <span class="font-italic text-muted">This comment may contain sensitive material</span>
  120. <span class="text-primary cursor-pointer pl-1" @click="status.sensitive = false">Show</span>
  121. </span>
  122. </span>
  123. </div>
  124. <div v-else>
  125. <p :class="[status.content.length > 620 ? 'mb-1 read-more' : 'mb-1']" style="overflow: hidden;">
  126. <a class="font-weight-bold pr-1 text-dark text-decoration-none" :href="profileUrl">{{statusUsername}}</a>
  127. <span class="comment-text" :id="status.id + '-status-readmore'" v-html="status.content"></span>
  128. </p>
  129. </div>
  130. <hr>
  131. </div>
  132. <div v-if="showComments">
  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-4">
  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 mt-3">
  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" onerror="this.onerror=null;this.src='/storage/avatars/default.jpg?v=0';">
  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 comment-body" style="word-break: break-all;" 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, true)">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" onerror="this.onerror=null;this.src='/storage/avatars/default.jpg?v=0';">
  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 comment-body" style="word-break: break-all;" 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 v-if="reactionBarLoading" class="card-body flex-grow-0 py-4 text-center">
  207. <div class="spinner-border" role="status">
  208. <span class="sr-only">Loading...</span>
  209. </div>
  210. </div>
  211. <div v-else class="card-body flex-grow-0 py-1">
  212. <div v-if="loaded && user.hasOwnProperty('id')" class="reactions my-2 pb-1 d-flex justify-content-between">
  213. <h3 v-bind:class="[reactions.liked ? 'fas fa-heart text-danger mr-3 m-0 cursor-pointer' : 'far fa-heart pr-3 m-0 like-btn cursor-pointer']" title="Like" v-on:click="likeStatus"></h3>
  214. <h3 v-if="!status.comments_disabled" class="far fa-comment mr-3 m-0 cursor-pointer" title="Comment" v-on:click="replyFocus(status)"></h3>
  215. <h3 @click="redirect(status.media_attachments[0].url)" class="fas fa-expand m-0 mr-3 cursor-pointer"></h3>
  216. <!-- <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> -->
  217. <h3 v-if="status.visibility == 'public'" v-bind:class="[reactions.bookmarked ? 'fas fa-bookmark text-warning m-0 mr-3 cursor-pointer' : 'far fa-bookmark m-0 mr-3 cursor-pointer']" title="Bookmark" v-on:click="bookmarkStatus"></h3>
  218. <h3 v-if="status.visibility == 'public'" v-bind:class="[reactions.shared ? 'fas fa-retweet m-0 text-primary cursor-pointer' : 'fas fa-retweet m-0 share-btn cursor-pointer']" title="Share" v-on:click="shareStatus"></h3>
  219. </div>
  220. <div class="reaction-counts mb-0">
  221. <div v-if="status.liked_by.username && status.liked_by.username !== user.username" class="likes mb-1">
  222. <span class="like-count">Liked by
  223. <a class="font-weight-bold text-dark" :href="status.liked_by.url">{{status.liked_by.username}}</a>
  224. <span v-if="status.liked_by.others == true">
  225. and <span class="font-weight-bold text-dark cursor-pointer" @click="likesModal"><span v-if="status.liked_by.total_count_pretty">{{status.liked_by.total_count_pretty}}</span> others</span>
  226. </span>
  227. </span>
  228. </div>
  229. </div>
  230. <div class="timestamp pt-2 d-flex align-items-bottom justify-content-between">
  231. <a v-bind:href="statusUrl" class="small text-muted" :title="status.created_at">
  232. {{timestampFormat()}}
  233. </a>
  234. <span class="small text-muted text-capitalize cursor-pointer" v-on:click="visibilityModal">{{status.visibility}}</span>
  235. </div>
  236. </div>
  237. </div>
  238. <div v-if="showComments" class="card-footer bg-white sticky-md-bottom p-0">
  239. <div v-if="user.length == 0" class="comment-form-guest p-3">
  240. <a href="/login">Login</a> to like or comment.
  241. </div>
  242. <form v-else class="border-0 rounded-0 align-middle" method="post" action="/i/comment" :data-id="statusId" data-truncate="false">
  243. <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;" @click="replyFocus(status)"></textarea>
  244. <input type="button" value="Post" class="d-inline-block btn btn-link font-weight-bold reply-btn text-decoration-none" disabled/>
  245. </form>
  246. </div>
  247. </div>
  248. </div>
  249. </div>
  250. <div class="container" v-if="showProfileMorePosts">
  251. <p class="text-lighter px-3 mt-5" style="font-weight: 600;font-size: 15px;">More posts from <a :href="profileUrl" class="text-dark">{{this.statusUsername}}</a></p>
  252. <div class="profile-timeline mt-md-4">
  253. <div class="row">
  254. <div class="col-4 p-1 p-md-3" v-for="(s, index) in profileMorePosts" :key="'tlob:'+index">
  255. <a class="card info-overlay card-md-border-0" :href="getStatusUrl(s)" v-once>
  256. <div :class="[s.sensitive ? 'square' : 'square ' + s.media_attachments[0].filter_class]">
  257. <span v-if="s.pf_type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  258. <span v-if="s.pf_type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  259. <span v-if="s.pf_type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  260. <div class="square-content" v-bind:style="previewBackground(s)">
  261. </div>
  262. <div class="info-overlay-text">
  263. <h5 class="text-white m-auto font-weight-bold">
  264. <span>
  265. <span class="far fa-heart fa-lg p-2 d-flex-inline"></span>
  266. <span class="d-flex-inline">{{s.favourites_count}}</span>
  267. </span>
  268. <span>
  269. <span class="fas fa-retweet fa-lg p-2 d-flex-inline"></span>
  270. <span class="d-flex-inline">{{s.reblogs_count}}</span>
  271. </span>
  272. </h5>
  273. </div>
  274. </div>
  275. </a>
  276. </div>
  277. </div>
  278. </div>
  279. </div>
  280. </div>
  281. </div>
  282. <comment-card
  283. v-if="currentLayout === 'comments'"
  284. :status="status"
  285. :profile="profile"
  286. v-on:current-layout="setCurrentLayout"
  287. :backToStatus="true"
  288. />
  289. <b-modal ref="likesModal"
  290. id="l-modal"
  291. hide-footer
  292. centered
  293. title="Likes"
  294. body-class="list-group-flush py-3 px-0">
  295. <div class="list-group">
  296. <div class="list-group-item border-0 py-1" v-for="(user, index) in likes" :key="'modal_likes_'+index">
  297. <div class="media">
  298. <a :href="user.url">
  299. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px" onerror="this.onerror=null;this.src='/storage/avatars/default.jpg?v=0';">
  300. </a>
  301. <div class="media-body">
  302. <p class="mb-0" style="font-size: 14px">
  303. <a :href="user.url" class="font-weight-bold text-dark">
  304. {{user.username}}
  305. </a>
  306. </p>
  307. <p 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">
  308. <span class="font-weight-bold">{{user.acct.split('@')[0]}}</span><span class="text-lighter">&commat;{{user.acct.split('@')[1]}}</span>
  309. </p>
  310. <p v-else class="text-muted mb-0 text-truncate" style="font-size: 14px">
  311. {{user.display_name}}
  312. </p>
  313. </div>
  314. </div>
  315. </div>
  316. <infinite-loading @infinite="infiniteLikesHandler" spinner="spiral">
  317. <div slot="no-more"></div>
  318. <div slot="no-results"></div>
  319. </infinite-loading>
  320. </div>
  321. </b-modal>
  322. <b-modal ref="sharesModal"
  323. id="s-modal"
  324. hide-footer
  325. centered
  326. title="Shares"
  327. body-class="list-group-flush py-3 px-0">
  328. <div class="list-group">
  329. <div class="list-group-item border-0 py-1" v-for="(user, index) in shares" :key="'modal_shares_'+index">
  330. <div class="media">
  331. <a :href="user.url">
  332. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px" onerror="this.onerror=null;this.src='/storage/avatars/default.jpg?v=0';">
  333. </a>
  334. <div class="media-body">
  335. <div class="d-inline-block">
  336. <p class="mb-0" style="font-size: 14px">
  337. <a :href="user.url" class="font-weight-bold text-dark">
  338. {{user.username}}
  339. </a>
  340. </p>
  341. <p class="text-muted mb-0" style="font-size: 14px">
  342. {{user.display_name}}
  343. </a>
  344. </p>
  345. </div>
  346. <p class="float-right"><!-- <a class="btn btn-primary font-weight-bold py-1" href="#">Follow</a> --></p>
  347. </div>
  348. </div>
  349. </div>
  350. <infinite-loading @infinite="infiniteSharesHandler" spinner="spiral">
  351. <div slot="no-more"></div>
  352. <div slot="no-results"></div>
  353. </infinite-loading>
  354. </div>
  355. </b-modal>
  356. <b-modal ref="taggedModal"
  357. id="tagged-modal"
  358. hide-footer
  359. centered
  360. title="Tagged People"
  361. body-class="list-group-flush py-3 px-0">
  362. <div class="list-group">
  363. <div class="list-group-item border-0 py-1" v-for="(taguser, index) in status.taggedPeople" :key="'modal_taggedpeople_'+index">
  364. <div class="media">
  365. <a :href="'/'+taguser.username">
  366. <img class="mr-3 rounded-circle box-shadow" :src="taguser.avatar" :alt="taguser.username + '’s avatar'" width="30px" onerror="this.onerror=null;this.src='/storage/avatars/default.jpg?v=0';">
  367. </a>
  368. <div class="media-body">
  369. <p class="pt-1 d-flex justify-content-between" style="font-size: 14px">
  370. <a :href="'/'+taguser.username" class="font-weight-bold text-dark">
  371. {{taguser.username}}
  372. </a>
  373. <button v-if="taguser.id == user.id" class="btn btn-outline-primary btn-sm py-1 px-3" @click="untagMe()">Untag Me</button>
  374. </p>
  375. </div>
  376. </div>
  377. </div>
  378. </div>
  379. <p class="mb-0 text-center small text-muted font-weight-bold"><a href="/site/kb/tagging-people">Learn more</a> about Tagging People.</p>
  380. </b-modal>
  381. <b-modal ref="ctxModal"
  382. id="ctx-modal"
  383. hide-header
  384. hide-footer
  385. centered
  386. rounded
  387. size="sm"
  388. body-class="list-group-flush p-0 rounded">
  389. <div class="list-group text-center">
  390. <div v-if="user && user.id != status.account.id && relationship && relationship.following" class="list-group-item rounded cursor-pointer font-weight-bold text-danger" @click="ctxMenuUnfollow()">Unfollow</div>
  391. <div v-if="user && user.id != status.account.id && relationship && !relationship.following" class="list-group-item rounded cursor-pointer font-weight-bold text-primary" @click="ctxMenuFollow()">Follow</div>
  392. <div class="list-group-item rounded cursor-pointer" @click="ctxMenuCopyLink()">Copy Link</div>
  393. <div v-if="status && user.id == status.account.id" class="list-group-item rounded cursor-pointer" @click="toggleCommentVisibility">{{ showComments ? 'Disable' : 'Enable'}} Comments</div>
  394. <a v-if="status && user.id == status.account.id" class="list-group-item rounded cursor-pointer text-dark text-decoration-none" :href="editUrl()">Edit</a>
  395. <div v-if="user && user.is_admin == true" class="list-group-item rounded cursor-pointer" @click="ctxModMenu()">ModTools</div>
  396. <div v-if="status && user.id != status.account.id && !relationship.blocking && !user.is_admin" class="list-group-item rounded cursor-pointer font-weight-bold text-danger" @click="blockProfile()">Block</div>
  397. <div v-if="status && user.id != status.account.id && relationship.blocking && !user.is_admin" class="list-group-item rounded cursor-pointer font-weight-bold text-danger" @click="unblockProfile()">Unblock</div>
  398. <a v-if="user && user.id != status.account.id && !user.is_admin" class="list-group-item rounded cursor-pointer font-weight-bold text-danger text-decoration-none" :href="reportUrl()">Report</a>
  399. <div v-if="status && (user.is_admin || user.id == status.account.id)" class="list-group-item rounded cursor-pointer font-weight-bold text-danger" @click="deletePost(ctxMenuStatus)">Delete</div>
  400. <div class="list-group-item rounded cursor-pointer text-lighter" @click="closeCtxMenu()">Cancel</div>
  401. </div>
  402. </b-modal>
  403. <b-modal ref="ctxModModal"
  404. id="ctx-mod-modal"
  405. hide-header
  406. hide-footer
  407. centered
  408. rounded
  409. size="sm"
  410. body-class="list-group-flush p-0 rounded">
  411. <div class="list-group text-center">
  412. <div class="list-group-item rounded cursor-pointer" @click="toggleCommentVisibility">{{ showComments ? 'Disable' : 'Enable'}} Comments</div>
  413. <div class="list-group-item rounded cursor-pointer" @click="moderatePost('unlist')">Unlist from Timelines</div>
  414. <div v-if="status.sensitive" class="list-group-item rounded cursor-pointer" @click="moderatePost('remcw')">Remove Content Warning</div>
  415. <div v-else class="list-group-item rounded cursor-pointer" @click="moderatePost('addcw')">Add Content Warning</div>
  416. <div class="list-group-item rounded cursor-pointer text-lighter" @click="ctxModMenuClose()">Cancel</div>
  417. </div>
  418. </b-modal>
  419. <b-modal ref="replyModal"
  420. id="ctx-reply-modal"
  421. hide-footer
  422. centered
  423. rounded
  424. :title-html="replyingToUsername ? 'Reply to <span class=text-dark>' + replyingToUsername + '</span>' : ''"
  425. title-tag="p"
  426. title-class="font-weight-bold text-muted"
  427. size="md"
  428. body-class="p-2 rounded">
  429. <div>
  430. <textarea class="form-control" rows="4" style="border: none; font-size: 18px; resize: none; white-space: pre-wrap;outline: none;" placeholder="Reply here ..." v-model="replyText">
  431. </textarea>
  432. <div class="border-top border-bottom my-2">
  433. <ul class="nav align-items-center emoji-reactions" style="overflow-x: scroll;flex-wrap: unset;">
  434. <li class="nav-item" v-on:click="emojiReaction(status)" v-for="e in emoji">{{e}}</li>
  435. </ul>
  436. </div>
  437. <div class="d-flex justify-content-between align-items-center">
  438. <div>
  439. <span class="pl-2 small text-muted font-weight-bold text-monospace">
  440. <span :class="[replyText.length > config.uploader.max_caption_length ? 'text-danger':'text-dark']">{{replyText.length > config.uploader.max_caption_length ? config.uploader.max_caption_length - replyText.length : replyText.length}}</span>/{{config.uploader.max_caption_length}}
  441. </span>
  442. </div>
  443. <div class="d-flex align-items-center">
  444. <div class="custom-control custom-switch mr-3">
  445. <input type="checkbox" class="custom-control-input" id="replyModalCWSwitch" v-model="replySensitive">
  446. <label :class="[replySensitive ? 'custom-control-label font-weight-bold text-dark':'custom-control-label text-lighter']" for="replyModalCWSwitch">Mark as NSFW</label>
  447. </div>
  448. <!-- <select class="custom-select custom-select-sm my-0 mr-2">
  449. <option value="public" selected="">Public</option>
  450. <option value="unlisted">Unlisted</option>
  451. <option value="followers">Followers Only</option>
  452. </select> -->
  453. <button class="btn btn-primary btn-sm py-2 px-4 lead text-uppercase font-weight-bold" v-on:click.prevent="postReply()" :disabled="replyText.length == 0">
  454. {{replySending == true ? 'POSTING' : 'POST'}}
  455. </button>
  456. </div>
  457. </div>
  458. </div>
  459. </b-modal>
  460. </div>
  461. </template>
  462. <style type="text/css" scoped>
  463. .status-comments,
  464. .reactions {
  465. background: #fff;
  466. }
  467. .postPresenterContainer {
  468. background: #fff;
  469. }
  470. @media(min-width: 720px) {
  471. .postPresenterContainer {
  472. min-height: 600px;
  473. }
  474. }
  475. ::-webkit-scrollbar {
  476. width: 0px;
  477. background: transparent;
  478. }
  479. .reply-btn {
  480. position: absolute;
  481. bottom: 12px;
  482. right: 20px;
  483. width: 60px;
  484. text-align: center;
  485. border-radius: 0 3px 3px 0;
  486. }
  487. .text-lighter {
  488. color:#B8C2CC !important;
  489. }
  490. .text-break {
  491. overflow-wrap: break-word;
  492. }
  493. .comments p {
  494. margin-bottom: 0;
  495. }
  496. .comment-reaction {
  497. font-size: 80%;
  498. }
  499. .show-reply-bar {
  500. display: inline-block;
  501. border-bottom: 1px solid #999;
  502. height: 0;
  503. margin-right: 16px;
  504. vertical-align: middle;
  505. width: 24px;
  506. }
  507. .comment-thread {
  508. margin-top: 1rem;
  509. }
  510. .emoji-reactions .nav-item {
  511. font-size: 1.2rem;
  512. padding: 9px;
  513. cursor: pointer;
  514. }
  515. .emoji-reactions::-webkit-scrollbar {
  516. width: 0px;
  517. height: 0px;
  518. background: transparent;
  519. }
  520. @media (min-width: 1200px) {
  521. .container {
  522. max-width: 1100px;
  523. }
  524. }
  525. </style>
  526. <script>
  527. pixelfed.postComponent = {};
  528. import StatusCard from './partials/StatusCard.vue';
  529. import CommentCard from './partials/CommentCard.vue';
  530. import PollCard from './partials/PollCard.vue';
  531. import CommentFeed from './partials/CommentFeed.vue';
  532. export default {
  533. props: [
  534. 'status-id',
  535. 'status-username',
  536. 'status-template',
  537. 'status-url',
  538. 'status-profile-url',
  539. 'status-avatar',
  540. 'status-profile-id',
  541. 'profile-layout'
  542. ],
  543. components: {
  544. StatusCard,
  545. CommentCard,
  546. CommentFeed,
  547. PollCard
  548. },
  549. data() {
  550. return {
  551. config: window.App.config,
  552. status: false,
  553. media: {},
  554. user: false,
  555. profile: false,
  556. reactions: {
  557. liked: false,
  558. shared: false
  559. },
  560. likes: [],
  561. likesPage: 1,
  562. shares: [],
  563. sharesPage: 1,
  564. replyText: '',
  565. replyStatus: {},
  566. replySensitive: false,
  567. relationship: {},
  568. results: [],
  569. pagination: {},
  570. min_id: 0,
  571. max_id: 0,
  572. reply_to_profile_id: 0,
  573. thread: false,
  574. showComments: false,
  575. warning: false,
  576. loaded: false,
  577. loading: null,
  578. replyingToId: this.statusId,
  579. replyingToUsername: this.statusUsername,
  580. replyToIndex: 0,
  581. replySending: false,
  582. emoji: window.App.util.emoji,
  583. showReadMore: true,
  584. showCaption: true,
  585. layout: this.profileLayout,
  586. showProfileMorePosts: false,
  587. profileMorePosts: [],
  588. reactionBarLoading: true,
  589. profileUrl: null,
  590. currentLayout: 'status'
  591. }
  592. },
  593. mounted() {
  594. axios.get('/api/pixelfed/v1/accounts/verify_credentials').then(res => {
  595. this.profile = res.data;
  596. });
  597. this.fetchRelationships();
  598. if(localStorage.getItem('pf_metro_ui.exp.rm') == 'false') {
  599. this.showReadMore = false;
  600. } else {
  601. this.showReadMore = true;
  602. }
  603. },
  604. updated() {
  605. $('.carousel').carousel();
  606. $('[data-toggle="tooltip"]').tooltip();
  607. if(this.showReadMore == true) {
  608. window.pixelfed.readmore();
  609. }
  610. document.querySelectorAll('.hashtag').forEach(function(i, e) {
  611. i.href = App.util.format.rewriteLinks(i);
  612. });
  613. },
  614. methods: {
  615. reportUrl() {
  616. return '/i/report?type=post&id=' + this.status.id;
  617. },
  618. editUrl() {
  619. return this.status.url + '/edit';
  620. },
  621. timestampFormat() {
  622. let ts = new Date(this.status.created_at);
  623. return ts.toDateString() + ' · ' + ts.toLocaleTimeString();
  624. },
  625. fetchData() {
  626. let self = this;
  627. axios.get('/api/v2/profile/'+this.statusUsername+'/status/'+this.statusId)
  628. .then(response => {
  629. self.status = response.data.status;
  630. self.media = self.status.media_attachments;
  631. self.likesPage = 2;
  632. self.sharesPage = 2;
  633. self.showCaption = !response.data.status.sensitive;
  634. if(self.status.comments_disabled == false) {
  635. self.showComments = true;
  636. this.fetchComments();
  637. }
  638. self.profileUrl = '/i/web/profile/_/' + response.data.status.account.id;
  639. this.loaded = true;
  640. // setTimeout(function() {
  641. // self.fetchProfilePosts();
  642. // }, 3000);
  643. setTimeout(function() {
  644. self.fetchState();
  645. document.querySelectorAll('.status-comment .postCommentsContainer .comment-body a').forEach(function(i, e) {
  646. i.href = App.util.format.rewriteLinks(i);
  647. });
  648. }, 500);
  649. }).catch(error => {
  650. swal('Oops!', 'An error occured, please try refreshing the page.', 'error');
  651. });
  652. },
  653. fetchState() {
  654. let self = this;
  655. axios.get('/api/v2/profile/'+this.statusUsername+'/status/'+this.statusId+'/state')
  656. .then(res => {
  657. self.user = res.data.user;
  658. window._sharedData.curUser = self.user;
  659. window.App.util.navatar();
  660. self.likes = res.data.likes;
  661. self.shares = res.data.shares;
  662. self.reactions = res.data.reactions;
  663. self.reactionBarLoading = false;
  664. });
  665. },
  666. likesModal() {
  667. if($('body').hasClass('loggedIn') == false) {
  668. window.location.href = '/login?next=' + encodeURIComponent('/p/' + this.status.shortcode);
  669. return;
  670. }
  671. if(this.likes.length) {
  672. this.$refs.likesModal.show();
  673. return;
  674. }
  675. axios.get('/api/v2/likes/profile/'+this.statusUsername+'/status/'+this.statusId)
  676. .then(res => {
  677. this.likes = res.data.data;
  678. this.$refs.likesModal.show();
  679. });
  680. },
  681. sharesModal() {
  682. if(this.status.reblogs_count == 0 || $('body').hasClass('loggedIn') == false) {
  683. window.location.href = '/login?next=' + encodeURIComponent('/p/' + this.status.shortcode);
  684. return;
  685. }
  686. if(this.shares.length) {
  687. this.$refs.sharesModal.show();
  688. return;
  689. }
  690. axios.get('/api/v2/shares/profile/'+this.statusUsername+'/status/'+this.statusId)
  691. .then(res => {
  692. this.shares = res.data.data;
  693. this.$refs.sharesModal.show();
  694. });
  695. },
  696. infiniteLikesHandler($state) {
  697. let api = '/api/v2/likes/profile/'+this.statusUsername+'/status/'+this.statusId;
  698. axios.get(api, {
  699. params: {
  700. page: this.likesPage,
  701. },
  702. }).then(({ data }) => {
  703. if (data.data.length > 0) {
  704. this.likes.push(...data.data);
  705. this.likesPage++;
  706. $state.loaded();
  707. } else {
  708. $state.complete();
  709. }
  710. });
  711. },
  712. infiniteSharesHandler($state) {
  713. axios.get('/api/v2/shares/profile/'+this.statusUsername+'/status/'+this.statusId, {
  714. params: {
  715. page: this.sharesPage,
  716. },
  717. }).then(({ data }) => {
  718. if (data.data.length > 0) {
  719. this.shares.push(...data.data);
  720. this.sharesPage++;
  721. $state.loaded();
  722. } else {
  723. $state.complete();
  724. }
  725. });
  726. },
  727. likeStatus(event) {
  728. if($('body').hasClass('loggedIn') == false) {
  729. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  730. return;
  731. }
  732. axios.post('/i/like', {
  733. item: this.status.id
  734. }).then(res => {
  735. this.status.favourites_count = res.data.count;
  736. if(this.reactions.liked == true) {
  737. this.reactions.liked = false;
  738. let user = this.user.id;
  739. this.likes = this.likes.filter(function(like) {
  740. return like.id !== user;
  741. });
  742. } else {
  743. this.reactions.liked = true;
  744. let user = this.user;
  745. this.likes.unshift(user);
  746. setTimeout(function() {
  747. event.target.classList.add('animate__animated', 'animate__bounce');
  748. },100);
  749. }
  750. }).catch(err => {
  751. console.error(err);
  752. swal('Error', 'Something went wrong, please try again later.', 'error');
  753. });
  754. window.navigator.vibrate(200);
  755. },
  756. shareStatus() {
  757. if($('body').hasClass('loggedIn') == false) {
  758. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  759. return;
  760. }
  761. axios.post('/i/share', {
  762. item: this.status.id
  763. }).then(res => {
  764. this.status.reblogs_count = res.data.count;
  765. if(this.reactions.shared == true) {
  766. this.reactions.shared = false;
  767. let user = this.user.id;
  768. this.shares = this.shares.filter(function(reaction) {
  769. return reaction.id !== user;
  770. });
  771. } else {
  772. this.reactions.shared = true;
  773. let user = this.user;
  774. this.shares.push(user);
  775. }
  776. }).catch(err => {
  777. console.error(err);
  778. swal('Error', 'Something went wrong, please try again later.', 'error');
  779. });
  780. },
  781. bookmarkStatus() {
  782. if($('body').hasClass('loggedIn') == false) {
  783. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  784. return;
  785. }
  786. axios.post('/i/bookmark', {
  787. item: this.status.id
  788. }).then(res => {
  789. if(this.reactions.bookmarked == true) {
  790. this.reactions.bookmarked = false;
  791. } else {
  792. this.reactions.bookmarked = true;
  793. }
  794. }).catch(err => {
  795. swal('Error', 'Something went wrong, please try again later.', 'error');
  796. });
  797. },
  798. blockProfile() {
  799. if($('body').hasClass('loggedIn') == false) {
  800. return;
  801. }
  802. axios.post('/i/block', {
  803. type: 'user',
  804. item: this.status.account.id
  805. }).then(res => {
  806. this.$refs.ctxModal.hide();
  807. this.relationship.blocking = true;
  808. swal('Success', 'You have successfully blocked ' + this.status.account.acct, 'success');
  809. }).catch(err => {
  810. swal('Error', 'Something went wrong. Please try again later.', 'error');
  811. });
  812. },
  813. unblockProfile() {
  814. if($('body').hasClass('loggedIn') == false) {
  815. return;
  816. }
  817. axios.post('/i/unblock', {
  818. type: 'user',
  819. item: this.status.account.id
  820. }).then(res => {
  821. this.relationship.blocking = false;
  822. this.$refs.ctxModal.hide();
  823. swal('Success', 'You have successfully unblocked ' + this.status.account.acct, 'success');
  824. }).catch(err => {
  825. swal('Error', 'Something went wrong. Please try again later.', 'error');
  826. });
  827. },
  828. deletePost(status) {
  829. if(!this.ownerOrAdmin()) {
  830. return;
  831. }
  832. var result = confirm('Are you sure you want to delete this post?');
  833. if (result) {
  834. if($('body').hasClass('loggedIn') == false) {
  835. return;
  836. }
  837. axios.post('/i/delete', {
  838. type: 'status',
  839. item: this.status.id
  840. }).then(res => {
  841. swal('Success', 'You have successfully deleted this post', 'success');
  842. setTimeout(function() {
  843. window.location.href = '/';
  844. }, 3000);
  845. }).catch(err => {
  846. swal('Error', 'Something went wrong. Please try again later.', 'error');
  847. });
  848. }
  849. },
  850. owner() {
  851. return this.user.id === this.status.account.id;
  852. },
  853. admin() {
  854. return this.user.is_admin == true;
  855. },
  856. ownerOrAdmin() {
  857. return this.owner() || this.admin();
  858. },
  859. postReply() {
  860. let self = this;
  861. this.replySending = true;
  862. if(this.replyText.length == 0 ||
  863. this.replyText.trim() == '@'+this.status.account.acct) {
  864. self.replyText = null;
  865. $('textarea[name="comment"]').blur();
  866. return;
  867. }
  868. let data = {
  869. item: this.replyingToId,
  870. comment: this.replyText,
  871. sensitive: this.replySensitive
  872. }
  873. this.replyText = '';
  874. axios.post('/i/comment', data)
  875. .then(function(res) {
  876. let entity = res.data.entity;
  877. if(entity.in_reply_to_id == self.status.id) {
  878. if(self.layout == 'metro') {
  879. self.results.push(entity);
  880. } else {
  881. self.results.unshift(entity);
  882. }
  883. let elem = $('.status-comments')[0];
  884. elem.scrollTop = elem.clientHeight * 2;
  885. } else {
  886. if(self.replyToIndex >= 0) {
  887. let el = self.results[self.replyToIndex];
  888. el.replies.push(entity);
  889. el.reply_count = el.reply_count + 1;
  890. }
  891. }
  892. self.$refs.replyModal.hide();
  893. self.replySending = false;
  894. });
  895. },
  896. deleteComment(id, i) {
  897. axios.post('/i/delete', {
  898. type: 'comment',
  899. item: id
  900. }).then(res => {
  901. this.results.splice(i, 1);
  902. }).catch(err => {
  903. swal('Something went wrong!', 'Please try again later', 'error');
  904. });
  905. },
  906. deleteCommentReply(id, i, pi) {
  907. axios.post('/i/delete', {
  908. type: 'comment',
  909. item: id
  910. }).then(res => {
  911. this.results[pi].replies.splice(i, 1);
  912. --this.results[pi].reply_count;
  913. }).catch(err => {
  914. swal('Something went wrong!', 'Please try again later', 'error');
  915. });
  916. },
  917. l(e) {
  918. let len = e.length;
  919. if(len < 10) { return e; }
  920. return e.substr(0, 10)+'...';
  921. },
  922. replyFocus(e, index, prependUsername = false) {
  923. if($('body').hasClass('loggedIn') == false) {
  924. this.redirect('/login?next=' + encodeURIComponent(window.location.pathname));
  925. return;
  926. }
  927. if(this.status.comments_disabled) {
  928. return;
  929. }
  930. this.replyToIndex = index;
  931. this.replyingToId = e.id;
  932. this.replyingToUsername = e.account.username;
  933. this.reply_to_profile_id = e.account.id;
  934. let username = e.account.local ? '@' + e.account.username + ' '
  935. : '@' + e.account.acct + ' ';
  936. if(prependUsername == true) {
  937. this.replyText = username;
  938. }
  939. this.$refs.replyModal.show();
  940. },
  941. fetchComments() {
  942. let url = '/api/v2/comments/'+this.statusProfileId+'/status/'+this.statusId;
  943. axios.get(url)
  944. .then(response => {
  945. let self = this;
  946. this.results = this.layout == 'metro' ?
  947. _.reverse(response.data.data) :
  948. response.data.data;
  949. this.pagination = response.data.meta.pagination;
  950. if(this.results.length > 0) {
  951. $('.load-more-link').removeClass('d-none');
  952. }
  953. $('.postCommentsLoader').addClass('d-none');
  954. $('.postCommentsContainer').removeClass('d-none');
  955. setTimeout(function() {
  956. document.querySelectorAll('.status-comment .postCommentsContainer .comment-body a').forEach(function(i, e) {
  957. i.href = App.util.format.rewriteLinks(i);
  958. });
  959. }, 500);
  960. }).catch(error => {
  961. if(!error.response) {
  962. $('.postCommentsLoader .lds-ring')
  963. .attr('style','width:100%')
  964. .addClass('pt-4 font-weight-bold text-muted')
  965. .text('An error occurred, cannot fetch comments. Please try again later.');
  966. } else {
  967. switch(error.response.status) {
  968. case 401:
  969. $('.postCommentsLoader .lds-ring')
  970. .attr('style','width:100%')
  971. .addClass('pt-4 font-weight-bold text-muted')
  972. .text('Please login to view.');
  973. break;
  974. default:
  975. $('.postCommentsLoader .lds-ring')
  976. .attr('style','width:100%')
  977. .addClass('pt-4 font-weight-bold text-muted')
  978. .text('An error occurred, cannot fetch comments. Please try again later.');
  979. break;
  980. }
  981. }
  982. });
  983. },
  984. loadMore(e) {
  985. e.preventDefault();
  986. if(this.pagination.total_pages == 1 || this.pagination.current_page == this.pagination.total_pages) {
  987. $('.load-more-link').addClass('d-none');
  988. return;
  989. }
  990. $('.load-more-link').addClass('d-none');
  991. $('.postCommentsLoader').removeClass('d-none');
  992. let next = this.pagination.links.next;
  993. axios.get(next)
  994. .then(response => {
  995. let self = this;
  996. let res = response.data.data;
  997. $('.postCommentsLoader').addClass('d-none');
  998. for(let i=0; i < res.length; i++) {
  999. this.results.unshift(res[i]);
  1000. }
  1001. this.pagination = response.data.meta.pagination;
  1002. $('.load-more-link').removeClass('d-none');
  1003. });
  1004. },
  1005. likeReply(status, $event) {
  1006. if($('body').hasClass('loggedIn') == false) {
  1007. swal('Login', 'Please login to perform this action.', 'info');
  1008. return;
  1009. }
  1010. axios.post('/i/like', {
  1011. item: status.id
  1012. }).then(res => {
  1013. status.favourites_count = res.data.count;
  1014. if(status.favourited == true) {
  1015. status.favourited = false;
  1016. } else {
  1017. status.favourited = true;
  1018. }
  1019. }).catch(err => {
  1020. swal('Error', 'Something went wrong, please try again later.', 'error');
  1021. });
  1022. },
  1023. truncate(str,lim) {
  1024. return _.truncate(str,{
  1025. length: lim
  1026. });
  1027. },
  1028. timeAgo(ts) {
  1029. return App.util.format.timeAgo(ts);
  1030. },
  1031. emojiReaction() {
  1032. let em = event.target.innerText;
  1033. if(this.replyText.length == 0) {
  1034. this.reply_to_profile_id = this.status.account.id;
  1035. this.replyText = em + ' ';
  1036. $('textarea[name="comment"]').focus();
  1037. } else {
  1038. this.reply_to_profile_id = this.status.account.id;
  1039. this.replyText += em + ' ';
  1040. $('textarea[name="comment"]').focus();
  1041. }
  1042. },
  1043. toggleCommentVisibility() {
  1044. if(this.ownerOrAdmin() == false) {
  1045. return;
  1046. }
  1047. let state = this.status.comments_disabled;
  1048. let self = this;
  1049. if(state == true) {
  1050. // re-enable comments
  1051. axios.post('/i/visibility', {
  1052. item: self.status.id,
  1053. disableComments: false
  1054. }).then(function(res) {
  1055. self.status.comments_disabled = false;
  1056. self.$refs.ctxModal.hide();
  1057. window.location.reload();
  1058. }).catch(function(err) {
  1059. return;
  1060. });
  1061. } else {
  1062. // disable comments
  1063. axios.post('/i/visibility', {
  1064. item: self.status.id,
  1065. disableComments: true
  1066. }).then(function(res) {
  1067. self.status.comments_disabled = true;
  1068. self.showComments = false;
  1069. self.$refs.ctxModal.hide();
  1070. }).catch(function(err) {
  1071. return;
  1072. });
  1073. }
  1074. },
  1075. fetchRelationships() {
  1076. if(document.querySelectorAll('body')[0].classList.contains('loggedIn') == false) {
  1077. this.fetchData();
  1078. return;
  1079. } else {
  1080. axios.get('/api/pixelfed/v1/accounts/relationships', {
  1081. params: {
  1082. 'id[]': this.statusProfileId
  1083. }
  1084. }).then(res => {
  1085. if(res.data[0] == null) {
  1086. this.fetchData();
  1087. return;
  1088. }
  1089. this.relationship = res.data[0];
  1090. if(res.data[0].blocking == true) {
  1091. this.loaded = true;
  1092. this.warning = true;
  1093. return;
  1094. } else {
  1095. this.fetchData();
  1096. return;
  1097. }
  1098. });
  1099. }
  1100. },
  1101. visibilityModal() {
  1102. switch(this.status.visibility) {
  1103. case 'public':
  1104. swal('Public Post', 'This post is visible to everyone.', 'info');
  1105. break;
  1106. case 'unlisted':
  1107. swal('Unlisted Post', 'This post is visible on profiles and with a direct links. It is not displayed on timelines.', 'info');
  1108. break;
  1109. case 'private':
  1110. swal('Private Post', 'This post is only visible to followers.', 'info');
  1111. break;
  1112. }
  1113. },
  1114. toggleReplies(reply) {
  1115. if(reply.thread) {
  1116. reply.thread = false;
  1117. } else {
  1118. if(reply.replies.length > 0) {
  1119. reply.thread = true;
  1120. return;
  1121. }
  1122. let url = '/api/v2/comments/'+reply.account.id+'/status/'+reply.id;
  1123. axios.get(url)
  1124. .then(response => {
  1125. reply.replies = _.reverse(response.data.data);
  1126. reply.thread = true;
  1127. });
  1128. }
  1129. },
  1130. redirect(url) {
  1131. window.location.href = url;
  1132. },
  1133. permalinkUrl(reply, showOrigin = false) {
  1134. let profile = reply.account;
  1135. if(profile.local == true) {
  1136. return reply.url;
  1137. } else {
  1138. return showOrigin ?
  1139. reply.url :
  1140. '/i/web/post/_/' + profile.id + '/' + reply.id;
  1141. }
  1142. },
  1143. fetchProfilePosts() {
  1144. if(!$('body').hasClass('loggedIn') && this.loaded) {
  1145. return;
  1146. }
  1147. let self = this;
  1148. let apiUrl = '/api/pixelfed/v1/accounts/' + this.statusProfileId + '/statuses';
  1149. axios.get(apiUrl, {
  1150. params: {
  1151. only_media: true,
  1152. min_id: 1,
  1153. limit: 9
  1154. }
  1155. })
  1156. .then(res => {
  1157. let data = res.data.filter(function(status) {
  1158. return status.media_attachments.length > 0 &&
  1159. status.id != self.statusId &&
  1160. status.sensitive == false
  1161. });
  1162. let ids = data.map(status => status.id);
  1163. // if(data.length >= 3) {
  1164. // self.showProfileMorePosts = true;
  1165. // }
  1166. self.profileMorePosts = data.slice(0,6);
  1167. })
  1168. },
  1169. previewUrl(status) {
  1170. return status.sensitive ? '/storage/no-preview.png?v=' + new Date().getTime() : status.media_attachments[0].preview_url;
  1171. },
  1172. previewBackground(status) {
  1173. let preview = this.previewUrl(status);
  1174. return 'background-image: url(' + preview + ');';
  1175. },
  1176. getStatusUrl(status, showOrigin = false) {
  1177. if(status.local == true || showOrigin == true) {
  1178. return status.url;
  1179. }
  1180. return '/i/web/post/_/' + status.account.id + '/' + status.id;
  1181. },
  1182. showTaggedPeopleModal() {
  1183. if(!$('body').hasClass('loggedIn') && this.loaded) {
  1184. return;
  1185. }
  1186. this.$refs.taggedModal.show();
  1187. },
  1188. untagMe() {
  1189. this.$refs.taggedModal.hide();
  1190. let id = this.user.id;
  1191. axios.post('/api/local/compose/tag/untagme', {
  1192. status_id: this.statusId,
  1193. profile_id: id
  1194. }).then(res => {
  1195. this.status.taggedPeople = this.status.taggedPeople.filter(t => {
  1196. return t.id != id;
  1197. });
  1198. swal('Untagged', 'You have been untagged from this post.', 'success');
  1199. }).catch(err => {
  1200. swal('An Error Occurred', 'Please try again later.', 'error');
  1201. });
  1202. },
  1203. copyPostUrl() {
  1204. navigator.clipboard.writeText(this.statusUrl);
  1205. return;
  1206. },
  1207. moderatePost(action, $event) {
  1208. let status = this.status;
  1209. let username = status.account.username;
  1210. let msg = '';
  1211. let self = this;
  1212. switch(action) {
  1213. case 'addcw':
  1214. msg = 'Are you sure you want to add a content warning to this post?';
  1215. swal({
  1216. title: 'Confirm',
  1217. text: msg,
  1218. icon: 'warning',
  1219. buttons: true,
  1220. dangerMode: true
  1221. }).then(res => {
  1222. if(res) {
  1223. axios.post('/api/v2/moderator/action', {
  1224. action: action,
  1225. item_id: status.id,
  1226. item_type: 'status'
  1227. }).then(res => {
  1228. swal('Success', 'Successfully added content warning', 'success');
  1229. status.sensitive = true;
  1230. self.ctxModMenuClose();
  1231. }).catch(err => {
  1232. swal(
  1233. 'Error',
  1234. 'Something went wrong, please try again later.',
  1235. 'error'
  1236. );
  1237. self.ctxModMenuClose();
  1238. });
  1239. }
  1240. });
  1241. break;
  1242. case 'remcw':
  1243. msg = 'Are you sure you want to remove the content warning on this post?';
  1244. swal({
  1245. title: 'Confirm',
  1246. text: msg,
  1247. icon: 'warning',
  1248. buttons: true,
  1249. dangerMode: true
  1250. }).then(res => {
  1251. if(res) {
  1252. axios.post('/api/v2/moderator/action', {
  1253. action: action,
  1254. item_id: status.id,
  1255. item_type: 'status'
  1256. }).then(res => {
  1257. swal('Success', 'Successfully added content warning', 'success');
  1258. status.sensitive = false;
  1259. self.ctxModMenuClose();
  1260. }).catch(err => {
  1261. swal(
  1262. 'Error',
  1263. 'Something went wrong, please try again later.',
  1264. 'error'
  1265. );
  1266. self.ctxModMenuClose();
  1267. });
  1268. }
  1269. });
  1270. break;
  1271. case 'unlist':
  1272. msg = 'Are you sure you want to unlist this post?';
  1273. swal({
  1274. title: 'Confirm',
  1275. text: msg,
  1276. icon: 'warning',
  1277. buttons: true,
  1278. dangerMode: true
  1279. }).then(res => {
  1280. if(res) {
  1281. axios.post('/api/v2/moderator/action', {
  1282. action: action,
  1283. item_id: status.id,
  1284. item_type: 'status'
  1285. }).then(res => {
  1286. // this.feed = this.feed.filter(f => {
  1287. // return f.id != status.id;
  1288. // });
  1289. swal('Success', 'Successfully unlisted post', 'success');
  1290. self.ctxModMenuClose();
  1291. }).catch(err => {
  1292. self.ctxModMenuClose();
  1293. swal(
  1294. 'Error',
  1295. 'Something went wrong, please try again later.',
  1296. 'error'
  1297. );
  1298. });
  1299. }
  1300. });
  1301. break;
  1302. }
  1303. },
  1304. ctxMenu() {
  1305. this.$refs.ctxModal.show();
  1306. return;
  1307. },
  1308. closeCtxMenu(truncate) {
  1309. this.$refs.ctxModal.hide();
  1310. },
  1311. ctxModMenu() {
  1312. this.$refs.ctxModal.hide();
  1313. this.$refs.ctxModModal.show();
  1314. },
  1315. ctxModMenuClose() {
  1316. this.$refs.ctxModal.hide();
  1317. this.$refs.ctxModModal.hide();
  1318. },
  1319. ctxMenuCopyLink() {
  1320. let status = this.status;
  1321. navigator.clipboard.writeText(status.url);
  1322. this.closeCtxMenu();
  1323. return;
  1324. },
  1325. ctxMenuFollow() {
  1326. let id = this.status.account.id;
  1327. axios.post('/i/follow', {
  1328. item: id
  1329. }).then(res => {
  1330. let username = this.status.account.acct;
  1331. this.relationship.following = true;
  1332. this.$refs.ctxModal.hide();
  1333. setTimeout(function() {
  1334. swal('Follow successful!', 'You are now following ' + username, 'success');
  1335. }, 500);
  1336. });
  1337. },
  1338. ctxMenuUnfollow() {
  1339. let id = this.status.account.id;
  1340. axios.post('/i/follow', {
  1341. item: id
  1342. }).then(res => {
  1343. let username = this.status.account.acct;
  1344. this.relationship.following = false;
  1345. this.$refs.ctxModal.hide();
  1346. setTimeout(function() {
  1347. swal('Unfollow successful!', 'You are no longer following ' + username, 'success');
  1348. }, 500);
  1349. });
  1350. },
  1351. setCurrentLayout(layout) {
  1352. this.currentLayout = layout;
  1353. },
  1354. commentFocus(status, $event) {
  1355. if(status.comments_disabled) {
  1356. return;
  1357. }
  1358. this.replies = {};
  1359. this.replyStatus = {};
  1360. this.replyText = '';
  1361. this.replyId = status.id;
  1362. this.replyStatus = status;
  1363. // this.$refs.replyModal.show();
  1364. this.fetchStatusComments(status, '');
  1365. $('nav').hide();
  1366. $('footer').hide();
  1367. $('.mobile-footer-spacer').attr('style', 'display:none !important');
  1368. $('.mobile-footer').attr('style', 'display:none !important');
  1369. $('.mt-md-4').hide();
  1370. this.currentLayout = 'comments';
  1371. window.history.pushState({}, '', this.getStatusUrl(status));
  1372. return;
  1373. },
  1374. fetchStatusComments(status, card) {
  1375. let url = '/api/v2/comments/'+status.account.id+'/status/'+status.id;
  1376. axios.get(url)
  1377. .then(response => {
  1378. let self = this;
  1379. this.replies = _.reverse(response.data.data);
  1380. this.pagination = response.data.meta.pagination;
  1381. if(this.replies.length > 0) {
  1382. $('.load-more-link').removeClass('d-none');
  1383. }
  1384. $('.postCommentsLoader').addClass('d-none');
  1385. $('.postCommentsContainer').removeClass('d-none');
  1386. // setTimeout(function() {
  1387. // document.querySelectorAll('.status-comment .postCommentsContainer .comment-body a').forEach(function(i, e) {
  1388. // i.href = App.util.format.rewriteLinks(i);
  1389. // });
  1390. // }, 500);
  1391. }).catch(error => {
  1392. if(!error.response) {
  1393. $('.postCommentsLoader .lds-ring')
  1394. .attr('style','width:100%')
  1395. .addClass('pt-4 font-weight-bold text-muted')
  1396. .text('An error occurred, cannot fetch comments. Please try again later.');
  1397. } else {
  1398. switch(error.response.status) {
  1399. case 401:
  1400. $('.postCommentsLoader .lds-ring')
  1401. .attr('style','width:100%')
  1402. .addClass('pt-4 font-weight-bold text-muted')
  1403. .text('Please login to view.');
  1404. break;
  1405. default:
  1406. $('.postCommentsLoader .lds-ring')
  1407. .attr('style','width:100%')
  1408. .addClass('pt-4 font-weight-bold text-muted')
  1409. .text('An error occurred, cannot fetch comments. Please try again later.');
  1410. break;
  1411. }
  1412. }
  1413. });
  1414. },
  1415. },
  1416. }
  1417. </script>