PostComponent.vue 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  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 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>
  134. </div>
  135. </div>
  136. </div>
  137. </div>
  138. </div>
  139. <div class="card-body flex-grow-0 py-1">
  140. <div class="reactions my-1">
  141. <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>
  142. <h3 v-if="!status.comments_disabled" class="far fa-comment pr-3 m-0 cursor-pointer" title="Comment" v-on:click="replyFocus(status)"></h3>
  143. <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>
  144. <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>
  145. </div>
  146. <div class="reaction-counts font-weight-bold mb-0">
  147. <span style="cursor:pointer;" v-on:click="likesModal">
  148. <span class="like-count">{{status.favourites_count || 0}}</span> likes
  149. </span>
  150. <span class="float-right" style="cursor:pointer;" v-on:click="sharesModal">
  151. <span class="share-count pl-4">{{status.reblogs_count || 0}}</span> shares
  152. </span>
  153. </div>
  154. <div class="timestamp">
  155. <a v-bind:href="statusUrl" class="small text-muted">
  156. {{timestampFormat()}}
  157. </a>
  158. </div>
  159. </div>
  160. </div>
  161. <div v-if="showComments && user.length !== 0" class="card-footer bg-white px-2 py-0">
  162. <ul class="nav align-items-center emoji-reactions" style="overflow-x: scroll;flex-wrap: unset;">
  163. <li class="nav-item" v-on:click="emojiReaction">😂</li>
  164. <li class="nav-item" v-on:click="emojiReaction">💯</li>
  165. <li class="nav-item" v-on:click="emojiReaction">❤️</li>
  166. <li class="nav-item" v-on:click="emojiReaction">🙌</li>
  167. <li class="nav-item" v-on:click="emojiReaction">👏</li>
  168. <li class="nav-item" v-on:click="emojiReaction">😍</li>
  169. <li class="nav-item" v-on:click="emojiReaction">😯</li>
  170. <li class="nav-item" v-on:click="emojiReaction">😢</li>
  171. <li class="nav-item" v-on:click="emojiReaction">😅</li>
  172. <li class="nav-item" v-on:click="emojiReaction">😁</li>
  173. <li class="nav-item" v-on:click="emojiReaction">🙂</li>
  174. <li class="nav-item" v-on:click="emojiReaction">😎</li>
  175. </ul>
  176. </div>
  177. <div v-if="showComments" class="card-footer bg-white sticky-md-bottom p-0">
  178. <div v-if="user.length == 0" class="comment-form-guest p-3">
  179. <a href="/login">Login</a> to like or comment.
  180. </div>
  181. <form v-else class="border-0 rounded-0 align-middle" method="post" action="/i/comment" :data-id="statusId" data-truncate="false">
  182. <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>
  183. <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"/>
  184. </form>
  185. </div>
  186. </div>
  187. </div>
  188. </div>
  189. </div>
  190. </div>
  191. <b-modal ref="likesModal"
  192. id="l-modal"
  193. hide-footer
  194. centered
  195. title="Likes"
  196. body-class="list-group-flush p-0">
  197. <div class="list-group">
  198. <div class="list-group-item border-0" v-for="(user, index) in likes" :key="'modal_likes_'+index">
  199. <div class="media">
  200. <a :href="user.url">
  201. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  202. </a>
  203. <div class="media-body">
  204. <p class="mb-0" style="font-size: 14px">
  205. <a :href="user.url" class="font-weight-bold text-dark">
  206. {{user.username}}
  207. </a>
  208. </p>
  209. <p class="text-muted mb-0" style="font-size: 14px">
  210. {{user.display_name}}
  211. </a>
  212. </p>
  213. </div>
  214. </div>
  215. </div>
  216. <infinite-loading @infinite="infiniteLikesHandler" spinner="spiral">
  217. <div slot="no-more"></div>
  218. <div slot="no-results"></div>
  219. </infinite-loading>
  220. </div>
  221. </b-modal>
  222. <b-modal ref="sharesModal"
  223. id="s-modal"
  224. hide-footer
  225. centered
  226. title="Shares"
  227. body-class="list-group-flush p-0">
  228. <div class="list-group">
  229. <div class="list-group-item border-0" v-for="(user, index) in shares" :key="'modal_shares_'+index">
  230. <div class="media">
  231. <a :href="user.url">
  232. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  233. </a>
  234. <div class="media-body">
  235. <div class="d-inline-block">
  236. <p class="mb-0" style="font-size: 14px">
  237. <a :href="user.url" class="font-weight-bold text-dark">
  238. {{user.username}}
  239. </a>
  240. </p>
  241. <p class="text-muted mb-0" style="font-size: 14px">
  242. {{user.display_name}}
  243. </a>
  244. </p>
  245. </div>
  246. <p class="float-right"><!-- <a class="btn btn-primary font-weight-bold py-1" href="#">Follow</a> --></p>
  247. </div>
  248. </div>
  249. </div>
  250. <infinite-loading @infinite="infiniteSharesHandler" spinner="spiral">
  251. <div slot="no-more"></div>
  252. <div slot="no-results"></div>
  253. </infinite-loading>
  254. </div>
  255. </b-modal>
  256. <b-modal
  257. id="lightbox"
  258. ref="lightboxModal"
  259. :hide-header="true"
  260. :hide-footer="true"
  261. centered
  262. size="lg"
  263. body-class="p-0"
  264. >
  265. <div v-if="lightboxMedia" :class="lightboxMedia.filter_class">
  266. <img :src="lightboxMedia.url" class="img-fluid" style="min-height: 100%; min-width: 100%">
  267. </div>
  268. </b-modal>
  269. </div>
  270. </template>
  271. <style type="text/css" scoped>
  272. .status-comments,
  273. .reactions,
  274. .col-md-4 {
  275. background: #fff;
  276. }
  277. .postPresenterContainer {
  278. background: #fff;
  279. }
  280. @media(min-width: 720px) {
  281. .postPresenterContainer {
  282. min-height: 600px;
  283. }
  284. }
  285. ::-webkit-scrollbar {
  286. width: 0px;
  287. background: transparent;
  288. }
  289. .reply-btn {
  290. position: absolute;
  291. bottom: 12px;
  292. right: 20px;
  293. width: 60px;
  294. text-align: center;
  295. border-radius: 0 3px 3px 0;
  296. }
  297. .text-lighter {
  298. color:#B8C2CC !important;
  299. }
  300. .text-break {
  301. overflow-wrap: break-word;
  302. }
  303. .comments p {
  304. margin-bottom: 0;
  305. }
  306. .comment-reaction {
  307. font-size: 80%;
  308. }
  309. .show-reply-bar {
  310. display: inline-block;
  311. border-bottom: 1px solid #999;
  312. height: 0;
  313. margin-right: 16px;
  314. vertical-align: middle;
  315. width: 24px;
  316. }
  317. .comment-thread {
  318. margin: 4px 0 0 40px;
  319. width: calc(100% - 40px);
  320. }
  321. .emoji-reactions .nav-item {
  322. font-size: 1.2rem;
  323. padding: 7px;
  324. cursor: pointer;
  325. }
  326. .emoji-reactions::-webkit-scrollbar {
  327. width: 0px;
  328. height: 0px;
  329. background: transparent;
  330. }
  331. </style>
  332. <script>
  333. pixelfed.postComponent = {};
  334. export default {
  335. props: ['status-id', 'status-username', 'status-template', 'status-url', 'status-profile-url', 'status-avatar', 'status-profile-id'],
  336. data() {
  337. return {
  338. status: false,
  339. media: {},
  340. user: false,
  341. reactions: {
  342. liked: false,
  343. shared: false
  344. },
  345. likes: [],
  346. likesPage: 1,
  347. shares: [],
  348. sharesPage: 1,
  349. lightboxMedia: false,
  350. replyText: '',
  351. relationship: {},
  352. results: [],
  353. pagination: {},
  354. min_id: 0,
  355. max_id: 0,
  356. reply_to_profile_id: 0,
  357. thread: false,
  358. showComments: false,
  359. warning: false,
  360. loaded: false,
  361. loading: null
  362. }
  363. },
  364. mounted() {
  365. this.fetchRelationships();
  366. let token = $('meta[name="csrf-token"]').attr('content');
  367. $('input[name="_token"]').each(function(k, v) {
  368. let el = $(v);
  369. el.val(token);
  370. });
  371. },
  372. updated() {
  373. $('.carousel').carousel();
  374. pixelfed.readmore();
  375. if(this.reactions) {
  376. if(this.reactions.bookmarked == true) {
  377. $('.postComponent .far.fa-bookmark').removeClass('far').addClass('fas text-warning');
  378. }
  379. if(this.reactions.shared == true) {
  380. $('.postComponent .far.fa-share-square').addClass('text-primary');
  381. }
  382. if(this.reactions.liked == true) {
  383. $('.postComponent .far.fa-heart').removeClass('far text-dark').addClass('fas text-danger');
  384. }
  385. }
  386. },
  387. methods: {
  388. showMuteBlock() {
  389. let sid = this.status.account.id;
  390. let uid = this.user.id;
  391. if(sid == uid) {
  392. $('.post-actions .menu-author').removeClass('d-none');
  393. } else {
  394. $('.post-actions .menu-user').removeClass('d-none');
  395. }
  396. },
  397. reportUrl() {
  398. return '/i/report?type=post&id=' + this.status.id;
  399. },
  400. editUrl() {
  401. return this.status.url + '/edit';
  402. },
  403. timestampFormat() {
  404. let ts = new Date(this.status.created_at);
  405. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  406. },
  407. fetchData() {
  408. axios.get('/api/v2/profile/'+this.statusUsername+'/status/'+this.statusId)
  409. .then(response => {
  410. let self = this;
  411. self.status = response.data.status;
  412. self.user = response.data.user;
  413. self.media = self.status.media_attachments;
  414. self.reactions = response.data.reactions;
  415. self.likes = response.data.likes;
  416. self.shares = response.data.shares;
  417. self.likesPage = 2;
  418. self.sharesPage = 2;
  419. //this.buildPresenter();
  420. this.showMuteBlock();
  421. pixelfed.readmore();
  422. if(self.status.comments_disabled == false) {
  423. self.showComments = true;
  424. this.fetchComments();
  425. }
  426. $('.postComponent').removeClass('d-none');
  427. $('.postPresenterLoader').addClass('d-none');
  428. $('.postPresenterContainer').removeClass('d-none');
  429. $('head title').text(this.status.account.username + ' posted a photo: ' + this.status.favourites_count + ' likes');
  430. }).catch(error => {
  431. if(!error.response) {
  432. $('.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.');
  433. } else {
  434. switch(error.response.status) {
  435. case 401:
  436. $('.postPresenterLoader .lds-ring')
  437. .attr('style','width:100%')
  438. .addClass('pt-4 font-weight-bold text-muted')
  439. .text('Please login to view.');
  440. break;
  441. default:
  442. $('.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.');
  443. break;
  444. }
  445. }
  446. });
  447. },
  448. likesModal() {
  449. if(this.status.favourites_count == 0 || $('body').hasClass('loggedIn') == false) {
  450. return;
  451. }
  452. this.$refs.likesModal.show();
  453. },
  454. sharesModal() {
  455. if(this.status.reblogs_count == 0 || $('body').hasClass('loggedIn') == false) {
  456. return;
  457. }
  458. this.$refs.sharesModal.show();
  459. },
  460. infiniteLikesHandler($state) {
  461. let api = '/api/v2/likes/profile/'+this.statusUsername+'/status/'+this.statusId;
  462. axios.get(api, {
  463. params: {
  464. page: this.likesPage,
  465. },
  466. }).then(({ data }) => {
  467. if (data.data.length > 0) {
  468. this.likes.push(...data.data);
  469. this.likesPage++;
  470. $state.loaded();
  471. } else {
  472. $state.complete();
  473. }
  474. });
  475. },
  476. infiniteSharesHandler($state) {
  477. axios.get('/api/v2/shares/profile/'+this.statusUsername+'/status/'+this.statusId, {
  478. params: {
  479. page: this.sharesPage,
  480. },
  481. }).then(({ data }) => {
  482. if (data.data.length > 0) {
  483. this.shares.push(...data.data);
  484. this.sharesPage++;
  485. $state.loaded();
  486. } else {
  487. $state.complete();
  488. }
  489. });
  490. },
  491. likeStatus(event) {
  492. if($('body').hasClass('loggedIn') == false) {
  493. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  494. return;
  495. }
  496. axios.post('/i/like', {
  497. item: this.status.id
  498. }).then(res => {
  499. this.status.favourites_count = res.data.count;
  500. if(this.reactions.liked == true) {
  501. this.reactions.liked = false;
  502. let user = this.user.id;
  503. this.likes = this.likes.filter(function(like) {
  504. return like.id !== user;
  505. });
  506. } else {
  507. this.reactions.liked = true;
  508. let user = this.user;
  509. this.likes.push(user);
  510. }
  511. }).catch(err => {
  512. console.error(err);
  513. swal('Error', 'Something went wrong, please try again later.', 'error');
  514. });
  515. },
  516. shareStatus() {
  517. if($('body').hasClass('loggedIn') == false) {
  518. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  519. return;
  520. }
  521. axios.post('/i/share', {
  522. item: this.status.id
  523. }).then(res => {
  524. this.status.reblogs_count = res.data.count;
  525. if(this.reactions.shared == true) {
  526. this.reactions.shared = false;
  527. let user = this.user.id;
  528. this.shares = this.shares.filter(function(reaction) {
  529. return reaction.id !== user;
  530. });
  531. } else {
  532. this.reactions.shared = true;
  533. let user = this.user;
  534. this.shares.push(user);
  535. }
  536. }).catch(err => {
  537. console.error(err);
  538. swal('Error', 'Something went wrong, please try again later.', 'error');
  539. });
  540. },
  541. bookmarkStatus() {
  542. if($('body').hasClass('loggedIn') == false) {
  543. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  544. return;
  545. }
  546. axios.post('/i/bookmark', {
  547. item: this.status.id
  548. }).then(res => {
  549. if(this.reactions.bookmarked == true) {
  550. this.reactions.bookmarked = false;
  551. } else {
  552. this.reactions.bookmarked = true;
  553. }
  554. }).catch(err => {
  555. swal('Error', 'Something went wrong, please try again later.', 'error');
  556. });
  557. },
  558. muteProfile() {
  559. if($('body').hasClass('loggedIn') == false) {
  560. return;
  561. }
  562. axios.post('/i/mute', {
  563. type: 'user',
  564. item: this.status.account.id
  565. }).then(res => {
  566. swal('Success', 'You have successfully muted ' + this.status.account.acct, 'success');
  567. }).catch(err => {
  568. swal('Error', 'Something went wrong. Please try again later.', 'error');
  569. });
  570. },
  571. blockProfile() {
  572. if($('body').hasClass('loggedIn') == false) {
  573. return;
  574. }
  575. axios.post('/i/block', {
  576. type: 'user',
  577. item: this.status.account.id
  578. }).then(res => {
  579. swal('Success', 'You have successfully blocked ' + this.status.account.acct, 'success');
  580. }).catch(err => {
  581. swal('Error', 'Something went wrong. Please try again later.', 'error');
  582. });
  583. },
  584. deletePost(status) {
  585. if(!this.ownerOrAdmin()) {
  586. return;
  587. }
  588. var result = confirm('Are you sure you want to delete this post?');
  589. if (result) {
  590. if($('body').hasClass('loggedIn') == false) {
  591. return;
  592. }
  593. axios.post('/i/delete', {
  594. type: 'status',
  595. item: this.status.id
  596. }).then(res => {
  597. swal('Success', 'You have successfully deleted this post', 'success');
  598. window.location.href = '/';
  599. }).catch(err => {
  600. swal('Error', 'Something went wrong. Please try again later.', 'error');
  601. });
  602. }
  603. },
  604. owner() {
  605. return this.user.id === this.status.account.id;
  606. },
  607. admin() {
  608. return this.user.is_admin == true;
  609. },
  610. ownerOrAdmin() {
  611. return this.owner() || this.admin();
  612. },
  613. lightbox(src) {
  614. this.lightboxMedia = src;
  615. this.$refs.lightboxModal.show();
  616. },
  617. postReply() {
  618. let self = this;
  619. if(this.replyText.length == 0 ||
  620. this.replyText.trim() == '@'+this.status.account.acct) {
  621. self.replyText = null;
  622. $('textarea[name="comment"]').blur();
  623. return;
  624. }
  625. let data = {
  626. item: this.statusId,
  627. comment: this.replyText
  628. }
  629. axios.post('/i/comment', data)
  630. .then(function(res) {
  631. let entity = res.data.entity;
  632. self.results.push(entity);
  633. self.replyText = '';
  634. let elem = $('.status-comments')[0];
  635. elem.scrollTop = elem.clientHeight;
  636. });
  637. },
  638. deleteComment(id, i) {
  639. axios.post('/i/delete', {
  640. type: 'comment',
  641. item: id
  642. }).then(res => {
  643. this.results.splice(i, 1);
  644. }).catch(err => {
  645. swal('Something went wrong!', 'Please try again later', 'error');
  646. });
  647. },
  648. l(e) {
  649. let len = e.length;
  650. if(len < 10) { return e; }
  651. return e.substr(0, 10)+'...';
  652. },
  653. replyFocus(e) {
  654. this.reply_to_profile_id = e.account.id;
  655. this.replyText = '@' + e.account.username + ' ';
  656. $('textarea[name="comment"]').focus();
  657. },
  658. fetchComments() {
  659. let url = '/api/v2/comments/'+this.statusUsername+'/status/'+this.statusId;
  660. axios.get(url)
  661. .then(response => {
  662. let self = this;
  663. this.results = _.reverse(response.data.data);
  664. this.pagination = response.data.meta.pagination;
  665. if(this.results.length > 0) {
  666. $('.load-more-link').removeClass('d-none');
  667. }
  668. $('.postCommentsLoader').addClass('d-none');
  669. $('.postCommentsContainer').removeClass('d-none');
  670. }).catch(error => {
  671. if(!error.response) {
  672. $('.postCommentsLoader .lds-ring')
  673. .attr('style','width:100%')
  674. .addClass('pt-4 font-weight-bold text-muted')
  675. .text('An error occurred, cannot fetch comments. Please try again later.');
  676. } else {
  677. switch(error.response.status) {
  678. case 401:
  679. $('.postCommentsLoader .lds-ring')
  680. .attr('style','width:100%')
  681. .addClass('pt-4 font-weight-bold text-muted')
  682. .text('Please login to view.');
  683. break;
  684. default:
  685. $('.postCommentsLoader .lds-ring')
  686. .attr('style','width:100%')
  687. .addClass('pt-4 font-weight-bold text-muted')
  688. .text('An error occurred, cannot fetch comments. Please try again later.');
  689. break;
  690. }
  691. }
  692. });
  693. },
  694. loadMore(e) {
  695. e.preventDefault();
  696. if(this.pagination.total_pages == 1 || this.pagination.current_page == this.pagination.total_pages) {
  697. $('.load-more-link').addClass('d-none');
  698. return;
  699. }
  700. $('.postCommentsLoader').removeClass('d-none');
  701. let next = this.pagination.links.next;
  702. axios.get(next)
  703. .then(response => {
  704. let self = this;
  705. let res = response.data.data;
  706. $('.postCommentsLoader').addClass('d-none');
  707. for(let i=0; i < res.length; i++) {
  708. this.results.unshift(res[i]);
  709. }
  710. this.pagination = response.data.meta.pagination;
  711. });
  712. },
  713. likeReply(status, $event) {
  714. if($('body').hasClass('loggedIn') == false) {
  715. return;
  716. }
  717. axios.post('/i/like', {
  718. item: status.id
  719. }).then(res => {
  720. status.favourites_count = res.data.count;
  721. if(status.favourited == true) {
  722. status.favourited = false;
  723. } else {
  724. status.favourited = true;
  725. }
  726. }).catch(err => {
  727. swal('Error', 'Something went wrong, please try again later.', 'error');
  728. });
  729. },
  730. truncate(str,lim) {
  731. return _.truncate(str,{
  732. length: lim
  733. });
  734. },
  735. timeAgo(ts) {
  736. let date = Date.parse(ts);
  737. let seconds = Math.floor((new Date() - date) / 1000);
  738. let interval = Math.floor(seconds / 31536000);
  739. if (interval >= 1) {
  740. return interval + "y";
  741. }
  742. interval = Math.floor(seconds / 604800);
  743. if (interval >= 1) {
  744. return interval + "w";
  745. }
  746. interval = Math.floor(seconds / 86400);
  747. if (interval >= 1) {
  748. return interval + "d";
  749. }
  750. interval = Math.floor(seconds / 3600);
  751. if (interval >= 1) {
  752. return interval + "h";
  753. }
  754. interval = Math.floor(seconds / 60);
  755. if (interval >= 1) {
  756. return interval + "m";
  757. }
  758. return Math.floor(seconds) + "s";
  759. },
  760. emojiReaction() {
  761. let em = event.target.innerText;
  762. if(this.replyText.length == 0) {
  763. this.reply_to_profile_id = this.status.account.id;
  764. this.replyText = '@' + this.status.account.username + ' ' + em;
  765. $('textarea[name="comment"]').focus();
  766. } else {
  767. this.reply_to_profile_id = this.status.account.id;
  768. this.replyText += em;
  769. $('textarea[name="comment"]').focus();
  770. }
  771. },
  772. toggleCommentVisibility() {
  773. if(this.ownerOrAdmin() == false) {
  774. return;
  775. }
  776. let state = this.status.comments_disabled;
  777. let self = this;
  778. if(state == true) {
  779. // re-enable comments
  780. axios.post('/i/visibility', {
  781. item: self.status.id,
  782. disableComments: false
  783. }).then(function(res) {
  784. window.location.href = self.status.url;
  785. }).catch(function(err) {
  786. return;
  787. });
  788. } else {
  789. // disable comments
  790. axios.post('/i/visibility', {
  791. item: self.status.id,
  792. disableComments: true
  793. }).then(function(res) {
  794. self.status.comments_disabled = false;
  795. self.showComments = false;
  796. }).catch(function(err) {
  797. return;
  798. });
  799. }
  800. },
  801. fetchRelationships() {
  802. let loader = this.$loading.show({
  803. 'opacity': 0,
  804. 'background-color': '#f5f8fa'
  805. });
  806. if(document.querySelectorAll('body')[0].classList.contains('loggedIn') == false) {
  807. this.loaded = true;
  808. loader.hide();
  809. this.fetchData();
  810. return;
  811. } else {
  812. axios.get('/api/v1/accounts/relationships', {
  813. params: {
  814. 'id[]': this.statusProfileId
  815. }
  816. }).then(res => {
  817. if(res.data[0] == null) {
  818. this.loaded = true;
  819. loader.hide();
  820. this.fetchData();
  821. return;
  822. }
  823. this.relationship = res.data[0];
  824. if(res.data[0].blocking == true) {
  825. this.loaded = true;
  826. loader.hide();
  827. this.warning = true;
  828. return;
  829. } else {
  830. this.loaded = true;
  831. loader.hide();
  832. this.fetchData();
  833. return;
  834. }
  835. });
  836. }
  837. },
  838. },
  839. }
  840. </script>