RemotePost.vue 58 KB

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