Post.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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"
  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:counter-change="counterChange"
  38. />
  39. </div>
  40. <div class="d-none d-lg-block col-lg-3">
  41. <rightbar />
  42. </div>
  43. </div>
  44. </div>
  45. <div v-if="postStateError" class="container-fluid mt-3">
  46. <div class="row">
  47. <div class="col-md-4 col-lg-3 d-md-block">
  48. <sidebar :user="user" />
  49. </div>
  50. <div class="col-md-8 col-lg-6">
  51. <div class="card card-body shadow-none border">
  52. <div class="d-flex align-self-center flex-column" style="max-width: 500px;">
  53. <p class="text-center">
  54. <i class="far fa-exclamation-triangle fa-3x text-lighter"></i>
  55. </p>
  56. <p class="text-center lead font-weight-bold">Error displaying post</p>
  57. <p class="mb-0">This can happen for a few reasons:</p>
  58. <ul class="text-lighter">
  59. <li>The url is invalid or has a typo</li>
  60. <li>The page has been flagged for review by our automated abuse detection systems</li>
  61. <li>The content may have been deleted</li>
  62. <li>You do not have permission to view this content</li>
  63. </ul>
  64. </div>
  65. </div>
  66. </div>
  67. <div class="d-none d-lg-block col-lg-3">
  68. <rightbar />
  69. </div>
  70. </div>
  71. </div>
  72. <context-menu
  73. v-if="isLoaded"
  74. ref="contextMenu"
  75. :status="post"
  76. :profile="user"
  77. @report-modal="handleReport()"
  78. @delete="deletePost()"
  79. />
  80. <likes-modal
  81. v-if="showLikesModal"
  82. ref="likesModal"
  83. :status="post"
  84. :profile="user"
  85. />
  86. <shares-modal
  87. v-if="showSharesModal"
  88. ref="sharesModal"
  89. :status="post"
  90. :profile="profile"
  91. />
  92. <report-modal
  93. v-if="post"
  94. ref="reportModal"
  95. :status="post"
  96. />
  97. <drawer />
  98. </div>
  99. </template>
  100. <script type="text/javascript">
  101. import Drawer from './partials/drawer.vue';
  102. import Rightbar from './partials/rightbar.vue';
  103. import Sidebar from './partials/sidebar.vue';
  104. import Status from './partials/TimelineStatus.vue';
  105. import ContextMenu from './partials/post/ContextMenu.vue';
  106. import MediaContainer from './partials/post/MediaContainer.vue';
  107. import LikesModal from './partials/post/LikeModal.vue';
  108. import SharesModal from './partials/post/ShareModal.vue';
  109. import ReportModal from './partials/modal/ReportPost.vue';
  110. export default {
  111. props: {
  112. cachedStatus: {
  113. type: Object
  114. },
  115. cachedProfile: {
  116. type: Object
  117. }
  118. },
  119. components: {
  120. "drawer": Drawer,
  121. "sidebar": Sidebar,
  122. "status": Status,
  123. "context-menu": ContextMenu,
  124. "media-container": MediaContainer,
  125. "likes-modal": LikesModal,
  126. "shares-modal": SharesModal,
  127. "rightbar": Rightbar,
  128. "report-modal": ReportModal
  129. },
  130. data() {
  131. return {
  132. isLoaded: false,
  133. user: undefined,
  134. profile: undefined,
  135. post: undefined,
  136. relationship: {},
  137. media: undefined,
  138. mediaIndex: 0,
  139. showLikesModal: false,
  140. isReply: false,
  141. reply: {},
  142. showSharesModal: false,
  143. postStateError: false
  144. }
  145. },
  146. beforeMount() {
  147. this.init();
  148. },
  149. watch: {
  150. '$route': 'init'
  151. },
  152. methods: {
  153. init() {
  154. if(this.cachedStatus && this.cachedProfile) {
  155. this.post = this.cachedStatus;
  156. this.media = this.post.media_attachments;
  157. this.profile = this.post.account;
  158. this.user = this.cachedProfile;
  159. if(this.post.in_reply_to_id) {
  160. this.fetchReply();
  161. } else {
  162. this.isReply = false;
  163. this.fetchRelationship();
  164. }
  165. } else {
  166. this.fetchSelf();
  167. }
  168. },
  169. fetchSelf() {
  170. this.user = window._sharedData.user;
  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. this.post = res.data;
  180. this.media = this.post.media_attachments;
  181. this.profile = this.post.account;
  182. if(this.post.in_reply_to_id) {
  183. this.fetchReply();
  184. } else {
  185. this.fetchRelationship();
  186. }
  187. }).catch(err => {
  188. switch(err.response.status) {
  189. case 403:
  190. case 404:
  191. this.$router.push('/i/web/404');
  192. break;
  193. }
  194. })
  195. },
  196. fetchReply() {
  197. axios.get('/api/pixelfed/v1/statuses/' + this.post.in_reply_to_id)
  198. .then(res => {
  199. this.reply = res.data;
  200. this.isReply = true;
  201. this.fetchRelationship();
  202. })
  203. .catch(err => {
  204. this.fetchRelationship();
  205. })
  206. },
  207. fetchRelationship() {
  208. if(this.profile.id == this.user.id) {
  209. this.relationship = {};
  210. this.fetchState();
  211. return;
  212. }
  213. axios.get('/api/pixelfed/v1/accounts/relationships', {
  214. params: {
  215. 'id[]': this.profile.id
  216. }
  217. }).then(res => {
  218. this.relationship = res.data[0];
  219. this.fetchState();
  220. });
  221. },
  222. fetchState() {
  223. axios.get('/api/v2/statuses/'+this.post.id+'/state')
  224. .then(res => {
  225. this.post.favourited = res.data.liked;
  226. this.post.reblogged = res.data.shared;
  227. this.post.bookmarked = res.data.bookmarked;
  228. if(!this.post.favourites_count && this.post.favourited) {
  229. this.post.favourites_count = 1;
  230. }
  231. this.isLoaded = true;
  232. }).catch(err => {
  233. this.isLoaded = false;
  234. this.postStateError = true;
  235. })
  236. },
  237. goBack() {
  238. this.$router.push('/i/web');
  239. },
  240. likeStatus() {
  241. let count = this.post.favourites_count;
  242. this.post.favourites_count = count + 1;
  243. this.post.favourited = !this.post.favourited;
  244. axios.post('/api/v1/statuses/' + this.post.id + '/favourite')
  245. .then(res => {
  246. //
  247. }).catch(err => {
  248. this.post.favourites_count = count;
  249. this.post.favourited = false;
  250. })
  251. },
  252. unlikeStatus() {
  253. let count = this.post.favourites_count;
  254. this.post.favourites_count = count - 1;
  255. this.post.favourited = !this.post.favourited;
  256. axios.post('/api/v1/statuses/' + this.post.id + '/unfavourite')
  257. .then(res => {
  258. //
  259. }).catch(err => {
  260. this.post.favourites_count = count;
  261. this.post.favourited = false;
  262. })
  263. },
  264. shareStatus() {
  265. let count = this.post.reblogs_count;
  266. this.post.reblogs_count = count + 1;
  267. this.post.reblogged = !this.post.reblogged;
  268. axios.post('/api/v1/statuses/' + this.post.id + '/reblog')
  269. .then(res => {
  270. //
  271. }).catch(err => {
  272. this.post.reblogs_count = count;
  273. this.post.reblogged = false;
  274. })
  275. },
  276. unshareStatus() {
  277. let count = this.post.reblogs_count;
  278. this.post.reblogs_count = count - 1;
  279. this.post.reblogged = !this.post.reblogged;
  280. axios.post('/api/v1/statuses/' + this.post.id + '/unreblog')
  281. .then(res => {
  282. //
  283. }).catch(err => {
  284. this.post.reblogs_count = count;
  285. this.post.reblogged = false;
  286. })
  287. },
  288. openContextMenu() {
  289. this.$nextTick(() => {
  290. this.$refs.contextMenu.open();
  291. });
  292. },
  293. openLikesModal() {
  294. this.showLikesModal = true;
  295. this.$nextTick(() => {
  296. this.$refs.likesModal.open();
  297. });
  298. },
  299. openSharesModal() {
  300. this.showSharesModal = true;
  301. this.$nextTick(() => {
  302. this.$refs.sharesModal.open();
  303. });
  304. },
  305. deletePost() {
  306. this.$router.push('/i/web');
  307. },
  308. goToPost(post) {
  309. this.$router.push({
  310. name: 'post',
  311. path: `/i/web/post/${post.id}`,
  312. params: {
  313. id: post.id,
  314. cachedStatus: post,
  315. cachedProfile: this.user
  316. }
  317. })
  318. },
  319. goToProfile(account) {
  320. this.$router.push({
  321. name: 'profile',
  322. path: `/i/web/profile/${account.id}`,
  323. params: {
  324. id: account.id,
  325. cachedProfile: account,
  326. cachedUser: this.user
  327. }
  328. })
  329. },
  330. handleBookmark() {
  331. axios.post('/i/bookmark', {
  332. item: this.post.id
  333. })
  334. .then(res => {
  335. this.post.bookmarked = !this.post.bookmarked;
  336. })
  337. .catch(err => {
  338. this.$bvToast.toast('Cannot bookmark post at this time.', {
  339. title: 'Bookmark Error',
  340. variant: 'danger',
  341. autoHideDelay: 5000
  342. });
  343. });
  344. },
  345. handleReport() {
  346. this.$nextTick(() => {
  347. this.$refs.reportModal.open();
  348. });
  349. },
  350. counterChange(type) {
  351. switch(type) {
  352. case 'comment-increment':
  353. this.post.reply_count = this.post.reply_count + 1;
  354. break;
  355. case 'comment-decrement':
  356. this.post.reply_count = this.post.reply_count - 1;
  357. break;
  358. }
  359. },
  360. }
  361. }
  362. </script>