Post.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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. v-on:edit="handleEdit"
  82. />
  83. <likes-modal
  84. v-if="showLikesModal"
  85. ref="likesModal"
  86. :status="post"
  87. :profile="user"
  88. />
  89. <shares-modal
  90. v-if="showSharesModal"
  91. ref="sharesModal"
  92. :status="post"
  93. :profile="profile"
  94. />
  95. <report-modal
  96. v-if="post"
  97. ref="reportModal"
  98. :status="post"
  99. />
  100. <post-edit-modal
  101. ref="editModal"
  102. v-on:update="mergeUpdatedPost"
  103. />
  104. <drawer />
  105. </div>
  106. </template>
  107. <script type="text/javascript">
  108. import Drawer from './partials/drawer.vue';
  109. import Rightbar from './partials/rightbar.vue';
  110. import Sidebar from './partials/sidebar.vue';
  111. import Status from './partials/TimelineStatus.vue';
  112. import ContextMenu from './partials/post/ContextMenu.vue';
  113. import MediaContainer from './partials/post/MediaContainer.vue';
  114. import LikesModal from './partials/post/LikeModal.vue';
  115. import SharesModal from './partials/post/ShareModal.vue';
  116. import ReportModal from './partials/modal/ReportPost.vue';
  117. import PostEditModal from './partials/post/PostEditModal.vue';
  118. export default {
  119. props: {
  120. cachedStatus: {
  121. type: Object
  122. },
  123. cachedProfile: {
  124. type: Object
  125. }
  126. },
  127. components: {
  128. "drawer": Drawer,
  129. "sidebar": Sidebar,
  130. "status": Status,
  131. "context-menu": ContextMenu,
  132. "media-container": MediaContainer,
  133. "likes-modal": LikesModal,
  134. "shares-modal": SharesModal,
  135. "rightbar": Rightbar,
  136. "report-modal": ReportModal,
  137. "post-edit-modal": PostEditModal
  138. },
  139. data() {
  140. return {
  141. isLoaded: false,
  142. user: undefined,
  143. profile: undefined,
  144. post: undefined,
  145. relationship: {},
  146. media: undefined,
  147. mediaIndex: 0,
  148. showLikesModal: false,
  149. isReply: false,
  150. reply: {},
  151. showSharesModal: false,
  152. postStateError: false,
  153. forceUpdateIdx: 0
  154. }
  155. },
  156. created() {
  157. this.init();
  158. },
  159. watch: {
  160. '$route': 'init'
  161. },
  162. methods: {
  163. init() {
  164. this.fetchSelf();
  165. },
  166. fetchSelf() {
  167. this.user = window._sharedData.user;
  168. this.isReply = false;
  169. this.fetchPost();
  170. },
  171. fetchPost() {
  172. axios.get('/api/pixelfed/v1/statuses/'+this.$route.params.id)
  173. .then(res => {
  174. if(!res.data || !res.data.hasOwnProperty('id')) {
  175. this.$router.push('/i/web/404');
  176. }
  177. if(!res.data.hasOwnProperty('account') || !res.data.account) {
  178. this.postStateError = true;
  179. return;
  180. }
  181. this.post = res.data;
  182. this.media = this.post.media_attachments;
  183. this.profile = this.post.account;
  184. if(this.post.in_reply_to_id) {
  185. this.fetchReply();
  186. } else {
  187. this.fetchRelationship();
  188. }
  189. }).catch(err => {
  190. switch(err.response.status) {
  191. case 403:
  192. case 404:
  193. this.$router.push('/i/web/404');
  194. break;
  195. }
  196. })
  197. },
  198. fetchReply() {
  199. axios.get('/api/pixelfed/v1/statuses/' + this.post.in_reply_to_id)
  200. .then(res => {
  201. this.reply = res.data;
  202. this.isReply = true;
  203. this.fetchRelationship();
  204. })
  205. .catch(err => {
  206. this.fetchRelationship();
  207. })
  208. },
  209. fetchRelationship() {
  210. if(this.profile.id == this.user.id) {
  211. this.relationship = {};
  212. this.fetchState();
  213. return;
  214. }
  215. axios.get('/api/pixelfed/v1/accounts/relationships', {
  216. params: {
  217. 'id[]': this.profile.id
  218. }
  219. }).then(res => {
  220. this.relationship = res.data[0];
  221. this.fetchState();
  222. });
  223. },
  224. fetchState() {
  225. axios.get('/api/v2/statuses/'+this.post.id+'/state')
  226. .then(res => {
  227. this.post.favourited = res.data.liked;
  228. this.post.reblogged = res.data.shared;
  229. this.post.bookmarked = res.data.bookmarked;
  230. if(!this.post.favourites_count && this.post.favourited) {
  231. this.post.favourites_count = 1;
  232. }
  233. this.isLoaded = true;
  234. }).catch(err => {
  235. this.isLoaded = false;
  236. this.postStateError = true;
  237. })
  238. },
  239. goBack() {
  240. this.$router.push('/i/web');
  241. },
  242. likeStatus() {
  243. let count = this.post.favourites_count;
  244. this.post.favourites_count = count + 1;
  245. this.post.favourited = !this.post.favourited;
  246. axios.post('/api/v1/statuses/' + this.post.id + '/favourite')
  247. .then(res => {
  248. //
  249. }).catch(err => {
  250. this.post.favourites_count = count;
  251. this.post.favourited = false;
  252. })
  253. },
  254. unlikeStatus() {
  255. let count = this.post.favourites_count;
  256. this.post.favourites_count = count - 1;
  257. this.post.favourited = !this.post.favourited;
  258. axios.post('/api/v1/statuses/' + this.post.id + '/unfavourite')
  259. .then(res => {
  260. //
  261. }).catch(err => {
  262. this.post.favourites_count = count;
  263. this.post.favourited = false;
  264. })
  265. },
  266. shareStatus() {
  267. let count = this.post.reblogs_count;
  268. this.post.reblogs_count = count + 1;
  269. this.post.reblogged = !this.post.reblogged;
  270. axios.post('/api/v1/statuses/' + this.post.id + '/reblog')
  271. .then(res => {
  272. //
  273. }).catch(err => {
  274. this.post.reblogs_count = count;
  275. this.post.reblogged = false;
  276. })
  277. },
  278. unshareStatus() {
  279. let count = this.post.reblogs_count;
  280. this.post.reblogs_count = count - 1;
  281. this.post.reblogged = !this.post.reblogged;
  282. axios.post('/api/v1/statuses/' + this.post.id + '/unreblog')
  283. .then(res => {
  284. //
  285. }).catch(err => {
  286. this.post.reblogs_count = count;
  287. this.post.reblogged = false;
  288. })
  289. },
  290. follow() {
  291. axios.post('/api/v1/accounts/' + this.post.account.id + '/follow')
  292. .then(res => {
  293. this.$store.commit('updateRelationship', [res.data]);
  294. this.user.following_count++;
  295. this.post.account.followers_count++;
  296. }).catch(err => {
  297. swal('Oops!', 'An error occurred when attempting to follow this account.', 'error');
  298. this.post.relationship.following = false;
  299. });
  300. },
  301. unfollow() {
  302. axios.post('/api/v1/accounts/' + this.post.account.id + '/unfollow')
  303. .then(res => {
  304. this.$store.commit('updateRelationship', [res.data]);
  305. this.user.following_count--;
  306. this.post.account.followers_count--;
  307. }).catch(err => {
  308. swal('Oops!', 'An error occurred when attempting to unfollow this account.', 'error');
  309. this.post.relationship.following = true;
  310. });
  311. },
  312. openContextMenu() {
  313. this.$nextTick(() => {
  314. this.$refs.contextMenu.open();
  315. });
  316. },
  317. openLikesModal() {
  318. this.showLikesModal = true;
  319. this.$nextTick(() => {
  320. this.$refs.likesModal.open();
  321. });
  322. },
  323. openSharesModal() {
  324. this.showSharesModal = true;
  325. this.$nextTick(() => {
  326. this.$refs.sharesModal.open();
  327. });
  328. },
  329. deletePost() {
  330. this.$router.push('/i/web');
  331. },
  332. goToPost(post) {
  333. this.$router.push({
  334. name: 'post',
  335. path: `/i/web/post/${post.id}`,
  336. params: {
  337. id: post.id,
  338. cachedStatus: post,
  339. cachedProfile: this.user
  340. }
  341. })
  342. },
  343. goToProfile(account) {
  344. this.$router.push({
  345. name: 'profile',
  346. path: `/i/web/profile/${account.id}`,
  347. params: {
  348. id: account.id,
  349. cachedProfile: account,
  350. cachedUser: this.user
  351. }
  352. })
  353. },
  354. handleBookmark() {
  355. axios.post('/i/bookmark', {
  356. item: this.post.id
  357. })
  358. .then(res => {
  359. this.post.bookmarked = !this.post.bookmarked;
  360. })
  361. .catch(err => {
  362. this.$bvToast.toast('Cannot bookmark post at this time.', {
  363. title: 'Bookmark Error',
  364. variant: 'danger',
  365. autoHideDelay: 5000
  366. });
  367. });
  368. },
  369. handleReport() {
  370. this.$nextTick(() => {
  371. this.$refs.reportModal.open();
  372. });
  373. },
  374. counterChange(type) {
  375. switch(type) {
  376. case 'comment-increment':
  377. this.post.reply_count = this.post.reply_count + 1;
  378. break;
  379. case 'comment-decrement':
  380. this.post.reply_count = this.post.reply_count - 1;
  381. break;
  382. }
  383. },
  384. handleEdit(status) {
  385. this.$refs.editModal.show(status);
  386. },
  387. mergeUpdatedPost(post) {
  388. this.post = post;
  389. this.$nextTick(() => {
  390. this.forceUpdateIdx++;
  391. });
  392. }
  393. }
  394. }
  395. </script>