RemotePost.vue 53 KB

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