PostComponent.vue 60 KB

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