Timeline.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. <template>
  2. <div class="container" style="">
  3. <div class="row">
  4. <div class="col-md-8 col-lg-8 pt-4 px-0 my-3">
  5. <div class="card mb-4 status-card card-md-rounded-0" :data-status-id="status.id" v-for="(status, index) in feed" :key="status.id">
  6. <div class="card-header d-inline-flex align-items-center bg-white">
  7. <img v-bind:src="status.account.avatar" width="32px" height="32px" style="border-radius: 32px;">
  8. <a class="username font-weight-bold pl-2 text-dark" v-bind:href="status.account.url">
  9. {{status.account.username}}
  10. </a>
  11. <div class="text-right" style="flex-grow:1;">
  12. <div class="dropdown">
  13. <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">
  14. <span class="fas fa-ellipsis-v fa-lg text-muted"></span>
  15. </button>
  16. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
  17. <a class="dropdown-item font-weight-bold" :href="status.url">Go to post</a>
  18. <span v-bind:class="[statusOwner(status) ? 'd-none' : '']">
  19. <a class="dropdown-item font-weight-bold" :href="reportUrl(status)">Report</a>
  20. <a class="dropdown-item font-weight-bold" v-on:click="muteProfile(status)">Mute Profile</a>
  21. <a class="dropdown-item font-weight-bold" v-on:click="blockProfile(status)">Block Profile</a>
  22. </span>
  23. <span v-bind:class="[statusOwner(status) ? '' : 'd-none']">
  24. <a class="dropdown-item font-weight-bold" :href="editUrl(status)">Edit</a>
  25. <a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost(status)">Delete</a>
  26. </span>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. <div class="postPresenterContainer">
  32. <div v-if="status.pf_type === 'photo'" class="w-100">
  33. <div v-if="status.sensitive == true">
  34. <details class="details-animated">
  35. <summary>
  36. <p class="mb-0 lead font-weight-bold">{{ status.spoiler_text ? status.spoiler_text : 'CW / NSFW / Hidden Media'}}</p>
  37. <p class="font-weight-light">(click to show)</p>
  38. </summary>
  39. <a class="max-hide-overflow" :href="status.url">
  40. <img class="card-img-top" :src="status.media_attachments[0].url">
  41. </a>
  42. </details>
  43. </div>
  44. <div v-else>
  45. <div>
  46. <img class="card-img-top" :src="status.media_attachments[0].url">
  47. </div>
  48. </div>
  49. </div>
  50. <div v-else-if="status.pf_type === 'video'" class="w-100">
  51. <div v-if="status.sensitive == true">
  52. <details class="details-animated">
  53. <summary>
  54. <p class="mb-0 lead font-weight-bold">{{ status.spoiler_text ? status.spoiler_text : 'CW / NSFW / Hidden Media'}}</p>
  55. <p class="font-weight-light">(click to show)</p>
  56. </summary>
  57. <div class="embed-responsive embed-responsive-16by9">
  58. <video class="video" preload="none" controls loop>
  59. <source :src="status.media_attachments[0].url" :type="status.media_attachments[0].mime">
  60. </video>
  61. </div>
  62. </details>
  63. </div>
  64. <div v-else class="embed-responsive embed-responsive-16by9">
  65. <video class="video" preload="none" controls loop>
  66. <source :src="status.media_attachments[0].url" :type="status.media_attachments[0].mime">
  67. </video>
  68. </div>
  69. </div>
  70. <div v-else-if="status.pf_type === 'photo:album'">
  71. <div v-if="status.sensitive == true">
  72. <details class="details-animated">
  73. <summary>
  74. <p class="mb-0 lead font-weight-bold">{{ status.spoiler_text ? status.spoiler_text : 'CW / NSFW / Hidden Media'}}</p>
  75. <p class="font-weight-light">(click to show)</p>
  76. </summary>
  77. <b-carousel :id="status.id + '-carousel'"
  78. style="text-shadow: 1px 1px 2px #333;"
  79. controls
  80. indicators
  81. background="#ffffff"
  82. :interval="0"
  83. >
  84. <b-carousel-slide v-for="(img, index) in status.media_attachments" :key="img.id">
  85. <img slot="img" class="d-block img-fluid w-100" :src="img.url" :alt="img.description">
  86. </b-carousel-slide>
  87. </b-carousel>
  88. </details>
  89. </div>
  90. <div v-else>
  91. <b-carousel :id="status.id + '-carousel'"
  92. style="text-shadow: 1px 1px 2px #333;"
  93. controls
  94. indicators
  95. background="#ffffff"
  96. :interval="0"
  97. >
  98. <b-carousel-slide v-for="(img, index) in status.media_attachments" :key="img.id">
  99. <img slot="img" class="d-block img-fluid w-100" :src="img.url" :alt="img.description">
  100. </b-carousel-slide>
  101. </b-carousel>
  102. </div>
  103. </div>
  104. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  105. <div v-if="status.sensitive == true">
  106. <details class="details-animated">
  107. <summary>
  108. <p class="mb-0 lead font-weight-bold">{{ status.spoiler_text ? status.spoiler_text : 'CW / NSFW / Hidden Media'}}</p>
  109. <p class="font-weight-light">(click to show)</p>
  110. </summary>
  111. <b-carousel :id="status.id + '-carousel'"
  112. style="text-shadow: 1px 1px 2px #333; background-color: #000;"
  113. controls
  114. img-blank
  115. background="#ffffff"
  116. :interval="0"
  117. >
  118. <b-carousel-slide v-for="(vid, index) in status.media_attachments" :key="vid.id + '-media'">
  119. <video slot="img" class="embed-responsive-item" preload="none" controls loop :alt="vid.description" width="100%" height="100%">
  120. <source :src="vid.url" :type="vid.mime">
  121. </video>
  122. </b-carousel-slide>
  123. </b-carousel>
  124. </details>
  125. </div>
  126. <div v-else>
  127. <b-carousel :id="status.id + '-carousel'"
  128. style="text-shadow: 1px 1px 2px #333; background-color: #000;"
  129. controls
  130. img-blank
  131. background="#ffffff"
  132. :interval="0"
  133. >
  134. <b-carousel-slide v-for="(vid, index) in status.media_attachments" :key="vid.id + '-media'">
  135. <video slot="img" class="embed-responsive-item" preload="none" controls loop :alt="vid.description" width="100%" height="100%">
  136. <source :src="vid.url" :type="vid.mime">
  137. </video>
  138. </b-carousel-slide>
  139. </b-carousel>
  140. </div>
  141. </div>
  142. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  143. <div v-if="status.sensitive == true">
  144. <details class="details-animated">
  145. <summary>
  146. <p class="mb-0 lead font-weight-bold">{{ status.spoiler_text ? status.spoiler_text : 'CW / NSFW / Hidden Media'}}</p>
  147. <p class="font-weight-light">(click to show)</p>
  148. </summary>
  149. <b-carousel :id="status.id + '-carousel'"
  150. style="text-shadow: 1px 1px 2px #333; background-color: #000;"
  151. controls
  152. img-blank
  153. background="#ffffff"
  154. :interval="0"
  155. >
  156. <b-carousel-slide v-for="(media, index) in status.media_attachments" :key="media.id + '-media'">
  157. <video v-if="media.type == 'Video'" slot="img" class="embed-responsive-item" preload="none" controls loop :alt="media.description" width="100%" height="100%">
  158. <source :src="media.url" :type="media.mime">
  159. </video>
  160. <img v-else-if="media.type == 'Image'" slot="img" class="d-block img-fluid w-100" :src="media.url" :alt="media.description">
  161. <p v-else class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  162. </b-carousel-slide>
  163. </b-carousel>
  164. </details>
  165. </div>
  166. <div v-else>
  167. <b-carousel :id="status.id + '-carousel'"
  168. style="text-shadow: 1px 1px 2px #333; background-color: #000;"
  169. controls
  170. img-blank
  171. background="#ffffff"
  172. :interval="0"
  173. >
  174. <b-carousel-slide v-for="(media, index) in status.media_attachments" :key="media.id + '-media'">
  175. <video v-if="media.type == 'Video'" slot="img" class="embed-responsive-item" preload="none" controls loop :alt="media.description" width="100%" height="100%">
  176. <source :src="media.url" :type="media.mime">
  177. </video>
  178. <img v-else-if="media.type == 'Image'" slot="img" class="d-block img-fluid w-100" :src="media.url" :alt="media.description">
  179. <p v-else class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  180. </b-carousel-slide>
  181. </b-carousel>
  182. </div>
  183. </div>
  184. <div v-else class="w-100">
  185. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  186. </div>
  187. </div>
  188. <div class="card-body">
  189. <div class="reactions my-1">
  190. <h3 v-bind:class="[status.favourited ? '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(status, $event)"></h3>
  191. <h3 class="far fa-comment pr-3 m-0 cursor-pointer" title="Comment" v-on:click="commentFocus(status, $event)"></h3>
  192. <h3 v-bind:class="[status.reblogged ? '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(status, $event)"></h3>
  193. </div>
  194. <div class="likes font-weight-bold">
  195. <span class="like-count">{{status.favourites_count}}</span> {{status.favourites_count == 1 ? 'like' : 'likes'}}
  196. </div>
  197. <div class="caption">
  198. <p class="mb-2 read-more" style="overflow: hidden;">
  199. <span class="username font-weight-bold">
  200. <bdi><a class="text-dark" :href="status.account.url">{{status.account.username}}</a></bdi>
  201. </span>
  202. <span v-html="status.content"></span>
  203. </p>
  204. </div>
  205. <div class="comments">
  206. </div>
  207. <div class="timestamp pt-1">
  208. <p class="small text-uppercase mb-0">
  209. <a :href="status.url" class="text-muted">
  210. <timeago :datetime="status.created_at" :auto-update="60" :converter-options="{includeSeconds:true}" :title="timestampFormat(status.created_at)" v-b-tooltip.hover.bottom></timeago>
  211. </a>
  212. </p>
  213. </div>
  214. </div>
  215. <div class="card-footer bg-white d-none">
  216. <form class="" v-on:submit.prevent="commentSubmit(status, $event)">
  217. <input type="hidden" name="item" value="">
  218. <input class="form-control status-reply-input" name="comment" placeholder="Add a comment…" autocomplete="off">
  219. </form>
  220. </div>
  221. </div>
  222. </div>
  223. <div class="col-md-4 col-lg-4 pt-4 my-3">
  224. <div class="media d-flex align-items-center mb-4">
  225. <a :href="profile.url">
  226. <img class="mr-3 rounded-circle box-shadow" :src="profile.avatar" alt="avatar" width="64px">
  227. </a>
  228. <div class="media-body">
  229. <p class="mb-0 px-0 font-weight-bold"><a :href="profile.url">&commat;{{profile.username}}</a></p>
  230. <p class="mb-0 text-muted text-truncate pb-0">{{profile.display_name}}</p>
  231. </div>
  232. </div>
  233. <div class="mb-4">
  234. <ul class="nav nav-pills flex-column timeline-sidenav" style="max-width: 240px;">
  235. <li class="nav-item">
  236. <a v-bind:class="[scope == '/' ? 'nav-link font-weight-bold active' : 'nav-link font-weight-bold']" href="/" data-type="personal">
  237. <i class="far fa-user pr-1"></i> My Timeline
  238. </a>
  239. </li>
  240. <li class="nav-item">
  241. <a v-bind:class="[scope == '/timeline/public' ? 'nav-link font-weight-bold active' : 'nav-link font-weight-bold']" href="/timeline/public" data-type="local">
  242. <i class="fas fa-bars pr-1"></i> Local Timeline
  243. </a>
  244. </li>
  245. <li class="nav-item" data-toggle="tooltip" data-placement="bottom" title="The network timeline is not available yet.">
  246. <span class="nav-link font-weight-bold">
  247. <i class="fas fa-globe pr-1"></i> Network Timeline
  248. </span>
  249. </li>
  250. </ul>
  251. </div>
  252. <footer>
  253. <div class="container pb-5">
  254. <p class="mb-0 text-uppercase font-weight-bold text-muted small">
  255. <a href="/site/about" class="text-dark pr-2">About Us</a>
  256. <a href="/site/help" class="text-dark pr-2">Support</a>
  257. <a href="/site/open-source" class="text-dark pr-2">Open Source</a>
  258. <a href="/site/language" class="text-dark pr-2">Language</a>
  259. <a href="/site/terms" class="text-dark pr-2">Terms</a>
  260. <a href="/site/privacy" class="text-dark pr-2">Privacy</a>
  261. <a href="/site/platform" class="text-dark pr-2">API</a>
  262. </p>
  263. <p class="mb-0 text-uppercase font-weight-bold text-muted small">
  264. <a href="http://pixelfed.org" class="text-muted" rel="noopener" title="" data-toggle="tooltip">Powered by PixelFed</a>
  265. </p>
  266. </div>
  267. </footer>
  268. </div>
  269. </div>
  270. </div>
  271. </template>
  272. <style type="text/css">
  273. .postPresenterContainer {
  274. display: flex;
  275. align-items: center;
  276. background: #000;
  277. min-height: 600px;
  278. }
  279. .cursor-pointer {
  280. cursor: pointer;
  281. }
  282. </style>
  283. <script type="text/javascript">
  284. export default {
  285. data() {
  286. return {
  287. page: 1,
  288. feed: [],
  289. profile: {},
  290. scope: window.location.pathname,
  291. min_id: 0,
  292. max_id: 0,
  293. }
  294. },
  295. beforeMount() {
  296. this.fetchTimelineApi();
  297. this.fetchProfile();
  298. },
  299. mounted() {
  300. },
  301. updated() {
  302. this.scroll();
  303. },
  304. methods: {
  305. fetchProfile() {
  306. axios.get('/api/v1/accounts/verify_credentials').then(res => {
  307. this.profile = res.data;
  308. }).catch(err => {
  309. swal(
  310. 'Oops, something went wrong',
  311. 'Please reload the page.',
  312. 'error'
  313. );
  314. });
  315. },
  316. fetchTimelineApi() {
  317. let homeTimeline = '/api/v1/timelines/home?page=' + this.page;
  318. let localTimeline = '/api/v1/timelines/public?page=' + this.page;
  319. let apiUrl = this.scope == '/' ? homeTimeline : localTimeline;
  320. axios.get(apiUrl).then(res => {
  321. let data = res.data;
  322. this.feed.push(...data);
  323. let ids = data.map(status => status.id);
  324. this.min_id = Math.min(...ids);
  325. if(this.page == 1) {
  326. this.max_id = Math.max(...ids);
  327. }
  328. this.page++;
  329. }).catch(err => {
  330. });
  331. },
  332. scroll() {
  333. window.onscroll = () => {
  334. let bottomOfWindow = document.documentElement.scrollTop + window.innerHeight == document.documentElement.offsetHeight;
  335. if (bottomOfWindow) {
  336. this.fetchTimelineApi();
  337. }
  338. };
  339. },
  340. reportUrl(status) {
  341. let type = status.in_reply_to ? 'comment' : 'post';
  342. let id = status.id;
  343. return '/i/report?type=' + type + '&id=' + id;
  344. },
  345. commentFocus(status, $event) {
  346. let el = event.target;
  347. let card = el.parentElement.parentElement.parentElement;
  348. let comments = card.getElementsByClassName('comments')[0];
  349. if(comments.children.length == 0) {
  350. comments.classList.add('mb-2');
  351. this.fetchStatusComments(status, card);
  352. }
  353. let footer = card.querySelectorAll('.card-footer')[0];
  354. let input = card.querySelectorAll('.status-reply-input')[0];
  355. if(footer.classList.contains('d-none') == true) {
  356. footer.classList.remove('d-none');
  357. input.focus();
  358. } else {
  359. footer.classList.add('d-none');
  360. input.blur();
  361. }
  362. },
  363. likeStatus(status, $event) {
  364. if($('body').hasClass('loggedIn') == false) {
  365. return;
  366. }
  367. axios.post('/i/like', {
  368. item: status.id
  369. }).then(res => {
  370. status.favourites_count = res.data.count;
  371. if(status.favourited == true) {
  372. status.favourited = false;
  373. } else {
  374. status.favourited = true;
  375. }
  376. }).catch(err => {
  377. swal('Error', 'Something went wrong, please try again later.', 'error');
  378. });
  379. },
  380. shareStatus(status, $event) {
  381. if($('body').hasClass('loggedIn') == false) {
  382. return;
  383. }
  384. axios.post('/i/share', {
  385. item: status.id
  386. }).then(res => {
  387. status.reblogs_count = res.data.count;
  388. if(status.reblogged == true) {
  389. status.reblogged = false;
  390. } else {
  391. status.reblogged = true;
  392. }
  393. }).catch(err => {
  394. swal('Error', 'Something went wrong, please try again later.', 'error');
  395. });
  396. },
  397. timestampFormat(timestamp) {
  398. let ts = new Date(timestamp);
  399. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  400. },
  401. editUrl(status) {
  402. return status.url + '/edit';
  403. },
  404. statusOwner(status) {
  405. let sid = status.account.id;
  406. let uid = this.profile.id;
  407. if(sid == uid) {
  408. return true;
  409. } else {
  410. return false;
  411. }
  412. },
  413. fetchStatusComments(status, card) {
  414. axios.get('/api/v2/status/'+status.id+'/replies')
  415. .then(res => {
  416. let comments = card.querySelectorAll('.comments')[0];
  417. let data = res.data;
  418. data.forEach(function(i, k) {
  419. let username = document.createElement('a');
  420. username.classList.add('font-weight-bold');
  421. username.classList.add('text-dark');
  422. username.classList.add('mr-2');
  423. username.setAttribute('href', i.account.url);
  424. username.textContent = i.account.username;
  425. let text = document.createElement('span');
  426. text.innerHTML = i.content;
  427. let comment = document.createElement('p');
  428. comment.classList.add('read-more');
  429. comment.classList.add('mb-0');
  430. comment.appendChild(username);
  431. comment.appendChild(text);
  432. comments.appendChild(comment);
  433. });
  434. }).catch(err => {
  435. })
  436. },
  437. muteProfile(status) {
  438. if($('body').hasClass('loggedIn') == false) {
  439. return;
  440. }
  441. axios.post('/i/mute', {
  442. type: 'user',
  443. item: status.account.id
  444. }).then(res => {
  445. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  446. swal('Success', 'You have successfully muted ' + status.account.acct, 'success');
  447. }).catch(err => {
  448. swal('Error', 'Something went wrong. Please try again later.', 'error');
  449. });
  450. },
  451. blockProfile(status) {
  452. if($('body').hasClass('loggedIn') == false) {
  453. return;
  454. }
  455. axios.post('/i/block', {
  456. type: 'user',
  457. item: status.account.id
  458. }).then(res => {
  459. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  460. swal('Success', 'You have successfully blocked ' + status.account.acct, 'success');
  461. }).catch(err => {
  462. swal('Error', 'Something went wrong. Please try again later.', 'error');
  463. });
  464. },
  465. deletePost(status, index) {
  466. if($('body').hasClass('loggedIn') == false || status.account.id !== this.profile.id) {
  467. return;
  468. }
  469. axios.post('/i/delete', {
  470. type: 'status',
  471. item: status.id
  472. }).then(res => {
  473. this.feed.splice(index,1);
  474. swal('Success', 'You have successfully deleted this post', 'success');
  475. }).catch(err => {
  476. swal('Error', 'Something went wrong. Please try again later.', 'error');
  477. });
  478. },
  479. commentSubmit(status, $event) {
  480. let id = status.id;
  481. let form = $event.target;
  482. let input = $(form).find('input[name="comment"]');
  483. let comment = input.val();
  484. let comments = form.parentElement.parentElement.getElementsByClassName('comments')[0];
  485. axios.post('/i/comment', {
  486. item: id,
  487. comment: comment
  488. }).then(res => {
  489. input.val('');
  490. input.blur();
  491. let username = document.createElement('a');
  492. username.classList.add('font-weight-bold');
  493. username.classList.add('text-dark');
  494. username.classList.add('mr-2');
  495. username.setAttribute('href', this.profile.url);
  496. username.textContent = this.profile.username;
  497. let text = document.createElement('span');
  498. text.innerHTML = comment;
  499. let wrapper = document.createElement('p');
  500. wrapper.classList.add('read-more');
  501. wrapper.classList.add('mb-0');
  502. wrapper.appendChild(username);
  503. wrapper.appendChild(text);
  504. comments.insertBefore(wrapper, comments.firstChild);
  505. });
  506. }
  507. }
  508. }
  509. </script>