PostComponent.vue 59 KB

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