PostComponent.vue 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953
  1. <template>
  2. <div>
  3. <div v-if="loaded && warning" class="bg-white pt-3 border-bottom">
  4. <div class="container">
  5. <p class="text-center font-weight-bold">You are blocking this account</p>
  6. <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>
  7. </div>
  8. </div>
  9. <div v-if="loaded && warning == false" class="postComponent">
  10. <div class="container px-0">
  11. <div class="card card-md-rounded-0 status-container orientation-unknown">
  12. <div class="row px-0 mx-0">
  13. <div class="d-flex d-md-none align-items-center justify-content-between card-header bg-white w-100">
  14. <a :href="statusProfileUrl" class="d-flex align-items-center status-username text-truncate" data-toggle="tooltip" data-placement="bottom" :title="statusUsername">
  15. <div class="status-avatar mr-2">
  16. <img :src="statusAvatar" width="24px" height="24px" style="border-radius:12px;">
  17. </div>
  18. <div class="username">
  19. <span class="username-link font-weight-bold text-dark">{{ statusUsername }}</span>
  20. </div>
  21. </a>
  22. <div v-if="user != false" class="float-right">
  23. <div class="post-actions">
  24. <div class="dropdown">
  25. <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">
  26. <span class="fas fa-ellipsis-v text-muted"></span>
  27. </button>
  28. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
  29. <div v-if="!owner()">
  30. <a class="dropdown-item font-weight-bold" :href="reportUrl()">Report</a>
  31. <a class="dropdown-item font-weight-bold" v-on:click="muteProfile()">Mute Profile</a>
  32. <a class="dropdown-item font-weight-bold" v-on:click="blockProfile()">Block Profile</a>
  33. </div>
  34. <div v-if="ownerOrAdmin()">
  35. <a class="dropdown-item font-weight-bold" href="#" v-on:click.prevent="toggleCommentVisibility">{{ showComments ? 'Disable' : 'Enable'}} Comments</a>
  36. <a class="dropdown-item font-weight-bold" :href="editUrl()">Edit</a>
  37. <a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost(status)">Delete</a>
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. <div class="col-12 col-md-8 px-0 mx-0">
  45. <div class="postPresenterLoader text-center">
  46. <div class="lds-ring"><div></div><div></div><div></div><div></div></div>
  47. </div>
  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>
  204. <b-modal ref="likesModal"
  205. id="l-modal"
  206. hide-footer
  207. centered
  208. title="Likes"
  209. body-class="list-group-flush p-0">
  210. <div class="list-group">
  211. <div class="list-group-item border-0" v-for="(user, index) in likes" :key="'modal_likes_'+index">
  212. <div class="media">
  213. <a :href="user.url">
  214. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  215. </a>
  216. <div class="media-body">
  217. <p class="mb-0" style="font-size: 14px">
  218. <a :href="user.url" class="font-weight-bold text-dark">
  219. {{user.username}}
  220. </a>
  221. </p>
  222. <p class="text-muted mb-0" style="font-size: 14px">
  223. {{user.display_name}}
  224. </a>
  225. </p>
  226. </div>
  227. </div>
  228. </div>
  229. <infinite-loading @infinite="infiniteLikesHandler" spinner="spiral">
  230. <div slot="no-more"></div>
  231. <div slot="no-results"></div>
  232. </infinite-loading>
  233. </div>
  234. </b-modal>
  235. <b-modal ref="sharesModal"
  236. id="s-modal"
  237. hide-footer
  238. centered
  239. title="Shares"
  240. body-class="list-group-flush p-0">
  241. <div class="list-group">
  242. <div class="list-group-item border-0" v-for="(user, index) in shares" :key="'modal_shares_'+index">
  243. <div class="media">
  244. <a :href="user.url">
  245. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  246. </a>
  247. <div class="media-body">
  248. <div class="d-inline-block">
  249. <p class="mb-0" style="font-size: 14px">
  250. <a :href="user.url" class="font-weight-bold text-dark">
  251. {{user.username}}
  252. </a>
  253. </p>
  254. <p class="text-muted mb-0" style="font-size: 14px">
  255. {{user.display_name}}
  256. </a>
  257. </p>
  258. </div>
  259. <p class="float-right"><!-- <a class="btn btn-primary font-weight-bold py-1" href="#">Follow</a> --></p>
  260. </div>
  261. </div>
  262. </div>
  263. <infinite-loading @infinite="infiniteSharesHandler" spinner="spiral">
  264. <div slot="no-more"></div>
  265. <div slot="no-results"></div>
  266. </infinite-loading>
  267. </div>
  268. </b-modal>
  269. <b-modal
  270. id="lightbox"
  271. ref="lightboxModal"
  272. :hide-header="true"
  273. :hide-footer="true"
  274. centered
  275. size="lg"
  276. body-class="p-0"
  277. >
  278. <div v-if="lightboxMedia" :class="lightboxMedia.filter_class">
  279. <img :src="lightboxMedia.url" class="img-fluid" style="min-height: 100%; min-width: 100%">
  280. </div>
  281. </b-modal>
  282. </div>
  283. </template>
  284. <style type="text/css" scoped>
  285. .status-comments,
  286. .reactions,
  287. .col-md-4 {
  288. background: #fff;
  289. }
  290. .postPresenterContainer {
  291. background: #fff;
  292. }
  293. @media(min-width: 720px) {
  294. .postPresenterContainer {
  295. min-height: 600px;
  296. }
  297. }
  298. ::-webkit-scrollbar {
  299. width: 0px;
  300. background: transparent;
  301. }
  302. .reply-btn {
  303. position: absolute;
  304. bottom: 12px;
  305. right: 20px;
  306. width: 60px;
  307. text-align: center;
  308. border-radius: 0 3px 3px 0;
  309. }
  310. .text-lighter {
  311. color:#B8C2CC !important;
  312. }
  313. .text-break {
  314. overflow-wrap: break-word;
  315. }
  316. .comments p {
  317. margin-bottom: 0;
  318. }
  319. .comment-reaction {
  320. font-size: 80%;
  321. }
  322. .show-reply-bar {
  323. display: inline-block;
  324. border-bottom: 1px solid #999;
  325. height: 0;
  326. margin-right: 16px;
  327. vertical-align: middle;
  328. width: 24px;
  329. }
  330. .comment-thread {
  331. margin: 4px 0 0 40px;
  332. width: calc(100% - 40px);
  333. }
  334. .emoji-reactions .nav-item {
  335. font-size: 1.2rem;
  336. padding: 9px;
  337. cursor: pointer;
  338. }
  339. .emoji-reactions::-webkit-scrollbar {
  340. width: 0px;
  341. height: 0px;
  342. background: transparent;
  343. }
  344. </style>
  345. <script>
  346. pixelfed.postComponent = {};
  347. export default {
  348. props: ['status-id', 'status-username', 'status-template', 'status-url', 'status-profile-url', 'status-avatar', 'status-profile-id'],
  349. data() {
  350. return {
  351. status: false,
  352. media: {},
  353. user: false,
  354. reactions: {
  355. liked: false,
  356. shared: false
  357. },
  358. likes: [],
  359. likesPage: 1,
  360. shares: [],
  361. sharesPage: 1,
  362. lightboxMedia: false,
  363. replyText: '',
  364. relationship: {},
  365. results: [],
  366. pagination: {},
  367. min_id: 0,
  368. max_id: 0,
  369. reply_to_profile_id: 0,
  370. thread: false,
  371. showComments: false,
  372. warning: false,
  373. loaded: false,
  374. loading: null,
  375. replyingToId: this.statusId,
  376. emoji: ['😀','😁','😂','🤣','😃','😄','😅','😆','😉','😊','😋','😎','😍','😘','😗','😙','😚','☺️','🙂','🤗','🤩','🤔','🤨','😐','😑','😶','🙄','😏','😣','😥','😮','🤐','😯','😪','😫','😴','😌','😛','😜','😝','🤤','😒','😓','😔','😕','🙃','🤑','😲','☹️','🙁','😖','😞','😟','😤','😢','😭','😦','😧','😨','😩','🤯','😬','😰','😱','😳','🤪','😵','😡','😠','🤬','😷','🤒','🤕','🤢','🤮','🤧','😇','🤠','🤡','🤥','🤫','🤭','🧐','🤓','😈','👿','👹','👺','💀','👻','👽','🤖','💩','😺','😸','😹','😻','😼','😽','🙀','😿','😾','🤲','👐','🙌','👏','🤝','👍','👎','👊','✊','🤛','🤜','🤞','✌️','🤟','🤘','👌','👈','👉','👆','👇','☝️','✋','🤚','🖐','🖖','👋','🤙','💪','🖕','✍️','🙏','💍','💄','💋','👄','👅','👂','👃','👣','👁','👀','🧠','🗣','👤','👥'],
  377. }
  378. },
  379. mounted() {
  380. this.fetchRelationships();
  381. let token = $('meta[name="csrf-token"]').attr('content');
  382. $('input[name="_token"]').each(function(k, v) {
  383. let el = $(v);
  384. el.val(token);
  385. });
  386. },
  387. updated() {
  388. $('.carousel').carousel();
  389. pixelfed.readmore();
  390. if(this.reactions) {
  391. if(this.reactions.bookmarked == true) {
  392. $('.postComponent .far.fa-bookmark').removeClass('far').addClass('fas text-warning');
  393. }
  394. if(this.reactions.shared == true) {
  395. $('.postComponent .far.fa-share-square').addClass('text-primary');
  396. }
  397. if(this.reactions.liked == true) {
  398. $('.postComponent .far.fa-heart').removeClass('far text-dark').addClass('fas text-danger');
  399. }
  400. }
  401. },
  402. methods: {
  403. showMuteBlock() {
  404. let sid = this.status.account.id;
  405. let uid = this.user.id;
  406. if(sid == uid) {
  407. $('.post-actions .menu-author').removeClass('d-none');
  408. } else {
  409. $('.post-actions .menu-user').removeClass('d-none');
  410. }
  411. },
  412. reportUrl() {
  413. return '/i/report?type=post&id=' + this.status.id;
  414. },
  415. editUrl() {
  416. return this.status.url + '/edit';
  417. },
  418. timestampFormat() {
  419. let ts = new Date(this.status.created_at);
  420. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  421. },
  422. fetchData() {
  423. axios.get('/api/v2/profile/'+this.statusUsername+'/status/'+this.statusId)
  424. .then(response => {
  425. let self = this;
  426. self.status = response.data.status;
  427. self.user = response.data.user;
  428. self.media = self.status.media_attachments;
  429. self.reactions = response.data.reactions;
  430. self.likes = response.data.likes;
  431. self.shares = response.data.shares;
  432. self.likesPage = 2;
  433. self.sharesPage = 2;
  434. //this.buildPresenter();
  435. this.showMuteBlock();
  436. pixelfed.readmore();
  437. if(self.status.comments_disabled == false) {
  438. self.showComments = true;
  439. this.fetchComments();
  440. }
  441. $('.postComponent').removeClass('d-none');
  442. $('.postPresenterLoader').addClass('d-none');
  443. $('.postPresenterContainer').removeClass('d-none');
  444. $('head title').text(this.status.account.username + ' posted a photo: ' + this.status.favourites_count + ' likes');
  445. }).catch(error => {
  446. if(!error.response) {
  447. $('.postPresenterLoader .lds-ring').attr('style','width:100%').addClass('pt-4 font-weight-bold text-muted').text('An error occurred, cannot fetch media. Please try again later.');
  448. } else {
  449. switch(error.response.status) {
  450. case 401:
  451. $('.postPresenterLoader .lds-ring')
  452. .attr('style','width:100%')
  453. .addClass('pt-4 font-weight-bold text-muted')
  454. .text('Please login to view.');
  455. break;
  456. default:
  457. $('.postPresenterLoader .lds-ring').attr('style','width:100%').addClass('pt-4 font-weight-bold text-muted').text('An error occurred, cannot fetch media. Please try again later.');
  458. break;
  459. }
  460. }
  461. });
  462. },
  463. likesModal() {
  464. if(this.status.favourites_count == 0 || $('body').hasClass('loggedIn') == false) {
  465. return;
  466. }
  467. this.$refs.likesModal.show();
  468. },
  469. sharesModal() {
  470. if(this.status.reblogs_count == 0 || $('body').hasClass('loggedIn') == false) {
  471. return;
  472. }
  473. this.$refs.sharesModal.show();
  474. },
  475. infiniteLikesHandler($state) {
  476. let api = '/api/v2/likes/profile/'+this.statusUsername+'/status/'+this.statusId;
  477. axios.get(api, {
  478. params: {
  479. page: this.likesPage,
  480. },
  481. }).then(({ data }) => {
  482. if (data.data.length > 0) {
  483. this.likes.push(...data.data);
  484. this.likesPage++;
  485. $state.loaded();
  486. } else {
  487. $state.complete();
  488. }
  489. });
  490. },
  491. infiniteSharesHandler($state) {
  492. axios.get('/api/v2/shares/profile/'+this.statusUsername+'/status/'+this.statusId, {
  493. params: {
  494. page: this.sharesPage,
  495. },
  496. }).then(({ data }) => {
  497. if (data.data.length > 0) {
  498. this.shares.push(...data.data);
  499. this.sharesPage++;
  500. $state.loaded();
  501. } else {
  502. $state.complete();
  503. }
  504. });
  505. },
  506. likeStatus(event) {
  507. if($('body').hasClass('loggedIn') == false) {
  508. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  509. return;
  510. }
  511. axios.post('/i/like', {
  512. item: this.status.id
  513. }).then(res => {
  514. this.status.favourites_count = res.data.count;
  515. if(this.reactions.liked == true) {
  516. this.reactions.liked = false;
  517. let user = this.user.id;
  518. this.likes = this.likes.filter(function(like) {
  519. return like.id !== user;
  520. });
  521. } else {
  522. this.reactions.liked = true;
  523. let user = this.user;
  524. this.likes.push(user);
  525. }
  526. }).catch(err => {
  527. console.error(err);
  528. swal('Error', 'Something went wrong, please try again later.', 'error');
  529. });
  530. },
  531. shareStatus() {
  532. if($('body').hasClass('loggedIn') == false) {
  533. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  534. return;
  535. }
  536. axios.post('/i/share', {
  537. item: this.status.id
  538. }).then(res => {
  539. this.status.reblogs_count = res.data.count;
  540. if(this.reactions.shared == true) {
  541. this.reactions.shared = false;
  542. let user = this.user.id;
  543. this.shares = this.shares.filter(function(reaction) {
  544. return reaction.id !== user;
  545. });
  546. } else {
  547. this.reactions.shared = true;
  548. let user = this.user;
  549. this.shares.push(user);
  550. }
  551. }).catch(err => {
  552. console.error(err);
  553. swal('Error', 'Something went wrong, please try again later.', 'error');
  554. });
  555. },
  556. bookmarkStatus() {
  557. if($('body').hasClass('loggedIn') == false) {
  558. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  559. return;
  560. }
  561. axios.post('/i/bookmark', {
  562. item: this.status.id
  563. }).then(res => {
  564. if(this.reactions.bookmarked == true) {
  565. this.reactions.bookmarked = false;
  566. } else {
  567. this.reactions.bookmarked = true;
  568. }
  569. }).catch(err => {
  570. swal('Error', 'Something went wrong, please try again later.', 'error');
  571. });
  572. },
  573. muteProfile() {
  574. if($('body').hasClass('loggedIn') == false) {
  575. return;
  576. }
  577. axios.post('/i/mute', {
  578. type: 'user',
  579. item: this.status.account.id
  580. }).then(res => {
  581. swal('Success', 'You have successfully muted ' + this.status.account.acct, 'success');
  582. }).catch(err => {
  583. swal('Error', 'Something went wrong. Please try again later.', 'error');
  584. });
  585. },
  586. blockProfile() {
  587. if($('body').hasClass('loggedIn') == false) {
  588. return;
  589. }
  590. axios.post('/i/block', {
  591. type: 'user',
  592. item: this.status.account.id
  593. }).then(res => {
  594. swal('Success', 'You have successfully blocked ' + this.status.account.acct, 'success');
  595. }).catch(err => {
  596. swal('Error', 'Something went wrong. Please try again later.', 'error');
  597. });
  598. },
  599. deletePost(status) {
  600. if(!this.ownerOrAdmin()) {
  601. return;
  602. }
  603. var result = confirm('Are you sure you want to delete this post?');
  604. if (result) {
  605. if($('body').hasClass('loggedIn') == false) {
  606. return;
  607. }
  608. axios.post('/i/delete', {
  609. type: 'status',
  610. item: this.status.id
  611. }).then(res => {
  612. swal('Success', 'You have successfully deleted this post', 'success');
  613. window.location.href = '/';
  614. }).catch(err => {
  615. swal('Error', 'Something went wrong. Please try again later.', 'error');
  616. });
  617. }
  618. },
  619. owner() {
  620. return this.user.id === this.status.account.id;
  621. },
  622. admin() {
  623. return this.user.is_admin == true;
  624. },
  625. ownerOrAdmin() {
  626. return this.owner() || this.admin();
  627. },
  628. lightbox(src) {
  629. this.lightboxMedia = src;
  630. this.$refs.lightboxModal.show();
  631. },
  632. postReply() {
  633. let self = this;
  634. if(this.replyText.length == 0 ||
  635. this.replyText.trim() == '@'+this.status.account.acct) {
  636. self.replyText = null;
  637. $('textarea[name="comment"]').blur();
  638. return;
  639. }
  640. let data = {
  641. item: this.replyingToId,
  642. comment: this.replyText
  643. }
  644. axios.post('/i/comment', data)
  645. .then(function(res) {
  646. let entity = res.data.entity;
  647. if(entity.in_reply_to_id == self.status.id) {
  648. self.results.push(entity);
  649. let elem = $('.status-comments')[0];
  650. elem.scrollTop = elem.clientHeight;
  651. } else {
  652. }
  653. self.replyText = '';
  654. });
  655. },
  656. deleteComment(id, i) {
  657. axios.post('/i/delete', {
  658. type: 'comment',
  659. item: id
  660. }).then(res => {
  661. this.results.splice(i, 1);
  662. }).catch(err => {
  663. swal('Something went wrong!', 'Please try again later', 'error');
  664. });
  665. },
  666. l(e) {
  667. let len = e.length;
  668. if(len < 10) { return e; }
  669. return e.substr(0, 10)+'...';
  670. },
  671. replyFocus(e) {
  672. this.replyingToId = e.id;
  673. this.reply_to_profile_id = e.account.id;
  674. this.replyText = '@' + e.account.username + ' ';
  675. $('textarea[name="comment"]').focus();
  676. },
  677. fetchComments() {
  678. let url = '/api/v2/comments/'+this.statusUsername+'/status/'+this.statusId;
  679. axios.get(url)
  680. .then(response => {
  681. let self = this;
  682. this.results = _.reverse(response.data.data);
  683. this.pagination = response.data.meta.pagination;
  684. if(this.results.length > 0) {
  685. $('.load-more-link').removeClass('d-none');
  686. }
  687. $('.postCommentsLoader').addClass('d-none');
  688. $('.postCommentsContainer').removeClass('d-none');
  689. }).catch(error => {
  690. if(!error.response) {
  691. $('.postCommentsLoader .lds-ring')
  692. .attr('style','width:100%')
  693. .addClass('pt-4 font-weight-bold text-muted')
  694. .text('An error occurred, cannot fetch comments. Please try again later.');
  695. } else {
  696. switch(error.response.status) {
  697. case 401:
  698. $('.postCommentsLoader .lds-ring')
  699. .attr('style','width:100%')
  700. .addClass('pt-4 font-weight-bold text-muted')
  701. .text('Please login to view.');
  702. break;
  703. default:
  704. $('.postCommentsLoader .lds-ring')
  705. .attr('style','width:100%')
  706. .addClass('pt-4 font-weight-bold text-muted')
  707. .text('An error occurred, cannot fetch comments. Please try again later.');
  708. break;
  709. }
  710. }
  711. });
  712. },
  713. loadMore(e) {
  714. e.preventDefault();
  715. if(this.pagination.total_pages == 1 || this.pagination.current_page == this.pagination.total_pages) {
  716. $('.load-more-link').addClass('d-none');
  717. return;
  718. }
  719. $('.postCommentsLoader').removeClass('d-none');
  720. let next = this.pagination.links.next;
  721. axios.get(next)
  722. .then(response => {
  723. let self = this;
  724. let res = response.data.data;
  725. $('.postCommentsLoader').addClass('d-none');
  726. for(let i=0; i < res.length; i++) {
  727. this.results.unshift(res[i]);
  728. }
  729. this.pagination = response.data.meta.pagination;
  730. });
  731. },
  732. likeReply(status, $event) {
  733. if($('body').hasClass('loggedIn') == false) {
  734. return;
  735. }
  736. axios.post('/i/like', {
  737. item: status.id
  738. }).then(res => {
  739. status.favourites_count = res.data.count;
  740. if(status.favourited == true) {
  741. status.favourited = false;
  742. } else {
  743. status.favourited = true;
  744. }
  745. }).catch(err => {
  746. swal('Error', 'Something went wrong, please try again later.', 'error');
  747. });
  748. },
  749. truncate(str,lim) {
  750. return _.truncate(str,{
  751. length: lim
  752. });
  753. },
  754. timeAgo(ts) {
  755. let date = Date.parse(ts);
  756. let seconds = Math.floor((new Date() - date) / 1000);
  757. let interval = Math.floor(seconds / 31536000);
  758. if (interval >= 1) {
  759. return interval + "y";
  760. }
  761. interval = Math.floor(seconds / 604800);
  762. if (interval >= 1) {
  763. return interval + "w";
  764. }
  765. interval = Math.floor(seconds / 86400);
  766. if (interval >= 1) {
  767. return interval + "d";
  768. }
  769. interval = Math.floor(seconds / 3600);
  770. if (interval >= 1) {
  771. return interval + "h";
  772. }
  773. interval = Math.floor(seconds / 60);
  774. if (interval >= 1) {
  775. return interval + "m";
  776. }
  777. return Math.floor(seconds) + "s";
  778. },
  779. emojiReaction() {
  780. let em = event.target.innerText;
  781. if(this.replyText.length == 0) {
  782. this.reply_to_profile_id = this.status.account.id;
  783. this.replyText = '@' + this.status.account.username + ' ' + em;
  784. $('textarea[name="comment"]').focus();
  785. } else {
  786. this.reply_to_profile_id = this.status.account.id;
  787. this.replyText += em;
  788. $('textarea[name="comment"]').focus();
  789. }
  790. },
  791. toggleCommentVisibility() {
  792. if(this.ownerOrAdmin() == false) {
  793. return;
  794. }
  795. let state = this.status.comments_disabled;
  796. let self = this;
  797. if(state == true) {
  798. // re-enable comments
  799. axios.post('/i/visibility', {
  800. item: self.status.id,
  801. disableComments: false
  802. }).then(function(res) {
  803. window.location.href = self.status.url;
  804. }).catch(function(err) {
  805. return;
  806. });
  807. } else {
  808. // disable comments
  809. axios.post('/i/visibility', {
  810. item: self.status.id,
  811. disableComments: true
  812. }).then(function(res) {
  813. self.status.comments_disabled = false;
  814. self.showComments = false;
  815. }).catch(function(err) {
  816. return;
  817. });
  818. }
  819. },
  820. fetchRelationships() {
  821. let loader = this.$loading.show({
  822. 'opacity': 0,
  823. 'background-color': '#f5f8fa'
  824. });
  825. if(document.querySelectorAll('body')[0].classList.contains('loggedIn') == false) {
  826. this.loaded = true;
  827. loader.hide();
  828. this.fetchData();
  829. return;
  830. } else {
  831. axios.get('/api/v1/accounts/relationships', {
  832. params: {
  833. 'id[]': this.statusProfileId
  834. }
  835. }).then(res => {
  836. if(res.data[0] == null) {
  837. this.loaded = true;
  838. loader.hide();
  839. this.fetchData();
  840. return;
  841. }
  842. this.relationship = res.data[0];
  843. if(res.data[0].blocking == true) {
  844. this.loaded = true;
  845. loader.hide();
  846. this.warning = true;
  847. return;
  848. } else {
  849. this.loaded = true;
  850. loader.hide();
  851. this.fetchData();
  852. return;
  853. }
  854. });
  855. }
  856. },
  857. visibilityModal() {
  858. switch(this.status.visibility) {
  859. case 'public':
  860. swal('Public Post', 'This post is visible to everyone.', 'info');
  861. break;
  862. case 'unlisted':
  863. swal('Unlisted Post', 'This post is visible on profiles and with a direct links. It is not displayed on timelines.', 'info');
  864. break;
  865. case 'private':
  866. swal('Private Post', 'This post is only visible to followers.', 'info');
  867. break;
  868. }
  869. },
  870. toggleReplies(reply) {
  871. if(reply.thread) {
  872. reply.thread = false;
  873. } else {
  874. if(reply.replies.length > 0) {
  875. reply.thread = true;
  876. return;
  877. }
  878. let url = '/api/v2/comments/'+reply.account.username+'/status/'+reply.id;
  879. axios.get(url)
  880. .then(response => {
  881. reply.replies = _.reverse(response.data.data);
  882. reply.thread = true;
  883. });
  884. }
  885. }
  886. },
  887. }
  888. </script>