Profile.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. <template>
  2. <div>
  3. <div class="d-flex justify-content-center py-5 my-5" v-if="loading">
  4. <img src="/img/pixelfed-icon-grey.svg" class="">
  5. </div>
  6. <div v-if="!loading">
  7. <div class="bg-white py-5 border-bottom">
  8. <div class="container">
  9. <div class="row">
  10. <div class="col-12 col-md-4 d-flex">
  11. <div class="profile-avatar mx-auto">
  12. <img class="rounded-circle box-shadow" :src="profile.avatar" width="172px" height="172px">
  13. </div>
  14. </div>
  15. <div class="col-12 col-md-8 d-flex align-items-center">
  16. <div class="profile-details">
  17. <div class="username-bar pb-2 d-flex align-items-center">
  18. <span class="font-weight-ultralight h1">{{profile.username}}</span>
  19. <span class="pl-4" v-if="profile.is_admin">
  20. <span class="btn btn-outline-danger font-weight-bold py-0">ADMIN</span>
  21. </span>
  22. <span class="pl-4" v-if="owner">
  23. <a class="fas fa-cog fa-lg text-muted" href="/settings/home"></a>
  24. </span>
  25. <span v-if="profile.id != user.id && user.hasOwnProperty('id')">
  26. <span class="pl-4" v-if="relationship.following == true">
  27. <button type="button" class="btn btn-outline-secondary font-weight-bold px-4 py-0" v-on:click="followProfile()">Unfollow</button>
  28. </span>
  29. <span class="pl-4" v-if="!relationship.following">
  30. <button type="button" class="btn btn-primary font-weight-bold px-4 py-0" v-on:click="followProfile()">Follow</button>
  31. </span>
  32. </span>
  33. </div>
  34. <div class="profile-stats pb-3 d-inline-flex lead">
  35. <div class="font-weight-light pr-5">
  36. <a class="text-dark" :href="profile.url">
  37. <span class="font-weight-bold">{{profile.statuses_count}}</span>
  38. Posts
  39. </a>
  40. </div>
  41. <div class="font-weight-light pr-5">
  42. <a class="text-dark cursor-pointer" v-on:click="followersModal()">
  43. <span class="font-weight-bold">{{profile.followers_count}}</span>
  44. Followers
  45. </a>
  46. </div>
  47. <div class="font-weight-light pr-5">
  48. <a class="text-dark cursor-pointer" v-on:click="followingModal()">
  49. <span class="font-weight-bold">{{profile.following_count}}</span>
  50. Following
  51. </a>
  52. </div>
  53. </div>
  54. <p class="lead mb-0 d-flex align-items-center">
  55. <span class="font-weight-bold pr-3">{{profile.display_name}}</span>
  56. </p>
  57. <div v-if="profile.note" class="mb-0 lead" v-html="profile.note"></div>
  58. <p v-if="profile.website" class="mb-0"><a :href="profile.website" class="font-weight-bold" rel="me external nofollow noopener" target="_blank">{{profile.website}}</a></p>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. <div>
  65. <ul class="nav nav-topbar d-flex justify-content-center border-0">
  66. <!-- <li class="nav-item">
  67. <a class="nav-link active font-weight-bold text-uppercase" :href="profile.url">Posts</a>
  68. </li>
  69. -->
  70. <li class="nav-item">
  71. <a :class="this.mode == 'grid' ? 'nav-link font-weight-bold text-uppercase active' : 'nav-link font-weight-bold text-uppercase'" href="#" v-on:click.prevent="switchMode('grid')"><i class="fas fa-th"></i></a>
  72. </li>
  73. <!-- <li class="nav-item">
  74. <a :class="this.mode == 'masonry' ? 'nav-link font-weight-bold text-uppercase active' : 'nav-link font-weight-bold text-uppercase'" href="#" v-on:click.prevent="switchMode('masonry')"><i class="fas fa-th-large"></i></a>
  75. </li> -->
  76. <li class="nav-item">
  77. <a :class="this.mode == 'list' ? 'nav-link font-weight-bold text-uppercase active' : 'nav-link font-weight-bold text-uppercase'" href="#" v-on:click.prevent="switchMode('list')"><i class="fas fa-th-list"></i></a>
  78. </li>
  79. <li class="nav-item" v-if="owner">
  80. <a class="nav-link font-weight-bold text-uppercase" :href="profile.url + '/saved'">Saved</a>
  81. </li>
  82. </ul>
  83. </div>
  84. <div class="container">
  85. <div class="profile-timeline mt-2 mt-md-4">
  86. <div class="row" v-if="mode == 'grid'">
  87. <div class="col-4 p-0 p-sm-2 p-md-3" v-for="(s, index) in timeline">
  88. <a class="card info-overlay card-md-border-0" :href="s.url">
  89. <div class="square">
  90. <span v-if="s.pf_type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  91. <span v-if="s.pf_type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  92. <span v-if="s.pf_type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  93. <div class="square-content" v-bind:style="previewBackground(s)">
  94. </div>
  95. <div class="info-overlay-text">
  96. <h5 class="text-white m-auto font-weight-bold">
  97. <span>
  98. <span class="far fa-heart fa-lg p-2 d-flex-inline"></span>
  99. <span class="d-flex-inline">{{s.favourites_count}}</span>
  100. </span>
  101. <span>
  102. <span class="fas fa-retweet fa-lg p-2 d-flex-inline"></span>
  103. <span class="d-flex-inline">{{s.reblogs_count}}</span>
  104. </span>
  105. </h5>
  106. </div>
  107. </div>
  108. </a>
  109. </div>
  110. </div>
  111. <div class="row" v-if="mode == 'list'">
  112. <div class="col-md-8 col-lg-8 offset-md-2 pt-2 px-0 my-3 timeline">
  113. <div class="card mb-4 status-card card-md-rounded-0" :data-status-id="status.id" v-for="(status, index) in timeline" :key="status.id">
  114. <div class="card-header d-inline-flex align-items-center bg-white">
  115. <img v-bind:src="status.account.avatar" width="32px" height="32px" style="border-radius: 32px;">
  116. <a class="username font-weight-bold pl-2 text-dark" v-bind:href="status.account.url">
  117. {{status.account.username}}
  118. </a>
  119. <div class="text-right" style="flex-grow:1;">
  120. <div class="dropdown">
  121. <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">
  122. <span class="fas fa-ellipsis-v fa-lg text-muted"></span>
  123. </button>
  124. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
  125. <a class="dropdown-item font-weight-bold" :href="status.url">Go to post</a>
  126. <span v-bind:class="[statusOwner(status) ? 'd-none' : '']">
  127. <a class="dropdown-item font-weight-bold" :href="reportUrl(status)">Report</a>
  128. <a class="dropdown-item font-weight-bold" v-on:click="muteProfile(status)">Mute Profile</a>
  129. <a class="dropdown-item font-weight-bold" v-on:click="blockProfile(status)">Block Profile</a>
  130. </span>
  131. <span v-bind:class="[statusOwner(status) ? '' : 'd-none']">
  132. <a class="dropdown-item font-weight-bold" :href="editUrl(status)">Edit</a>
  133. <a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost(status)">Delete</a>
  134. </span>
  135. </div>
  136. </div>
  137. </div>
  138. </div>
  139. <div class="postPresenterContainer">
  140. <div v-if="status.pf_type === 'photo'" class="w-100">
  141. <photo-presenter :status="status"></photo-presenter>
  142. </div>
  143. <div v-else-if="status.pf_type === 'video'" class="w-100">
  144. <video-presenter :status="status"></video-presenter>
  145. </div>
  146. <div v-else-if="status.pf_type === 'photo:album'" class="w-100">
  147. <photo-album-presenter :status="status"></photo-album-presenter>
  148. </div>
  149. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  150. <video-album-presenter :status="status"></video-album-presenter>
  151. </div>
  152. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  153. <mixed-album-presenter :status="status"></mixed-album-presenter>
  154. </div>
  155. <div v-else class="w-100">
  156. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  157. </div>
  158. </div>
  159. <div class="card-body">
  160. <div class="reactions my-1">
  161. <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>
  162. <h3 class="far fa-comment pr-3 m-0 cursor-pointer" title="Comment" v-on:click="commentFocus(status, $event)"></h3>
  163. <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>
  164. </div>
  165. <div class="likes font-weight-bold">
  166. <span class="like-count">{{status.favourites_count}}</span> {{status.favourites_count == 1 ? 'like' : 'likes'}}
  167. </div>
  168. <div class="caption">
  169. <p class="mb-2 read-more" style="overflow: hidden;">
  170. <span class="username font-weight-bold">
  171. <bdi><a class="text-dark" :href="status.account.url">{{status.account.username}}</a></bdi>
  172. </span>
  173. <span v-html="status.content"></span>
  174. </p>
  175. </div>
  176. <div class="comments">
  177. </div>
  178. <div class="timestamp pt-1">
  179. <p class="small text-uppercase mb-0">
  180. <a :href="status.url" class="text-muted">
  181. <timeago :datetime="status.created_at" :auto-update="60" :converter-options="{includeSeconds:true}" :title="timestampFormat(status.created_at)" v-b-tooltip.hover.bottom></timeago>
  182. </a>
  183. </p>
  184. </div>
  185. </div>
  186. <div class="card-footer bg-white d-none">
  187. <form class="" v-on:submit.prevent="commentSubmit(status, $event)">
  188. <input type="hidden" name="item" value="">
  189. <input class="form-control status-reply-input" name="comment" placeholder="Add a comment…" autocomplete="off">
  190. </form>
  191. </div>
  192. </div>
  193. </div>
  194. </div>
  195. <div class="masonry-grid" v-if="mode == 'masonry'">
  196. <div class="d-inline p-0 p-sm-2 p-md-3 masonry-item" v-for="(status, index) in timeline">
  197. <a class="" v-on:click.prevent="statusModal(status)" :href="status.url">
  198. <img :src="previewUrl(status)" :class="'o-'+masonryOrientation(status)">
  199. </a>
  200. </div>
  201. </div>
  202. <div v-if="timeline.length">
  203. <infinite-loading @infinite="infiniteTimeline">
  204. <div slot="no-more"></div>
  205. <div slot="no-results"></div>
  206. </infinite-loading>
  207. </div>
  208. </div>
  209. </div>
  210. </div>
  211. <!-- <b-modal id="statusModal" ref="statusModalRef" hide-footer hide-header v-if="modalStatus" size="lg" v-on:hide.native="closeModal()" lazy class="border-0">
  212. <post-component v-bind:status-template="modalStatus.pf_type" v-bind:status-id="modalStatus.id" v-bind:status-username="modalStatus.account.username" v-bind:status-url="modalStatus.url" v-bind:status-profile-url="modalStatus.account.url" v-bind:status-avatar="modalStatus.account.avatar"></post-component>
  213. </b-modal> -->
  214. <b-modal ref="followingModal"
  215. id="following-modal"
  216. hide-footer
  217. centered
  218. title="Following"
  219. body-class="list-group-flush p-0">
  220. <div class="list-group">
  221. <div class="list-group-item border-0" v-for="(user, index) in following" :key="'following_'+index">
  222. <div class="media">
  223. <a :href="user.url">
  224. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  225. </a>
  226. <div class="media-body">
  227. <p class="mb-0" style="font-size: 14px">
  228. <a :href="user.url" class="font-weight-bold text-dark">
  229. {{user.username}}
  230. </a>
  231. </p>
  232. <p class="text-muted mb-0" style="font-size: 14px">
  233. {{user.display_name}}
  234. </p>
  235. </div>
  236. </div>
  237. </div>
  238. <div v-if="followingMore" class="list-group-item text-center" v-on:click="followingLoadMore()">
  239. <p class="mb-0 small text-muted font-weight-light cursor-pointer">Load more</p>
  240. </div>
  241. </div>
  242. </b-modal>
  243. <b-modal ref="followerModal"
  244. id="follower-modal"
  245. hide-footer
  246. centered
  247. title="Followers"
  248. body-class="list-group-flush p-0">
  249. <div class="list-group">
  250. <div class="list-group-item border-0" v-for="(user, index) in followers" :key="'follower_'+index">
  251. <div class="media">
  252. <a :href="user.url">
  253. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  254. </a>
  255. <div class="media-body">
  256. <p class="mb-0" style="font-size: 14px">
  257. <a :href="user.url" class="font-weight-bold text-dark">
  258. {{user.username}}
  259. </a>
  260. </p>
  261. <p class="text-muted mb-0" style="font-size: 14px">
  262. {{user.display_name}}
  263. </p>
  264. </div>
  265. </div>
  266. </div>
  267. <div v-if="followerMore" class="list-group-item text-center" v-on:click="followersLoadMore()">
  268. <p class="mb-0 small text-muted font-weight-light cursor-pointer">Load more</p>
  269. </div>
  270. </div>
  271. </b-modal>
  272. </div>
  273. </template>
  274. <!-- <style type="text/css" scoped="">
  275. .modal-body {
  276. padding: 0;
  277. margin: 0;
  278. }
  279. @media (min-width: 992px) {
  280. .modal-lg, .modal-xl {
  281. max-width: 900px;
  282. }
  283. }
  284. </style> -->
  285. <style type="text/css" scoped>
  286. .o-square {
  287. max-width: 320px;
  288. }
  289. .o-portrait {
  290. max-width: 320px;
  291. }
  292. .o-landscape {
  293. max-width: 320px;
  294. }
  295. .post-icon {
  296. color: #fff;
  297. position:relative;
  298. margin-top: 10px;
  299. z-index: 9;
  300. opacity: 0.6;
  301. text-shadow: 3px 3px 16px #272634;
  302. }
  303. </style>
  304. <script type="text/javascript">
  305. export default {
  306. props: [
  307. 'profile-id'
  308. ],
  309. data() {
  310. return {
  311. profile: {},
  312. user: {},
  313. timeline: [],
  314. timelinePage: 2,
  315. min_id: 0,
  316. max_id: 0,
  317. loading: true,
  318. owner: false,
  319. mode: 'grid',
  320. modes: ['grid', 'list', 'masonry'],
  321. modalStatus: false,
  322. relationship: {},
  323. followers: [],
  324. followerCursor: 1,
  325. followerMore: true,
  326. following: [],
  327. followingCursor: 1,
  328. followingMore: true
  329. }
  330. },
  331. beforeMount() {
  332. this.fetchProfile();
  333. },
  334. mounted() {
  335. },
  336. updated() {
  337. },
  338. methods: {
  339. fetchProfile() {
  340. axios.get('/api/v1/accounts/' + this.profileId).then(res => {
  341. this.profile = res.data;
  342. });
  343. axios.get('/api/v1/accounts/verify_credentials').then(res => {
  344. this.user = res.data;
  345. });
  346. axios.get('/api/v1/accounts/relationships', {
  347. params: {
  348. 'id[]': this.profileId
  349. }
  350. }).then(res => {
  351. this.relationship = res.data[0];
  352. });
  353. let apiUrl = '/api/v1/accounts/' + this.profileId + '/statuses';
  354. axios.get(apiUrl, {
  355. params: {
  356. only_media: true,
  357. min_id: 1,
  358. }
  359. })
  360. .then(res => {
  361. let data = res.data;
  362. this.timeline = data;
  363. let ids = data.map(status => status.id);
  364. this.min_id = Math.max(...ids);
  365. this.max_id = Math.min(...ids);
  366. this.modalStatus = _.first(res.data);
  367. this.loading = false;
  368. this.ownerCheck();
  369. }).catch(err => {
  370. swal(
  371. 'Oops, something went wrong',
  372. 'Please release the page.',
  373. 'error'
  374. );
  375. });
  376. },
  377. ownerCheck() {
  378. this.owner = this.profile.id === this.user.id;
  379. },
  380. infiniteTimeline($state) {
  381. let apiUrl = '/api/v1/accounts/' + this.profileId + '/statuses';
  382. axios.get(apiUrl, {
  383. params: {
  384. only_media: true,
  385. max_id: this.max_id
  386. },
  387. }).then(res => {
  388. if (res.data.length && this.loading == false) {
  389. let data = res.data;
  390. this.timeline.push(...data);
  391. let ids = data.map(status => status.id);
  392. this.max_id = Math.min(...ids);
  393. this.loading = false;
  394. $state.loaded();
  395. } else {
  396. $state.complete();
  397. }
  398. });
  399. },
  400. previewUrl(status) {
  401. return status.media_attachments[0].preview_url;
  402. },
  403. previewBackground(status) {
  404. let preview = this.previewUrl(status);
  405. return 'background-image: url(' + preview + ');';
  406. },
  407. switchMode(mode) {
  408. this.mode = _.indexOf(this.modes, mode) ? mode : 'grid';
  409. if(this.mode == 'masonry') {
  410. $('.masonry').masonry({
  411. columnWidth: 200,
  412. itemSelector: '.masonry-item'
  413. });
  414. }
  415. },
  416. reportUrl(status) {
  417. let type = status.in_reply_to ? 'comment' : 'post';
  418. let id = status.id;
  419. return '/i/report?type=' + type + '&id=' + id;
  420. },
  421. commentFocus(status, $event) {
  422. let el = event.target;
  423. let card = el.parentElement.parentElement.parentElement;
  424. let comments = card.getElementsByClassName('comments')[0];
  425. if(comments.children.length == 0) {
  426. comments.classList.add('mb-2');
  427. this.fetchStatusComments(status, card);
  428. }
  429. let footer = card.querySelectorAll('.card-footer')[0];
  430. let input = card.querySelectorAll('.status-reply-input')[0];
  431. if(footer.classList.contains('d-none') == true) {
  432. footer.classList.remove('d-none');
  433. input.focus();
  434. } else {
  435. footer.classList.add('d-none');
  436. input.blur();
  437. }
  438. },
  439. likeStatus(status, $event) {
  440. if($('body').hasClass('loggedIn') == false) {
  441. return;
  442. }
  443. axios.post('/i/like', {
  444. item: status.id
  445. }).then(res => {
  446. status.favourites_count = res.data.count;
  447. if(status.favourited == true) {
  448. status.favourited = false;
  449. } else {
  450. status.favourited = true;
  451. }
  452. }).catch(err => {
  453. swal('Error', 'Something went wrong, please try again later.', 'error');
  454. });
  455. },
  456. shareStatus(status, $event) {
  457. if($('body').hasClass('loggedIn') == false) {
  458. return;
  459. }
  460. axios.post('/i/share', {
  461. item: status.id
  462. }).then(res => {
  463. status.reblogs_count = res.data.count;
  464. if(status.reblogged == true) {
  465. status.reblogged = false;
  466. } else {
  467. status.reblogged = true;
  468. }
  469. }).catch(err => {
  470. swal('Error', 'Something went wrong, please try again later.', 'error');
  471. });
  472. },
  473. timestampFormat(timestamp) {
  474. let ts = new Date(timestamp);
  475. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  476. },
  477. editUrl(status) {
  478. return status.url + '/edit';
  479. },
  480. redirect(url) {
  481. window.location.href = url;
  482. return;
  483. },
  484. replyUrl(status) {
  485. let username = this.profile.username;
  486. let id = status.account.id == this.profile.id ? status.id : status.in_reply_to_id;
  487. return '/p/' + username + '/' + id;
  488. },
  489. mentionUrl(status) {
  490. let username = status.account.username;
  491. let id = status.id;
  492. return '/p/' + username + '/' + id;
  493. },
  494. statusOwner(status) {
  495. let sid = status.account.id;
  496. let uid = this.profile.id;
  497. if(sid == uid) {
  498. return true;
  499. } else {
  500. return false;
  501. }
  502. },
  503. fetchStatusComments(status, card) {
  504. axios.get('/api/v2/status/'+status.id+'/replies')
  505. .then(res => {
  506. let comments = card.querySelectorAll('.comments')[0];
  507. let data = res.data;
  508. data.forEach(function(i, k) {
  509. let username = document.createElement('a');
  510. username.classList.add('font-weight-bold');
  511. username.classList.add('text-dark');
  512. username.classList.add('mr-2');
  513. username.setAttribute('href', i.account.url);
  514. username.textContent = i.account.username;
  515. let text = document.createElement('span');
  516. text.innerHTML = i.content;
  517. let comment = document.createElement('p');
  518. comment.classList.add('read-more');
  519. comment.classList.add('mb-0');
  520. comment.appendChild(username);
  521. comment.appendChild(text);
  522. comments.appendChild(comment);
  523. });
  524. }).catch(err => {
  525. })
  526. },
  527. muteProfile(status) {
  528. if($('body').hasClass('loggedIn') == false) {
  529. return;
  530. }
  531. axios.post('/i/mute', {
  532. type: 'user',
  533. item: status.account.id
  534. }).then(res => {
  535. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  536. swal('Success', 'You have successfully muted ' + status.account.acct, 'success');
  537. }).catch(err => {
  538. swal('Error', 'Something went wrong. Please try again later.', 'error');
  539. });
  540. },
  541. blockProfile(status) {
  542. if($('body').hasClass('loggedIn') == false) {
  543. return;
  544. }
  545. axios.post('/i/block', {
  546. type: 'user',
  547. item: status.account.id
  548. }).then(res => {
  549. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  550. swal('Success', 'You have successfully blocked ' + status.account.acct, 'success');
  551. }).catch(err => {
  552. swal('Error', 'Something went wrong. Please try again later.', 'error');
  553. });
  554. },
  555. deletePost(status, index) {
  556. if($('body').hasClass('loggedIn') == false || status.account.id !== this.profile.id) {
  557. return;
  558. }
  559. axios.post('/i/delete', {
  560. type: 'status',
  561. item: status.id
  562. }).then(res => {
  563. this.feed.splice(index,1);
  564. swal('Success', 'You have successfully deleted this post', 'success');
  565. }).catch(err => {
  566. swal('Error', 'Something went wrong. Please try again later.', 'error');
  567. });
  568. },
  569. commentSubmit(status, $event) {
  570. let id = status.id;
  571. let form = $event.target;
  572. let input = $(form).find('input[name="comment"]');
  573. let comment = input.val();
  574. let comments = form.parentElement.parentElement.getElementsByClassName('comments')[0];
  575. axios.post('/i/comment', {
  576. item: id,
  577. comment: comment
  578. }).then(res => {
  579. input.val('');
  580. input.blur();
  581. let username = document.createElement('a');
  582. username.classList.add('font-weight-bold');
  583. username.classList.add('text-dark');
  584. username.classList.add('mr-2');
  585. username.setAttribute('href', this.user.url);
  586. username.textContent = this.user.username;
  587. let text = document.createElement('span');
  588. text.innerHTML = comment;
  589. let wrapper = document.createElement('p');
  590. wrapper.classList.add('read-more');
  591. wrapper.classList.add('mb-0');
  592. wrapper.appendChild(username);
  593. wrapper.appendChild(text);
  594. comments.insertBefore(wrapper, comments.firstChild);
  595. });
  596. },
  597. statusModal(status) {
  598. this.modalStatus = status;
  599. this.$refs.statusModalRef.show();
  600. },
  601. masonryOrientation(status) {
  602. let o = status.media_attachments[0].orientation;
  603. if(!o) {
  604. o = 'square';
  605. }
  606. return o;
  607. },
  608. followProfile() {
  609. axios.post('/i/follow', {
  610. item: this.profileId
  611. }).then(res => {
  612. if(this.relationship.following) {
  613. this.profile.followers_count--;
  614. if(this.profile.locked == true) {
  615. window.location.href = '/';
  616. }
  617. } else {
  618. this.profile.followers_count++;
  619. }
  620. this.relationship.following = !this.relationship.following;
  621. });
  622. },
  623. followingModal() {
  624. if(this.following.length > 0) {
  625. this.$refs.followingModal.show();
  626. return;
  627. }
  628. axios.get('/api/v1/accounts/'+this.profile.id+'/following', {
  629. params: {
  630. page: this.followingCursor
  631. }
  632. })
  633. .then(res => {
  634. this.following = res.data;
  635. this.followingCursor++;
  636. if(res.data.length < 10) {
  637. this.followingMore = false;
  638. }
  639. });
  640. this.$refs.followingModal.show();
  641. },
  642. followersModal() {
  643. if(this.followers.length > 0) {
  644. this.$refs.followerModal.show();
  645. return;
  646. }
  647. axios.get('/api/v1/accounts/'+this.profile.id+'/followers', {
  648. params: {
  649. page: this.followerCursor
  650. }
  651. })
  652. .then(res => {
  653. this.followers = res.data;
  654. this.followerCursor++;
  655. if(res.data.length < 10) {
  656. this.followerMore = false;
  657. }
  658. })
  659. this.$refs.followerModal.show();
  660. },
  661. followingLoadMore() {
  662. axios.get('/api/v1/accounts/'+this.profile.id+'/following', {
  663. params: {
  664. page: this.followingCursor
  665. }
  666. })
  667. .then(res => {
  668. if(res.data.length > 0) {
  669. this.following.push(...res.data);
  670. this.followingCursor++;
  671. }
  672. if(res.data.length < 10) {
  673. this.followingMore = false;
  674. }
  675. });
  676. },
  677. followersLoadMore() {
  678. axios.get('/api/v1/accounts/'+this.profile.id+'/followers', {
  679. params: {
  680. page: this.followerCursor
  681. }
  682. })
  683. .then(res => {
  684. if(res.data.length > 0) {
  685. this.followers.push(...res.data);
  686. this.followerCursor++;
  687. }
  688. if(res.data.length < 10) {
  689. this.followerMore = false;
  690. }
  691. });
  692. }
  693. }
  694. }
  695. </script>