PostComponent.vue 56 KB

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