1
0

Post.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <template>
  2. <div class="post-timeline-component web-wrapper">
  3. <div v-if="isLoaded" class="container-fluid mt-3">
  4. <div class="row">
  5. <div class="col-md-4 col-lg-3 d-md-block">
  6. <sidebar :user="user" />
  7. </div>
  8. <div class="col-md-8 col-lg-6">
  9. <div v-if="isReply" class="p-3 rounded-top mb-n3" style="background-color: var(--card-header-accent)">
  10. <p>
  11. <i class="fal fa-reply mr-1"></i> In reply to
  12. <a
  13. :href="'/i/web/profile/' + reply.account.id"
  14. class="font-weight-bold primary"
  15. @click.prevent="goToProfile(reply.account)">
  16. &commat;{{ reply.account.acct }}
  17. </a>
  18. <button
  19. @click.prevent="goToPost(reply)"
  20. class="btn btn-primary font-weight-bold btn-sm px-3 float-right rounded-pill">
  21. View Post
  22. </button>
  23. </p>
  24. </div>
  25. <status
  26. :key="post.id + ':fui:' + forceUpdateIdx"
  27. :status="post"
  28. :profile="user"
  29. v-on:menu="openContextMenu()"
  30. v-on:like="likeStatus()"
  31. v-on:unlike="unlikeStatus()"
  32. v-on:likes-modal="openLikesModal()"
  33. v-on:shares-modal="openSharesModal()"
  34. v-on:bookmark="handleBookmark()"
  35. v-on:share="shareStatus()"
  36. v-on:unshare="unshareStatus()"
  37. v-on:follow="follow()"
  38. v-on:unfollow="unfollow()"
  39. v-on:counter-change="counterChange"
  40. />
  41. </div>
  42. <div class="d-none d-lg-block col-lg-3">
  43. <rightbar />
  44. </div>
  45. </div>
  46. </div>
  47. <div v-if="postStateError" class="container-fluid mt-3">
  48. <div class="row">
  49. <div class="col-md-4 col-lg-3 d-md-block">
  50. <sidebar :user="user" />
  51. </div>
  52. <div class="col-md-8 col-lg-6">
  53. <div class="card card-body shadow-none border">
  54. <div class="d-flex align-self-center flex-column" style="max-width: 500px;">
  55. <p class="text-center">
  56. <i class="far fa-exclamation-triangle fa-3x text-lighter"></i>
  57. </p>
  58. <p class="text-center lead font-weight-bold">Error displaying post</p>
  59. <p class="mb-0">This can happen for a few reasons:</p>
  60. <ul class="text-lighter">
  61. <li>The url is invalid or has a typo</li>
  62. <li>The page has been flagged for review by our automated abuse detection systems</li>
  63. <li>The content may have been deleted</li>
  64. <li>You do not have permission to view this content</li>
  65. </ul>
  66. </div>
  67. </div>
  68. </div>
  69. <div class="d-none d-lg-block col-lg-3">
  70. <rightbar />
  71. </div>
  72. </div>
  73. </div>
  74. <context-menu
  75. v-if="isLoaded"
  76. ref="contextMenu"
  77. :status="post"
  78. :profile="user"
  79. @report-modal="handleReport()"
  80. @delete="deletePost()"
  81. @pinned="handlePinned()"
  82. @unpinned="handleUnpinned()"
  83. v-on:edit="handleEdit"
  84. />
  85. <likes-modal
  86. v-if="showLikesModal"
  87. ref="likesModal"
  88. :status="post"
  89. :profile="user"
  90. />
  91. <shares-modal
  92. v-if="showSharesModal"
  93. ref="sharesModal"
  94. :status="post"
  95. :profile="profile"
  96. />
  97. <report-modal
  98. v-if="post"
  99. ref="reportModal"
  100. :status="post"
  101. />
  102. <post-edit-modal
  103. ref="editModal"
  104. v-on:update="mergeUpdatedPost"
  105. />
  106. <drawer />
  107. </div>
  108. </template>
  109. <script type="text/javascript">
  110. import Drawer from './partials/drawer.vue';
  111. import Rightbar from './partials/rightbar.vue';
  112. import Sidebar from './partials/sidebar.vue';
  113. import Status from './partials/TimelineStatus.vue';
  114. import ContextMenu from './partials/post/ContextMenu.vue';
  115. import MediaContainer from './partials/post/MediaContainer.vue';
  116. import LikesModal from './partials/post/LikeModal.vue';
  117. import SharesModal from './partials/post/ShareModal.vue';
  118. import ReportModal from './partials/modal/ReportPost.vue';
  119. import PostEditModal from './partials/post/PostEditModal.vue';
  120. export default {
  121. props: {
  122. cachedStatus: {
  123. type: Object
  124. },
  125. cachedProfile: {
  126. type: Object
  127. }
  128. },
  129. components: {
  130. "drawer": Drawer,
  131. "sidebar": Sidebar,
  132. "status": Status,
  133. "context-menu": ContextMenu,
  134. "media-container": MediaContainer,
  135. "likes-modal": LikesModal,
  136. "shares-modal": SharesModal,
  137. "rightbar": Rightbar,
  138. "report-modal": ReportModal,
  139. "post-edit-modal": PostEditModal
  140. },
  141. data() {
  142. return {
  143. isLoaded: false,
  144. user: undefined,
  145. profile: undefined,
  146. post: undefined,
  147. relationship: {},
  148. media: undefined,
  149. mediaIndex: 0,
  150. showLikesModal: false,
  151. isReply: false,
  152. reply: {},
  153. showSharesModal: false,
  154. postStateError: false,
  155. forceUpdateIdx: 0
  156. }
  157. },
  158. created() {
  159. this.init();
  160. },
  161. watch: {
  162. '$route': 'init'
  163. },
  164. methods: {
  165. init() {
  166. this.fetchSelf();
  167. },
  168. fetchSelf() {
  169. this.user = window._sharedData.user;
  170. this.isReply = false;
  171. this.fetchPost();
  172. },
  173. fetchPost() {
  174. axios.get('/api/pixelfed/v1/statuses/'+this.$route.params.id)
  175. .then(res => {
  176. if(!res.data || !res.data.hasOwnProperty('id')) {
  177. this.$router.push('/i/web/404');
  178. }
  179. if(!res.data.hasOwnProperty('account') || !res.data.account) {
  180. this.postStateError = true;
  181. return;
  182. }
  183. this.post = res.data;
  184. this.media = this.post.media_attachments;
  185. this.profile = this.post.account;
  186. if(res.data.account && res.data.account.local) {
  187. window.history.pushState({}, '', `/p/${res.data.account.acct}/${res.data.id}`);
  188. }
  189. if(this.post.in_reply_to_id) {
  190. this.fetchReply();
  191. } else {
  192. this.fetchRelationship();
  193. }
  194. }).catch(err => {
  195. switch(err.response.status) {
  196. case 403:
  197. case 404:
  198. this.$router.push('/i/web/404');
  199. break;
  200. }
  201. })
  202. },
  203. fetchReply() {
  204. axios.get('/api/pixelfed/v1/statuses/' + this.post.in_reply_to_id)
  205. .then(res => {
  206. this.reply = res.data;
  207. this.isReply = true;
  208. this.fetchRelationship();
  209. })
  210. .catch(err => {
  211. this.fetchRelationship();
  212. })
  213. },
  214. fetchRelationship() {
  215. if(this.profile.id == this.user.id) {
  216. this.relationship = {};
  217. this.fetchState();
  218. return;
  219. }
  220. axios.get('/api/pixelfed/v1/accounts/relationships', {
  221. params: {
  222. 'id[]': this.profile.id
  223. }
  224. }).then(res => {
  225. this.relationship = res.data[0];
  226. this.fetchState();
  227. });
  228. },
  229. fetchState() {
  230. axios.get('/api/v2/statuses/'+this.post.id+'/state')
  231. .then(res => {
  232. this.post.favourited = res.data.liked;
  233. this.post.reblogged = res.data.shared;
  234. this.post.bookmarked = res.data.bookmarked;
  235. if(!this.post.favourites_count && this.post.favourited) {
  236. this.post.favourites_count = 1;
  237. }
  238. this.isLoaded = true;
  239. }).catch(err => {
  240. this.isLoaded = false;
  241. this.postStateError = true;
  242. })
  243. },
  244. goBack() {
  245. this.$router.push('/i/web');
  246. },
  247. likeStatus() {
  248. let count = this.post.favourites_count;
  249. this.post.favourites_count = count + 1;
  250. this.post.favourited = !this.post.favourited;
  251. axios.post('/api/v1/statuses/' + this.post.id + '/favourite')
  252. .then(res => {
  253. //
  254. }).catch(err => {
  255. this.post.favourites_count = count;
  256. this.post.favourited = false;
  257. })
  258. },
  259. unlikeStatus() {
  260. let count = this.post.favourites_count;
  261. this.post.favourites_count = count - 1;
  262. this.post.favourited = !this.post.favourited;
  263. axios.post('/api/v1/statuses/' + this.post.id + '/unfavourite')
  264. .then(res => {
  265. //
  266. }).catch(err => {
  267. this.post.favourites_count = count;
  268. this.post.favourited = false;
  269. })
  270. },
  271. shareStatus() {
  272. let count = this.post.reblogs_count;
  273. this.post.reblogs_count = count + 1;
  274. this.post.reblogged = !this.post.reblogged;
  275. axios.post('/api/v1/statuses/' + this.post.id + '/reblog')
  276. .then(res => {
  277. //
  278. }).catch(err => {
  279. this.post.reblogs_count = count;
  280. this.post.reblogged = false;
  281. })
  282. },
  283. unshareStatus() {
  284. let count = this.post.reblogs_count;
  285. this.post.reblogs_count = count - 1;
  286. this.post.reblogged = !this.post.reblogged;
  287. axios.post('/api/v1/statuses/' + this.post.id + '/unreblog')
  288. .then(res => {
  289. //
  290. }).catch(err => {
  291. this.post.reblogs_count = count;
  292. this.post.reblogged = false;
  293. })
  294. },
  295. follow() {
  296. axios.post('/api/v1/accounts/' + this.post.account.id + '/follow')
  297. .then(res => {
  298. this.$store.commit('updateRelationship', [res.data]);
  299. this.user.following_count++;
  300. this.post.account.followers_count++;
  301. }).catch(err => {
  302. swal('Oops!', 'An error occurred when attempting to follow this account.', 'error');
  303. this.post.relationship.following = false;
  304. });
  305. },
  306. unfollow() {
  307. axios.post('/api/v1/accounts/' + this.post.account.id + '/unfollow')
  308. .then(res => {
  309. this.$store.commit('updateRelationship', [res.data]);
  310. this.user.following_count--;
  311. this.post.account.followers_count--;
  312. }).catch(err => {
  313. swal('Oops!', 'An error occurred when attempting to unfollow this account.', 'error');
  314. this.post.relationship.following = true;
  315. });
  316. },
  317. openContextMenu() {
  318. this.$nextTick(() => {
  319. this.$refs.contextMenu.open();
  320. });
  321. },
  322. openLikesModal() {
  323. this.showLikesModal = true;
  324. this.$nextTick(() => {
  325. this.$refs.likesModal.open();
  326. });
  327. },
  328. openSharesModal() {
  329. this.showSharesModal = true;
  330. this.$nextTick(() => {
  331. this.$refs.sharesModal.open();
  332. });
  333. },
  334. deletePost() {
  335. this.$router.push('/i/web');
  336. },
  337. goToPost(post) {
  338. this.$router.push({
  339. name: 'post',
  340. path: `/i/web/post/${post.id}`,
  341. params: {
  342. id: post.id,
  343. cachedStatus: post,
  344. cachedProfile: this.user
  345. }
  346. })
  347. },
  348. goToProfile(account) {
  349. this.$router.push({
  350. name: 'profile',
  351. path: `/i/web/profile/${account.id}`,
  352. params: {
  353. id: account.id,
  354. cachedProfile: account,
  355. cachedUser: this.user
  356. }
  357. })
  358. },
  359. handleBookmark() {
  360. axios.post('/i/bookmark', {
  361. item: this.post.id
  362. })
  363. .then(res => {
  364. this.post.bookmarked = !this.post.bookmarked;
  365. })
  366. .catch(err => {
  367. this.$bvToast.toast('Cannot bookmark post at this time.', {
  368. title: 'Bookmark Error',
  369. variant: 'danger',
  370. autoHideDelay: 5000
  371. });
  372. });
  373. },
  374. handleReport() {
  375. this.$nextTick(() => {
  376. this.$refs.reportModal.open();
  377. });
  378. },
  379. counterChange(type) {
  380. switch(type) {
  381. case 'comment-increment':
  382. this.post.reply_count = this.post.reply_count + 1;
  383. break;
  384. case 'comment-decrement':
  385. this.post.reply_count = this.post.reply_count - 1;
  386. break;
  387. }
  388. },
  389. handleEdit(status) {
  390. this.$refs.editModal.show(status);
  391. },
  392. mergeUpdatedPost(post) {
  393. this.post = post;
  394. this.$nextTick(() => {
  395. this.forceUpdateIdx++;
  396. });
  397. },
  398. handlePinned() {
  399. this.post.pinned = true;
  400. },
  401. handleUnpinned() {
  402. this.post.pinned = false;
  403. },
  404. }
  405. }
  406. </script>