PostComponent.vue 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  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 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">Click <a href="#" class="cursor-pointer" @click.prevent="warning = false; fetchData()">here</a> to view this status</p>
  10. </div>
  11. </div>
  12. <div v-if="loaded && warning == false" class="postComponent">
  13. <div v-if="profileLayout == 'metro'" class="container px-0">
  14. <div class="card card-md-rounded-0 status-container orientation-unknown">
  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. <a :href="statusProfileUrl" class="d-flex align-items-center status-username text-truncate" data-toggle="tooltip" data-placement="bottom" :title="statusUsername">
  18. <div class="status-avatar mr-2">
  19. <img :src="statusAvatar" width="24px" height="24px" style="border-radius:12px;">
  20. </div>
  21. <div class="username">
  22. <span class="username-link font-weight-bold text-dark">{{ statusUsername }}</span>
  23. </div>
  24. </a>
  25. <div v-if="user != false" class="float-right">
  26. <div class="post-actions">
  27. <div class="dropdown">
  28. <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">
  29. <span class="fas fa-ellipsis-v text-muted"></span>
  30. </button>
  31. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
  32. <div v-if="!owner()">
  33. <a class="dropdown-item font-weight-bold" :href="reportUrl()">Report</a>
  34. <a class="dropdown-item font-weight-bold" v-on:click="muteProfile()">Mute Profile</a>
  35. <a class="dropdown-item font-weight-bold" v-on:click="blockProfile()">Block Profile</a>
  36. </div>
  37. <div v-if="ownerOrAdmin()">
  38. <a class="dropdown-item font-weight-bold" href="#" v-on:click.prevent="toggleCommentVisibility">{{ showComments ? 'Disable' : 'Enable'}} Comments</a>
  39. <a class="dropdown-item font-weight-bold" :href="editUrl()">Edit</a>
  40. <a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost(status)">Delete</a>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. <div class="col-12 col-md-8 px-0 mx-0">
  48. <div class="postPresenterContainer d-none d-flex justify-content-center align-items-center">
  49. <div v-if="status.pf_type === 'photo'" class="w-100">
  50. <photo-presenter :status="status" v-on:lightbox="lightbox"></photo-presenter>
  51. </div>
  52. <div v-else-if="status.pf_type === 'video'" class="w-100">
  53. <video-presenter :status="status"></video-presenter>
  54. </div>
  55. <div v-else-if="status.pf_type === 'photo:album'" class="w-100">
  56. <photo-album-presenter :status="status" v-on:lightbox="lightbox"></photo-album-presenter>
  57. </div>
  58. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  59. <video-album-presenter :status="status"></video-album-presenter>
  60. </div>
  61. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  62. <mixed-album-presenter :status="status" v-on:lightbox="lightbox"></mixed-album-presenter>
  63. </div>
  64. <div v-else class="w-100">
  65. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  66. </div>
  67. </div>
  68. </div>
  69. <div class="col-12 col-md-4 px-0 d-flex flex-column border-left border-md-left-0">
  70. <div class="d-md-flex d-none align-items-center justify-content-between card-header py-3 bg-white">
  71. <a :href="statusProfileUrl" class="d-flex align-items-center status-username text-truncate" data-toggle="tooltip" data-placement="bottom" :title="statusUsername">
  72. <div class="status-avatar mr-2">
  73. <img :src="statusAvatar" width="24px" height="24px" style="border-radius:12px;">
  74. </div>
  75. <div class="username">
  76. <span class="username-link font-weight-bold text-dark">{{ statusUsername }}</span>
  77. </div>
  78. </a>
  79. <div class="float-right">
  80. <div class="post-actions">
  81. <div v-if="user != false" class="dropdown">
  82. <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">
  83. <span class="fas fa-ellipsis-v text-muted"></span>
  84. </button>
  85. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
  86. <span v-if="!owner()">
  87. <a class="dropdown-item font-weight-bold" :href="reportUrl()">Report</a>
  88. <a class="dropdown-item font-weight-bold" v-on:click="muteProfile">Mute Profile</a>
  89. <a class="dropdown-item font-weight-bold" v-on:click="blockProfile">Block Profile</a>
  90. </span>
  91. <span v-if="ownerOrAdmin()">
  92. <a class="dropdown-item font-weight-bold" href="#" v-on:click.prevent="toggleCommentVisibility">{{ showComments ? 'Disable' : 'Enable'}} Comments</a>
  93. <a class="dropdown-item font-weight-bold" :href="editUrl()">Edit</a>
  94. <a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost">Delete</a>
  95. </span>
  96. </div>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. <div class="d-flex flex-md-column flex-column-reverse h-100">
  102. <div class="card-body status-comments pb-5">
  103. <div class="status-comment">
  104. <p class="mb-1 read-more" style="overflow: hidden;">
  105. <span class="font-weight-bold pr-1">{{statusUsername}}</span>
  106. <span class="comment-text" :id="status.id + '-status-readmore'" v-html="status.content"></span>
  107. </p>
  108. <div v-if="showComments">
  109. <div class="postCommentsLoader text-center">
  110. <div class="spinner-border" role="status">
  111. <span class="sr-only">Loading...</span>
  112. </div>
  113. </div>
  114. <div class="postCommentsContainer d-none pt-3">
  115. <p v-if="status.reply_count > 10"class="mb-1 text-center load-more-link d-none"><a href="#" class="text-muted" v-on:click="loadMore">Load more comments</a></p>
  116. <div class="comments" data-min-id="0" data-max-id="0">
  117. <div v-for="(reply, index) in results" class="pb-3">
  118. <p class="d-flex justify-content-between align-items-top read-more" style="overflow-y: hidden;">
  119. <span>
  120. <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>
  121. <span class="text-break" v-html="reply.content"></span>
  122. </span>
  123. <span class="pl-2" style="min-width:38px">
  124. <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>
  125. <post-menu :status="reply" :profile="user" :size="'sm'" :modal="'true'" class="d-inline-block pl-2" v-on:deletePost="deleteComment(reply.id, index)"></post-menu>
  126. </span>
  127. </p>
  128. <p class="">
  129. <span class="text-muted mr-3" style="width: 20px;" v-text="timeAgo(reply.created_at)"></span>
  130. <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>
  131. <span class="text-muted comment-reaction font-weight-bold cursor-pointer" v-on:click="replyFocus(reply)">Reply</span>
  132. </p>
  133. <div v-if="reply.reply_count > 0" class="cursor-pointer" style="margin-left:30px;" v-on:click="toggleReplies(reply)">
  134. <span class="show-reply-bar"></span>
  135. <span class="comment-reaction font-weight-bold text-muted">{{reply.thread ? 'Hide' : 'View'}} Replies ({{reply.reply_count}})</span>
  136. </div>
  137. <div v-if="reply.thread == true" class="comment-thread">
  138. <p class="d-flex justify-content-between align-items-top read-more pb-3" style="overflow-y: hidden;" v-for="(s, index) in reply.replies">
  139. <span>
  140. <a class="text-dark font-weight-bold mr-1" :href="s.account.url" :title="s.account.username">{{s.account.username}}</a>
  141. <span class="text-break" v-html="s.content"></span>
  142. </span>
  143. </p>
  144. </div>
  145. </div>
  146. </div>
  147. </div>
  148. </div>
  149. </div>
  150. </div>
  151. <div class="card-body flex-grow-0 py-1">
  152. <div class="reactions my-1">
  153. <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>
  154. <h3 v-if="!status.comments_disabled" class="far fa-comment pr-3 m-0 cursor-pointer" title="Comment" v-on:click="replyFocus(status)"></h3>
  155. <h3 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>
  156. <h3 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>
  157. </div>
  158. <div class="reaction-counts font-weight-bold mb-0">
  159. <span style="cursor:pointer;" v-on:click="likesModal">
  160. <span class="like-count">{{status.favourites_count || 0}}</span> likes
  161. </span>
  162. <span class="float-right" style="cursor:pointer;" v-on:click="sharesModal">
  163. <span class="share-count pl-4">{{status.reblogs_count || 0}}</span> shares
  164. </span>
  165. </div>
  166. <div class="timestamp pt-2 d-flex align-items-bottom justify-content-between">
  167. <a v-bind:href="statusUrl" class="small text-muted">
  168. {{timestampFormat()}}
  169. </a>
  170. <span class="small text-muted text-capitalize cursor-pointer" v-on:click="visibilityModal">{{status.visibility}}</span>
  171. </div>
  172. </div>
  173. </div>
  174. <div v-if="showComments && user.length !== 0" class="card-footer bg-white px-2 py-0">
  175. <ul class="nav align-items-center emoji-reactions" style="overflow-x: scroll;flex-wrap: unset;">
  176. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜‚</li>
  177. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ’ฏ</li>
  178. <li class="nav-item" v-on:click="emojiReaction">โค๏ธ</li>
  179. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ™Œ</li>
  180. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ‘</li>
  181. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜</li>
  182. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜ฏ</li>
  183. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜ข</li>
  184. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜…</li>
  185. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜</li>
  186. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ™‚</li>
  187. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜Ž</li>
  188. </ul>
  189. </div>
  190. <div v-if="showComments" class="card-footer bg-white sticky-md-bottom p-0">
  191. <div v-if="user.length == 0" class="comment-form-guest p-3">
  192. <a href="/login">Login</a> to like or comment.
  193. </div>
  194. <form v-else class="border-0 rounded-0 align-middle" method="post" action="/i/comment" :data-id="statusId" data-truncate="false">
  195. <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>
  196. <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"/>
  197. </form>
  198. </div>
  199. </div>
  200. </div>
  201. </div>
  202. </div>
  203. <div v-if="profileLayout == 'moment'" class="momentui">
  204. <div class="bg-dark mt-md-n4">
  205. <div class="container", v-on:doubletap="likeStatus(status, $event)">
  206. <div class="postPresenterContainer d-none d-flex justify-content-center align-items-center bg-dark">
  207. <div v-if="status.pf_type === 'photo'" class="w-100">
  208. <photo-presenter :status="status" v-on:lightbox="lightbox"></photo-presenter>
  209. </div>
  210. <div v-else-if="status.pf_type === 'video'" class="w-100">
  211. <video-presenter :status="status"></video-presenter>
  212. </div>
  213. <div v-else-if="status.pf_type === 'photo:album'" class="w-100">
  214. <photo-album-presenter :status="status" v-on:lightbox="lightbox"></photo-album-presenter>
  215. </div>
  216. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  217. <video-album-presenter :status="status"></video-album-presenter>
  218. </div>
  219. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  220. <mixed-album-presenter :status="status" v-on:lightbox="lightbox"></mixed-album-presenter>
  221. </div>
  222. <div v-else class="w-100">
  223. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  224. </div>
  225. </div>
  226. </div>
  227. </div>
  228. <div class="bg-white">
  229. <div class="container">
  230. <div class="row py-5">
  231. <div class="col-12 col-md-8">
  232. <div class="reactions py-2">
  233. <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>
  234. <h3 v-if="!status.comments_disabled" class="far fa-comment pr-3 m-0 cursor-pointer" title="Comment" v-on:click="replyFocus(status)"></h3>
  235. <h3 v-bind:class="[reactions.shared ? 'far fa-share-square pr-3 m-0 text-primary float-right cursor-pointer' : 'far fa-share-square pr-3 m-0 share-btn float-right cursor-pointer']" title="Share" v-on:click="shareStatus"></h3>
  236. </div>
  237. <div class="reaction-counts font-weight-bold mb-0">
  238. <span style="cursor:pointer;" v-on:click="likesModal">
  239. <span class="like-count">{{status.favourites_count || 0}}</span> likes
  240. </span>
  241. <span class="float-right" style="cursor:pointer;" v-on:click="sharesModal">
  242. <span class="share-count pl-4">{{status.reblogs_count || 0}}</span> shares
  243. </span>
  244. </div>
  245. <hr>
  246. <div class="media align-items-center">
  247. <img :src="statusAvatar" class="rounded-circle shadow-lg mr-3" alt="avatar" width="72px" height="72px">
  248. <div class="media-body lead">
  249. by <a :href="statusProfileUrl">{{statusUsername}}</a>
  250. </div>
  251. </div>
  252. <hr>
  253. <div>
  254. <p class="lead"><i class="far fa-clock"></i> {{timestampFormat()}}</p>
  255. <div class="lead" v-html="status.content"></div>
  256. </div>
  257. </div>
  258. <div class="col-12 col-md-4">
  259. <div v-if="status.comments_disabled" class="bg-light p-5 text-center lead">
  260. <p class="mb-0">Comments have been disabled on this post.</p>
  261. </div>
  262. </div>
  263. </div>
  264. </div>
  265. </div>
  266. </div>
  267. </div>
  268. <b-modal ref="likesModal"
  269. id="l-modal"
  270. hide-footer
  271. centered
  272. title="Likes"
  273. body-class="list-group-flush p-0">
  274. <div class="list-group">
  275. <div class="list-group-item border-0" v-for="(user, index) in likes" :key="'modal_likes_'+index">
  276. <div class="media">
  277. <a :href="user.url">
  278. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + 'โ€™s avatar'" width="30px">
  279. </a>
  280. <div class="media-body">
  281. <p class="mb-0" style="font-size: 14px">
  282. <a :href="user.url" class="font-weight-bold text-dark">
  283. {{user.username}}
  284. </a>
  285. </p>
  286. <p class="text-muted mb-0" style="font-size: 14px">
  287. {{user.display_name}}
  288. </a>
  289. </p>
  290. </div>
  291. </div>
  292. </div>
  293. <infinite-loading @infinite="infiniteLikesHandler" spinner="spiral">
  294. <div slot="no-more"></div>
  295. <div slot="no-results"></div>
  296. </infinite-loading>
  297. </div>
  298. </b-modal>
  299. <b-modal ref="sharesModal"
  300. id="s-modal"
  301. hide-footer
  302. centered
  303. title="Shares"
  304. body-class="list-group-flush p-0">
  305. <div class="list-group">
  306. <div class="list-group-item border-0" v-for="(user, index) in shares" :key="'modal_shares_'+index">
  307. <div class="media">
  308. <a :href="user.url">
  309. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + 'โ€™s avatar'" width="30px">
  310. </a>
  311. <div class="media-body">
  312. <div class="d-inline-block">
  313. <p class="mb-0" style="font-size: 14px">
  314. <a :href="user.url" class="font-weight-bold text-dark">
  315. {{user.username}}
  316. </a>
  317. </p>
  318. <p class="text-muted mb-0" style="font-size: 14px">
  319. {{user.display_name}}
  320. </a>
  321. </p>
  322. </div>
  323. <p class="float-right"><!-- <a class="btn btn-primary font-weight-bold py-1" href="#">Follow</a> --></p>
  324. </div>
  325. </div>
  326. </div>
  327. <infinite-loading @infinite="infiniteSharesHandler" spinner="spiral">
  328. <div slot="no-more"></div>
  329. <div slot="no-results"></div>
  330. </infinite-loading>
  331. </div>
  332. </b-modal>
  333. <b-modal
  334. id="lightbox"
  335. ref="lightboxModal"
  336. :hide-header="true"
  337. :hide-footer="true"
  338. centered
  339. size="lg"
  340. body-class="p-0"
  341. >
  342. <div v-if="lightboxMedia" :class="lightboxMedia.filter_class">
  343. <img :src="lightboxMedia.url" class="img-fluid" style="min-height: 100%; min-width: 100%">
  344. </div>
  345. </b-modal>
  346. </div>
  347. </template>
  348. <style type="text/css" scoped>
  349. .status-comments,
  350. .reactions {
  351. background: #fff;
  352. }
  353. .postPresenterContainer {
  354. background: #fff;
  355. }
  356. @media(min-width: 720px) {
  357. .postPresenterContainer {
  358. min-height: 600px;
  359. }
  360. }
  361. ::-webkit-scrollbar {
  362. width: 0px;
  363. background: transparent;
  364. }
  365. .reply-btn {
  366. position: absolute;
  367. bottom: 12px;
  368. right: 20px;
  369. width: 60px;
  370. text-align: center;
  371. border-radius: 0 3px 3px 0;
  372. }
  373. .text-lighter {
  374. color:#B8C2CC !important;
  375. }
  376. .text-break {
  377. overflow-wrap: break-word;
  378. }
  379. .comments p {
  380. margin-bottom: 0;
  381. }
  382. .comment-reaction {
  383. font-size: 80%;
  384. }
  385. .show-reply-bar {
  386. display: inline-block;
  387. border-bottom: 1px solid #999;
  388. height: 0;
  389. margin-right: 16px;
  390. vertical-align: middle;
  391. width: 24px;
  392. }
  393. .comment-thread {
  394. margin: 4px 0 0 40px;
  395. width: calc(100% - 40px);
  396. }
  397. .emoji-reactions .nav-item {
  398. font-size: 1.2rem;
  399. padding: 9px;
  400. cursor: pointer;
  401. }
  402. .emoji-reactions::-webkit-scrollbar {
  403. width: 0px;
  404. height: 0px;
  405. background: transparent;
  406. }
  407. </style>
  408. <style type="text/css">
  409. .momentui .bg-dark {
  410. background: #000 !important;
  411. }
  412. .momentui .carousel.slide,
  413. .momentui .carousel-item {
  414. background: #000 !important;
  415. }
  416. </style>
  417. <script>
  418. pixelfed.postComponent = {};
  419. export default {
  420. props: [
  421. 'status-id',
  422. 'status-username',
  423. 'status-template',
  424. 'status-url',
  425. 'status-profile-url',
  426. 'status-avatar',
  427. 'status-profile-id',
  428. 'profile-layout'
  429. ],
  430. data() {
  431. return {
  432. status: false,
  433. media: {},
  434. user: false,
  435. reactions: {
  436. liked: false,
  437. shared: false
  438. },
  439. likes: [],
  440. likesPage: 1,
  441. shares: [],
  442. sharesPage: 1,
  443. lightboxMedia: false,
  444. replyText: '',
  445. relationship: {},
  446. results: [],
  447. pagination: {},
  448. min_id: 0,
  449. max_id: 0,
  450. reply_to_profile_id: 0,
  451. thread: false,
  452. showComments: false,
  453. warning: false,
  454. loaded: false,
  455. loading: null,
  456. replyingToId: this.statusId,
  457. emoji: ['๐Ÿ˜€','๐Ÿ˜','๐Ÿ˜‚','๐Ÿคฃ','๐Ÿ˜ƒ','๐Ÿ˜„','๐Ÿ˜…','๐Ÿ˜†','๐Ÿ˜‰','๐Ÿ˜Š','๐Ÿ˜‹','๐Ÿ˜Ž','๐Ÿ˜','๐Ÿ˜˜','๐Ÿ˜—','๐Ÿ˜™','๐Ÿ˜š','โ˜บ๏ธ','๐Ÿ™‚','๐Ÿค—','๐Ÿคฉ','๐Ÿค”','๐Ÿคจ','๐Ÿ˜','๐Ÿ˜‘','๐Ÿ˜ถ','๐Ÿ™„','๐Ÿ˜','๐Ÿ˜ฃ','๐Ÿ˜ฅ','๐Ÿ˜ฎ','๐Ÿค','๐Ÿ˜ฏ','๐Ÿ˜ช','๐Ÿ˜ซ','๐Ÿ˜ด','๐Ÿ˜Œ','๐Ÿ˜›','๐Ÿ˜œ','๐Ÿ˜','๐Ÿคค','๐Ÿ˜’','๐Ÿ˜“','๐Ÿ˜”','๐Ÿ˜•','๐Ÿ™ƒ','๐Ÿค‘','๐Ÿ˜ฒ','โ˜น๏ธ','๐Ÿ™','๐Ÿ˜–','๐Ÿ˜ž','๐Ÿ˜Ÿ','๐Ÿ˜ค','๐Ÿ˜ข','๐Ÿ˜ญ','๐Ÿ˜ฆ','๐Ÿ˜ง','๐Ÿ˜จ','๐Ÿ˜ฉ','๐Ÿคฏ','๐Ÿ˜ฌ','๐Ÿ˜ฐ','๐Ÿ˜ฑ','๐Ÿ˜ณ','๐Ÿคช','๐Ÿ˜ต','๐Ÿ˜ก','๐Ÿ˜ ','๐Ÿคฌ','๐Ÿ˜ท','๐Ÿค’','๐Ÿค•','๐Ÿคข','๐Ÿคฎ','๐Ÿคง','๐Ÿ˜‡','๐Ÿค ','๐Ÿคก','๐Ÿคฅ','๐Ÿคซ','๐Ÿคญ','๐Ÿง','๐Ÿค“','๐Ÿ˜ˆ','๐Ÿ‘ฟ','๐Ÿ‘น','๐Ÿ‘บ','๐Ÿ’€','๐Ÿ‘ป','๐Ÿ‘ฝ','๐Ÿค–','๐Ÿ’ฉ','๐Ÿ˜บ','๐Ÿ˜ธ','๐Ÿ˜น','๐Ÿ˜ป','๐Ÿ˜ผ','๐Ÿ˜ฝ','๐Ÿ™€','๐Ÿ˜ฟ','๐Ÿ˜พ','๐Ÿคฒ','๐Ÿ‘','๐Ÿ™Œ','๐Ÿ‘','๐Ÿค','๐Ÿ‘','๐Ÿ‘Ž','๐Ÿ‘Š','โœŠ','๐Ÿค›','๐Ÿคœ','๐Ÿคž','โœŒ๏ธ','๐ŸคŸ','๐Ÿค˜','๐Ÿ‘Œ','๐Ÿ‘ˆ','๐Ÿ‘‰','๐Ÿ‘†','๐Ÿ‘‡','โ˜๏ธ','โœ‹','๐Ÿคš','๐Ÿ–','๐Ÿ––','๐Ÿ‘‹','๐Ÿค™','๐Ÿ’ช','๐Ÿ–•','โœ๏ธ','๐Ÿ™','๐Ÿ’','๐Ÿ’„','๐Ÿ’‹','๐Ÿ‘„','๐Ÿ‘…','๐Ÿ‘‚','๐Ÿ‘ƒ','๐Ÿ‘ฃ','๐Ÿ‘','๐Ÿ‘€','๐Ÿง ','๐Ÿ—ฃ','๐Ÿ‘ค','๐Ÿ‘ฅ'],
  458. }
  459. },
  460. mounted() {
  461. this.fetchRelationships();
  462. },
  463. updated() {
  464. $('.carousel').carousel();
  465. window.pixelfed.readmore();
  466. },
  467. methods: {
  468. showMuteBlock() {
  469. let sid = this.status.account.id;
  470. let uid = this.user.id;
  471. if(sid == uid) {
  472. $('.post-actions .menu-author').removeClass('d-none');
  473. } else {
  474. $('.post-actions .menu-user').removeClass('d-none');
  475. }
  476. },
  477. reportUrl() {
  478. return '/i/report?type=post&id=' + this.status.id;
  479. },
  480. editUrl() {
  481. return this.status.url + '/edit';
  482. },
  483. timestampFormat() {
  484. let ts = new Date(this.status.created_at);
  485. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  486. },
  487. fetchData() {
  488. axios.get('/api/v2/profile/'+this.statusUsername+'/status/'+this.statusId)
  489. .then(response => {
  490. let self = this;
  491. self.status = response.data.status;
  492. self.user = response.data.user;
  493. self.media = self.status.media_attachments;
  494. self.reactions = response.data.reactions;
  495. self.likes = response.data.likes;
  496. self.shares = response.data.shares;
  497. self.likesPage = 2;
  498. self.sharesPage = 2;
  499. this.showMuteBlock();
  500. if(self.status.comments_disabled == false) {
  501. self.showComments = true;
  502. this.fetchComments();
  503. }
  504. this.loaded = true;
  505. $('head title').text(this.status.account.username + ' posted a photo: ' + this.status.favourites_count + ' likes');
  506. }).catch(error => {
  507. if(!error.response) {
  508. } else {
  509. switch(error.response.status) {
  510. case 401:
  511. break;
  512. default:
  513. break;
  514. }
  515. }
  516. });
  517. },
  518. likesModal() {
  519. if(this.status.favourites_count == 0 || $('body').hasClass('loggedIn') == false) {
  520. return;
  521. }
  522. this.$refs.likesModal.show();
  523. },
  524. sharesModal() {
  525. if(this.status.reblogs_count == 0 || $('body').hasClass('loggedIn') == false) {
  526. return;
  527. }
  528. this.$refs.sharesModal.show();
  529. },
  530. infiniteLikesHandler($state) {
  531. let api = '/api/v2/likes/profile/'+this.statusUsername+'/status/'+this.statusId;
  532. axios.get(api, {
  533. params: {
  534. page: this.likesPage,
  535. },
  536. }).then(({ data }) => {
  537. if (data.data.length > 0) {
  538. this.likes.push(...data.data);
  539. this.likesPage++;
  540. $state.loaded();
  541. } else {
  542. $state.complete();
  543. }
  544. });
  545. },
  546. infiniteSharesHandler($state) {
  547. axios.get('/api/v2/shares/profile/'+this.statusUsername+'/status/'+this.statusId, {
  548. params: {
  549. page: this.sharesPage,
  550. },
  551. }).then(({ data }) => {
  552. if (data.data.length > 0) {
  553. this.shares.push(...data.data);
  554. this.sharesPage++;
  555. $state.loaded();
  556. } else {
  557. $state.complete();
  558. }
  559. });
  560. },
  561. likeStatus(event) {
  562. if($('body').hasClass('loggedIn') == false) {
  563. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  564. return;
  565. }
  566. axios.post('/i/like', {
  567. item: this.status.id
  568. }).then(res => {
  569. this.status.favourites_count = res.data.count;
  570. if(this.reactions.liked == true) {
  571. this.reactions.liked = false;
  572. let user = this.user.id;
  573. this.likes = this.likes.filter(function(like) {
  574. return like.id !== user;
  575. });
  576. } else {
  577. this.reactions.liked = true;
  578. let user = this.user;
  579. this.likes.push(user);
  580. }
  581. }).catch(err => {
  582. console.error(err);
  583. swal('Error', 'Something went wrong, please try again later.', 'error');
  584. });
  585. },
  586. shareStatus() {
  587. if($('body').hasClass('loggedIn') == false) {
  588. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  589. return;
  590. }
  591. axios.post('/i/share', {
  592. item: this.status.id
  593. }).then(res => {
  594. this.status.reblogs_count = res.data.count;
  595. if(this.reactions.shared == true) {
  596. this.reactions.shared = false;
  597. let user = this.user.id;
  598. this.shares = this.shares.filter(function(reaction) {
  599. return reaction.id !== user;
  600. });
  601. } else {
  602. this.reactions.shared = true;
  603. let user = this.user;
  604. this.shares.push(user);
  605. }
  606. }).catch(err => {
  607. console.error(err);
  608. swal('Error', 'Something went wrong, please try again later.', 'error');
  609. });
  610. },
  611. bookmarkStatus() {
  612. if($('body').hasClass('loggedIn') == false) {
  613. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  614. return;
  615. }
  616. axios.post('/i/bookmark', {
  617. item: this.status.id
  618. }).then(res => {
  619. if(this.reactions.bookmarked == true) {
  620. this.reactions.bookmarked = false;
  621. } else {
  622. this.reactions.bookmarked = true;
  623. }
  624. }).catch(err => {
  625. swal('Error', 'Something went wrong, please try again later.', 'error');
  626. });
  627. },
  628. muteProfile() {
  629. if($('body').hasClass('loggedIn') == false) {
  630. return;
  631. }
  632. axios.post('/i/mute', {
  633. type: 'user',
  634. item: this.status.account.id
  635. }).then(res => {
  636. swal('Success', 'You have successfully muted ' + this.status.account.acct, 'success');
  637. }).catch(err => {
  638. swal('Error', 'Something went wrong. Please try again later.', 'error');
  639. });
  640. },
  641. blockProfile() {
  642. if($('body').hasClass('loggedIn') == false) {
  643. return;
  644. }
  645. axios.post('/i/block', {
  646. type: 'user',
  647. item: this.status.account.id
  648. }).then(res => {
  649. swal('Success', 'You have successfully blocked ' + this.status.account.acct, 'success');
  650. }).catch(err => {
  651. swal('Error', 'Something went wrong. Please try again later.', 'error');
  652. });
  653. },
  654. deletePost(status) {
  655. if(!this.ownerOrAdmin()) {
  656. return;
  657. }
  658. var result = confirm('Are you sure you want to delete this post?');
  659. if (result) {
  660. if($('body').hasClass('loggedIn') == false) {
  661. return;
  662. }
  663. axios.post('/i/delete', {
  664. type: 'status',
  665. item: this.status.id
  666. }).then(res => {
  667. swal('Success', 'You have successfully deleted this post', 'success');
  668. window.location.href = '/';
  669. }).catch(err => {
  670. swal('Error', 'Something went wrong. Please try again later.', 'error');
  671. });
  672. }
  673. },
  674. owner() {
  675. return this.user.id === this.status.account.id;
  676. },
  677. admin() {
  678. return this.user.is_admin == true;
  679. },
  680. ownerOrAdmin() {
  681. return this.owner() || this.admin();
  682. },
  683. lightbox(src) {
  684. this.lightboxMedia = src;
  685. this.$refs.lightboxModal.show();
  686. },
  687. postReply() {
  688. let self = this;
  689. if(this.replyText.length == 0 ||
  690. this.replyText.trim() == '@'+this.status.account.acct) {
  691. self.replyText = null;
  692. $('textarea[name="comment"]').blur();
  693. return;
  694. }
  695. let data = {
  696. item: this.replyingToId,
  697. comment: this.replyText
  698. }
  699. axios.post('/i/comment', data)
  700. .then(function(res) {
  701. let entity = res.data.entity;
  702. if(entity.in_reply_to_id == self.status.id) {
  703. self.results.push(entity);
  704. let elem = $('.status-comments')[0];
  705. elem.scrollTop = elem.clientHeight;
  706. } else {
  707. }
  708. self.replyText = '';
  709. });
  710. },
  711. deleteComment(id, i) {
  712. axios.post('/i/delete', {
  713. type: 'comment',
  714. item: id
  715. }).then(res => {
  716. this.results.splice(i, 1);
  717. }).catch(err => {
  718. swal('Something went wrong!', 'Please try again later', 'error');
  719. });
  720. },
  721. l(e) {
  722. let len = e.length;
  723. if(len < 10) { return e; }
  724. return e.substr(0, 10)+'...';
  725. },
  726. replyFocus(e) {
  727. this.replyingToId = e.id;
  728. this.reply_to_profile_id = e.account.id;
  729. this.replyText = '@' + e.account.username + ' ';
  730. $('textarea[name="comment"]').focus();
  731. },
  732. fetchComments() {
  733. let url = '/api/v2/comments/'+this.statusUsername+'/status/'+this.statusId;
  734. axios.get(url)
  735. .then(response => {
  736. let self = this;
  737. this.results = _.reverse(response.data.data);
  738. this.pagination = response.data.meta.pagination;
  739. if(this.results.length > 0) {
  740. $('.load-more-link').removeClass('d-none');
  741. }
  742. $('.postCommentsLoader').addClass('d-none');
  743. $('.postCommentsContainer').removeClass('d-none');
  744. }).catch(error => {
  745. if(!error.response) {
  746. $('.postCommentsLoader .lds-ring')
  747. .attr('style','width:100%')
  748. .addClass('pt-4 font-weight-bold text-muted')
  749. .text('An error occurred, cannot fetch comments. Please try again later.');
  750. } else {
  751. switch(error.response.status) {
  752. case 401:
  753. $('.postCommentsLoader .lds-ring')
  754. .attr('style','width:100%')
  755. .addClass('pt-4 font-weight-bold text-muted')
  756. .text('Please login to view.');
  757. break;
  758. default:
  759. $('.postCommentsLoader .lds-ring')
  760. .attr('style','width:100%')
  761. .addClass('pt-4 font-weight-bold text-muted')
  762. .text('An error occurred, cannot fetch comments. Please try again later.');
  763. break;
  764. }
  765. }
  766. });
  767. },
  768. loadMore(e) {
  769. e.preventDefault();
  770. if(this.pagination.total_pages == 1 || this.pagination.current_page == this.pagination.total_pages) {
  771. $('.load-more-link').addClass('d-none');
  772. return;
  773. }
  774. $('.postCommentsLoader').removeClass('d-none');
  775. let next = this.pagination.links.next;
  776. axios.get(next)
  777. .then(response => {
  778. let self = this;
  779. let res = response.data.data;
  780. $('.postCommentsLoader').addClass('d-none');
  781. for(let i=0; i < res.length; i++) {
  782. this.results.unshift(res[i]);
  783. }
  784. this.pagination = response.data.meta.pagination;
  785. });
  786. },
  787. likeReply(status, $event) {
  788. if($('body').hasClass('loggedIn') == false) {
  789. return;
  790. }
  791. axios.post('/i/like', {
  792. item: status.id
  793. }).then(res => {
  794. status.favourites_count = res.data.count;
  795. if(status.favourited == true) {
  796. status.favourited = false;
  797. } else {
  798. status.favourited = true;
  799. }
  800. }).catch(err => {
  801. swal('Error', 'Something went wrong, please try again later.', 'error');
  802. });
  803. },
  804. truncate(str,lim) {
  805. return _.truncate(str,{
  806. length: lim
  807. });
  808. },
  809. timeAgo(ts) {
  810. let date = Date.parse(ts);
  811. let seconds = Math.floor((new Date() - date) / 1000);
  812. let interval = Math.floor(seconds / 31536000);
  813. if (interval >= 1) {
  814. return interval + "y";
  815. }
  816. interval = Math.floor(seconds / 604800);
  817. if (interval >= 1) {
  818. return interval + "w";
  819. }
  820. interval = Math.floor(seconds / 86400);
  821. if (interval >= 1) {
  822. return interval + "d";
  823. }
  824. interval = Math.floor(seconds / 3600);
  825. if (interval >= 1) {
  826. return interval + "h";
  827. }
  828. interval = Math.floor(seconds / 60);
  829. if (interval >= 1) {
  830. return interval + "m";
  831. }
  832. return Math.floor(seconds) + "s";
  833. },
  834. emojiReaction() {
  835. let em = event.target.innerText;
  836. if(this.replyText.length == 0) {
  837. this.reply_to_profile_id = this.status.account.id;
  838. this.replyText = '@' + this.status.account.username + ' ' + em;
  839. $('textarea[name="comment"]').focus();
  840. } else {
  841. this.reply_to_profile_id = this.status.account.id;
  842. this.replyText += em;
  843. $('textarea[name="comment"]').focus();
  844. }
  845. },
  846. toggleCommentVisibility() {
  847. if(this.ownerOrAdmin() == false) {
  848. return;
  849. }
  850. let state = this.status.comments_disabled;
  851. let self = this;
  852. if(state == true) {
  853. // re-enable comments
  854. axios.post('/i/visibility', {
  855. item: self.status.id,
  856. disableComments: false
  857. }).then(function(res) {
  858. window.location.href = self.status.url;
  859. }).catch(function(err) {
  860. return;
  861. });
  862. } else {
  863. // disable comments
  864. axios.post('/i/visibility', {
  865. item: self.status.id,
  866. disableComments: true
  867. }).then(function(res) {
  868. self.status.comments_disabled = false;
  869. self.showComments = false;
  870. }).catch(function(err) {
  871. return;
  872. });
  873. }
  874. },
  875. fetchRelationships() {
  876. if(document.querySelectorAll('body')[0].classList.contains('loggedIn') == false) {
  877. this.fetchData();
  878. return;
  879. } else {
  880. axios.get('/api/v1/accounts/relationships', {
  881. params: {
  882. 'id[]': this.statusProfileId
  883. }
  884. }).then(res => {
  885. if(res.data[0] == null) {
  886. this.fetchData();
  887. return;
  888. }
  889. this.relationship = res.data[0];
  890. if(res.data[0].blocking == true) {
  891. this.loaded = true;
  892. this.warning = true;
  893. return;
  894. } else {
  895. this.fetchData();
  896. return;
  897. }
  898. });
  899. }
  900. },
  901. visibilityModal() {
  902. switch(this.status.visibility) {
  903. case 'public':
  904. swal('Public Post', 'This post is visible to everyone.', 'info');
  905. break;
  906. case 'unlisted':
  907. swal('Unlisted Post', 'This post is visible on profiles and with a direct links. It is not displayed on timelines.', 'info');
  908. break;
  909. case 'private':
  910. swal('Private Post', 'This post is only visible to followers.', 'info');
  911. break;
  912. }
  913. },
  914. toggleReplies(reply) {
  915. if(reply.thread) {
  916. reply.thread = false;
  917. } else {
  918. if(reply.replies.length > 0) {
  919. reply.thread = true;
  920. return;
  921. }
  922. let url = '/api/v2/comments/'+reply.account.username+'/status/'+reply.id;
  923. axios.get(url)
  924. .then(response => {
  925. reply.replies = _.reverse(response.data.data);
  926. reply.thread = true;
  927. });
  928. }
  929. }
  930. },
  931. }
  932. </script>