PostComponent.vue 60 KB

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