1
0

PostComponent.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. <style>
  2. #l-modal .modal-body,
  3. #s-modal .modal-body {
  4. max-height: 70vh;
  5. overflow-y: scroll;
  6. }
  7. .status-comments,
  8. .reactions,
  9. .col-md-4 {
  10. background: #fff;
  11. }
  12. .postPresenterContainer {
  13. background: #fff;
  14. }
  15. @media(min-width: 720px) {
  16. .postPresenterContainer {
  17. min-height: 600px;
  18. }
  19. }
  20. </style>
  21. <template>
  22. <div class="postComponent d-none">
  23. <div class="container px-0 mt-md-4">
  24. <div class="card card-md-rounded-0 status-container orientation-unknown">
  25. <div class="row px-0 mx-0">
  26. <div class="d-flex d-md-none align-items-center justify-content-between card-header bg-white w-100">
  27. <a :href="statusProfileUrl" class="d-flex align-items-center status-username text-truncate" data-toggle="tooltip" data-placement="bottom" :title="statusUsername">
  28. <div class="status-avatar mr-2">
  29. <img :src="statusAvatar" width="24px" height="24px" style="border-radius:12px;">
  30. </div>
  31. <div class="username">
  32. <span class="username-link font-weight-bold text-dark">{{ statusUsername }}</span>
  33. </div>
  34. </a>
  35. <div class="float-right">
  36. <div class="post-actions">
  37. <div class="dropdown">
  38. <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">
  39. <span class="fas fa-ellipsis-v text-muted"></span>
  40. </button>
  41. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
  42. <span class="menu-user d-none">
  43. <a class="dropdown-item font-weight-bold" :href="reportUrl()">Report</a>
  44. <a class="dropdown-item font-weight-bold" v-on:click="muteProfile">Mute Profile</a>
  45. <a class="dropdown-item font-weight-bold" v-on:click="blockProfile">Block Profile</a>
  46. </span>
  47. <span class="menu-author d-none">
  48. <a class="dropdown-item font-weight-bold" :href="editUrl()">Edit</a>
  49. <a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost">Delete</a>
  50. </span>
  51. </div>
  52. </div>
  53. </div>
  54. </div>
  55. </div>
  56. <div class="col-12 col-md-8 px-0 mx-0">
  57. <div class="postPresenterLoader text-center">
  58. <div class="lds-ring"><div></div><div></div><div></div><div></div></div>
  59. </div>
  60. <div class="postPresenterContainer d-none d-flex justify-content-center align-items-center">
  61. <div v-if="status.pf_type === 'photo'" class="w-100">
  62. <photo-presenter :status="status"></photo-presenter>
  63. </div>
  64. <div v-else-if="status.pf_type === 'video'" class="w-100">
  65. <video-presenter :status="status"></video-presenter>
  66. </div>
  67. <div v-else-if="status.pf_type === 'photo:album'" class="w-100">
  68. <photo-album-presenter :status="status"></photo-album-presenter>
  69. </div>
  70. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  71. <video-album-presenter :status="status"></video-album-presenter>
  72. </div>
  73. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  74. <mixed-album-presenter :status="status"></mixed-album-presenter>
  75. </div>
  76. <div v-else class="w-100">
  77. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  78. </div>
  79. </div>
  80. </div>
  81. <div class="col-12 col-md-4 px-0 d-flex flex-column border-left border-md-left-0">
  82. <div class="d-md-flex d-none align-items-center justify-content-between card-header py-3 bg-white">
  83. <a :href="statusProfileUrl" class="d-flex align-items-center status-username text-truncate" data-toggle="tooltip" data-placement="bottom" :title="statusUsername">
  84. <div class="status-avatar mr-2">
  85. <img :src="statusAvatar" width="24px" height="24px" style="border-radius:12px;">
  86. </div>
  87. <div class="username">
  88. <span class="username-link font-weight-bold text-dark">{{ statusUsername }}</span>
  89. </div>
  90. </a>
  91. <div class="float-right">
  92. <div class="post-actions">
  93. <div class="dropdown">
  94. <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">
  95. <span class="fas fa-ellipsis-v text-muted"></span>
  96. </button>
  97. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
  98. <span class="menu-user d-none">
  99. <a class="dropdown-item font-weight-bold" :href="reportUrl()">Report</a>
  100. <a class="dropdown-item font-weight-bold" v-on:click="muteProfile">Mute Profile</a>
  101. <a class="dropdown-item font-weight-bold" v-on:click="blockProfile">Block Profile</a>
  102. </span>
  103. <span class="menu-author d-none">
  104. <a class="dropdown-item font-weight-bold" :href="editUrl()">Edit</a>
  105. <a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost">Delete</a>
  106. </span>
  107. </div>
  108. </div>
  109. </div>
  110. </div>
  111. </div>
  112. <div class="d-flex flex-md-column flex-column-reverse h-100">
  113. <div class="card-body status-comments">
  114. <div class="status-comment">
  115. <p class="mb-1 read-more" style="overflow: hidden;">
  116. <span class="font-weight-bold pr-1">{{statusUsername}}</span>
  117. <span class="comment-text" :id="status.id + '-status-readmore'" v-html="status.content"></span>
  118. </p>
  119. <post-comments :user="this.user" :post-id="statusId" :post-username="statusUsername"></post-comments>
  120. </div>
  121. </div>
  122. <div class="card-body flex-grow-0 py-1">
  123. <div class="reactions my-1">
  124. <h3 v-bind:class="[reactions.liked ? 'fas fa-heart text-danger pr-3 m-0' : 'far fa-heart pr-3 m-0 like-btn']" title="Like" v-on:click="likeStatus"></h3>
  125. <h3 class="far fa-comment pr-3 m-0" title="Comment" v-on:click="commentFocus"></h3>
  126. <h3 v-bind:class="[reactions.shared ? 'far fa-share-square pr-3 m-0 text-primary' : 'far fa-share-square pr-3 m-0 share-btn']" title="Share" v-on:click="shareStatus"></h3>
  127. <h3 v-bind:class="[reactions.bookmarked ? 'fas fa-bookmark text-warning m-0 float-right' : 'far fa-bookmark m-0 float-right']" title="Bookmark" v-on:click="bookmarkStatus"></h3>
  128. </div>
  129. <div class="reaction-counts font-weight-bold mb-0">
  130. <span style="cursor:pointer;" v-on:click="likesModal">
  131. <span class="like-count">{{status.favourites_count || 0}}</span> likes
  132. </span>
  133. <span class="float-right" style="cursor:pointer;" v-on:click="sharesModal">
  134. <span class="share-count pl-4">{{status.reblogs_count || 0}}</span> shares
  135. </span>
  136. </div>
  137. <div class="timestamp">
  138. <a v-bind:href="statusUrl" class="small text-muted">
  139. {{timestampFormat()}}
  140. </a>
  141. </div>
  142. </div>
  143. </div>
  144. <div class="card-footer bg-white sticky-md-bottom">
  145. <div class="comment-form-guest">
  146. <a href="/login">Login</a> to like or comment.
  147. </div>
  148. <form class="comment-form d-none" method="post" action="/i/comment" :data-id="statusId" data-truncate="false">
  149. <input type="hidden" name="_token" value="">
  150. <input type="hidden" name="item" :value="statusId">
  151. <input class="form-control" name="comment" placeholder="Add a comment..." autocomplete="off">
  152. <input type="submit" value="Send" class="btn btn-primary comment-submit" />
  153. </form>
  154. </div>
  155. </div>
  156. </div>
  157. </div>
  158. </div>
  159. <b-modal ref="likesModal"
  160. id="l-modal"
  161. hide-footer
  162. centered
  163. title="Likes"
  164. body-class="list-group-flush p-0">
  165. <div class="list-group">
  166. <div class="list-group-item border-0" v-for="user in likes">
  167. <div class="media">
  168. <a :href="user.url">
  169. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '\'s avatar'" width="30px">
  170. </a>
  171. <div class="media-body">
  172. <p class="mb-0" style="font-size: 14px">
  173. <a :href="user.url" class="font-weight-bold text-dark">
  174. {{user.username}}
  175. </a>
  176. </p>
  177. <p class="text-muted mb-0" style="font-size: 14px">
  178. {{user.display_name}}
  179. </a>
  180. </p>
  181. </div>
  182. </div>
  183. </div>
  184. <infinite-loading @infinite="infiniteLikesHandler" spinner="spiral">
  185. <div slot="no-more"></div>
  186. <div slot="no-results"></div>
  187. </infinite-loading>
  188. </div>
  189. </b-modal>
  190. <b-modal ref="sharesModal"
  191. id="s-modal"
  192. hide-footer
  193. centered
  194. title="Shares"
  195. body-class="list-group-flush p-0">
  196. <div class="list-group">
  197. <div class="list-group-item border-0" v-for="user in shares">
  198. <div class="media">
  199. <a :href="user.url">
  200. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '\'s avatar'" width="30px">
  201. </a>
  202. <div class="media-body">
  203. <p class="mb-0" style="font-size: 14px">
  204. <a :href="user.url" class="font-weight-bold text-dark">
  205. {{user.username}}
  206. </a>
  207. </p>
  208. <p class="text-muted mb-0" style="font-size: 14px">
  209. {{user.display_name}}
  210. </a>
  211. </p>
  212. </div>
  213. </div>
  214. </div>
  215. <infinite-loading @infinite="infiniteSharesHandler" spinner="spiral">
  216. <div slot="no-more"></div>
  217. <div slot="no-results"></div>
  218. </infinite-loading>
  219. </div>
  220. </b-modal>
  221. </div>
  222. </template>
  223. <script>
  224. pixelfed.postComponent = {};
  225. export default {
  226. props: ['status-id', 'status-username', 'status-template', 'status-url', 'status-profile-url', 'status-avatar'],
  227. data() {
  228. return {
  229. status: {},
  230. media: {},
  231. user: {},
  232. reactions: {
  233. liked: false,
  234. shared: false
  235. },
  236. likes: {},
  237. likesPage: 1,
  238. shares: {},
  239. sharesPage: 1,
  240. }
  241. },
  242. mounted() {
  243. this.fetchData();
  244. this.authCheck();
  245. let token = $('meta[name="csrf-token"]').attr('content');
  246. $('input[name="_token"]').each(function(k, v) {
  247. let el = $(v);
  248. el.val(token);
  249. });
  250. },
  251. updated() {
  252. $('.carousel').carousel();
  253. if(this.reactions) {
  254. if(this.reactions.bookmarked == true) {
  255. $('.far.fa-bookmark').removeClass('far').addClass('fas text-warning');
  256. }
  257. if(this.reactions.shared == true) {
  258. $('.far.fa-share-square').addClass('text-primary');
  259. }
  260. if(this.reactions.liked == true) {
  261. $('.far.fa-heart ').removeClass('far text-dark').addClass('fas text-danger');
  262. }
  263. }
  264. if(this.status) {
  265. let title = this.status.account.username + ' posted a photo: ' + this.status.favourites_count + ' likes';
  266. $('head title').text(title);
  267. }
  268. },
  269. methods: {
  270. authCheck() {
  271. let authed = $('body').hasClass('loggedIn');
  272. if(authed == true) {
  273. $('.comment-form-guest').addClass('d-none');
  274. $('.comment-form').removeClass('d-none');
  275. }
  276. },
  277. showMuteBlock() {
  278. let sid = this.status.account.id;
  279. let uid = this.user.id;
  280. if(sid == uid) {
  281. $('.post-actions .menu-author').removeClass('d-none');
  282. } else {
  283. $('.post-actions .menu-user').removeClass('d-none');
  284. }
  285. },
  286. reportUrl() {
  287. return '/i/report?type=post&id=' + this.status.id;
  288. },
  289. editUrl() {
  290. return this.status.url + '/edit';
  291. },
  292. timestampFormat() {
  293. let ts = new Date(this.status.created_at);
  294. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  295. },
  296. fetchData() {
  297. let loader = this.$loading.show({
  298. 'opacity': 0,
  299. 'background-color': '#f5f8fa'
  300. });
  301. axios.get('/api/v2/profile/'+this.statusUsername+'/status/'+this.statusId)
  302. .then(response => {
  303. let self = this;
  304. self.status = response.data.status;
  305. self.user = response.data.user;
  306. self.media = self.status.media_attachments;
  307. self.reactions = response.data.reactions;
  308. self.likes = response.data.likes;
  309. self.shares = response.data.shares;
  310. self.likesPage = 2;
  311. self.sharesPage = 2;
  312. //this.buildPresenter();
  313. this.showMuteBlock();
  314. loader.hide();
  315. pixelfed.readmore();
  316. $('.postComponent').removeClass('d-none');
  317. $('.postPresenterLoader').addClass('d-none');
  318. $('.postPresenterContainer').removeClass('d-none');
  319. }).catch(error => {
  320. if(!error.response) {
  321. $('.postPresenterLoader .lds-ring').attr('style','width:100%').addClass('pt-4 font-weight-bold text-muted').text('An error occured, cannot fetch media. Please try again later.');
  322. } else {
  323. switch(error.response.status) {
  324. case 401:
  325. $('.postPresenterLoader .lds-ring')
  326. .attr('style','width:100%')
  327. .addClass('pt-4 font-weight-bold text-muted')
  328. .text('Please login to view.');
  329. break;
  330. default:
  331. $('.postPresenterLoader .lds-ring').attr('style','width:100%').addClass('pt-4 font-weight-bold text-muted').text('An error occured, cannot fetch media. Please try again later.');
  332. break;
  333. }
  334. }
  335. });
  336. },
  337. commentFocus() {
  338. $('.comment-form input[name="comment"]').focus();
  339. },
  340. likesModal() {
  341. if(this.status.favourites_count == 0 || $('body').hasClass('loggedIn') == false) {
  342. return;
  343. }
  344. this.$refs.likesModal.show();
  345. },
  346. sharesModal() {
  347. if(this.status.reblogs_count == 0 || $('body').hasClass('loggedIn') == false) {
  348. return;
  349. }
  350. this.$refs.sharesModal.show();
  351. },
  352. infiniteLikesHandler($state) {
  353. let api = '/api/v2/likes/profile/'+this.statusUsername+'/status/'+this.statusId;
  354. axios.get(api, {
  355. params: {
  356. page: this.likesPage,
  357. },
  358. }).then(({ data }) => {
  359. if (data.data.length) {
  360. this.likesPage += 1;
  361. this.likes.push(...data.data);
  362. $state.loaded();
  363. } else {
  364. $state.complete();
  365. }
  366. });
  367. },
  368. infiniteSharesHandler($state) {
  369. axios.get('/api/v2/shares/profile/'+this.statusUsername+'/status/'+this.statusId, {
  370. params: {
  371. page: this.sharesPage,
  372. },
  373. }).then(({ data }) => {
  374. if (data.data.length) {
  375. this.sharesPage += 1;
  376. this.shares.push(...data.data);
  377. $state.loaded();
  378. } else {
  379. $state.complete();
  380. }
  381. });
  382. },
  383. likeStatus(event) {
  384. if($('body').hasClass('loggedIn') == false) {
  385. return;
  386. }
  387. axios.post('/i/like', {
  388. item: this.status.id
  389. }).then(res => {
  390. this.status.favourites_count = res.data.count;
  391. if(this.reactions.liked == true) {
  392. this.reactions.liked = false;
  393. } else {
  394. this.reactions.liked = true;
  395. }
  396. }).catch(err => {
  397. swal('Error', 'Something went wrong, please try again later.', 'error');
  398. });
  399. },
  400. shareStatus() {
  401. if($('body').hasClass('loggedIn') == false) {
  402. return;
  403. }
  404. axios.post('/i/share', {
  405. item: this.status.id
  406. }).then(res => {
  407. this.status.reblogs_count = res.data.count;
  408. if(this.reactions.shared == true) {
  409. this.reactions.shared = false;
  410. } else {
  411. this.reactions.shared = true;
  412. }
  413. }).catch(err => {
  414. swal('Error', 'Something went wrong, please try again later.', 'error');
  415. });
  416. },
  417. bookmarkStatus() {
  418. if($('body').hasClass('loggedIn') == false) {
  419. return;
  420. }
  421. axios.post('/i/bookmark', {
  422. item: this.status.id
  423. }).then(res => {
  424. if(this.reactions.bookmarked == true) {
  425. this.reactions.bookmarked = false;
  426. } else {
  427. this.reactions.bookmarked = true;
  428. }
  429. }).catch(err => {
  430. swal('Error', 'Something went wrong, please try again later.', 'error');
  431. });
  432. },
  433. muteProfile() {
  434. if($('body').hasClass('loggedIn') == false) {
  435. return;
  436. }
  437. axios.post('/i/mute', {
  438. type: 'user',
  439. item: this.status.account.id
  440. }).then(res => {
  441. swal('Success', 'You have successfully muted ' + this.status.account.acct, 'success');
  442. }).catch(err => {
  443. swal('Error', 'Something went wrong. Please try again later.', 'error');
  444. });
  445. },
  446. blockProfile() {
  447. if($('body').hasClass('loggedIn') == false) {
  448. return;
  449. }
  450. axios.post('/i/block', {
  451. type: 'user',
  452. item: this.status.account.id
  453. }).then(res => {
  454. swal('Success', 'You have successfully blocked ' + this.status.account.acct, 'success');
  455. }).catch(err => {
  456. swal('Error', 'Something went wrong. Please try again later.', 'error');
  457. });
  458. },
  459. deletePost() {
  460. if($('body').hasClass('loggedIn') == false) {
  461. return;
  462. }
  463. axios.post('/i/delete', {
  464. type: 'status',
  465. item: this.status.id
  466. }).then(res => {
  467. swal('Success', 'You have successfully deleted this post', 'success');
  468. }).catch(err => {
  469. swal('Error', 'Something went wrong. Please try again later.', 'error');
  470. });
  471. }
  472. }
  473. }
  474. </script>