PostComponent.vue 58 KB

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