Profile.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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. this.loading = false;
  343. });
  344. axios.get('/api/v1/accounts/verify_credentials').then(res => {
  345. this.user = res.data;
  346. });
  347. axios.get('/api/v1/accounts/relationships', {
  348. params: {
  349. 'id[]': this.profileId
  350. }
  351. }).then(res => {
  352. this.relationship = res.data[0];
  353. });
  354. let apiUrl = '/api/v1/accounts/' + this.profileId + '/statuses';
  355. axios.get(apiUrl, {
  356. params: {
  357. only_media: true,
  358. min_id: 1,
  359. }
  360. })
  361. .then(res => {
  362. let data = res.data;
  363. this.timeline = data;
  364. let ids = data.map(status => status.id);
  365. this.min_id = Math.max(...ids);
  366. this.max_id = Math.min(...ids);
  367. this.modalStatus = _.first(res.data);
  368. this.loading = false;
  369. this.ownerCheck();
  370. }).catch(err => {
  371. swal(
  372. 'Oops, something went wrong',
  373. 'Please release the page.',
  374. 'error'
  375. );
  376. });
  377. },
  378. ownerCheck() {
  379. this.owner = this.profile.id === this.user.id;
  380. },
  381. infiniteTimeline($state) {
  382. let apiUrl = '/api/v1/accounts/' + this.profileId + '/statuses';
  383. axios.get(apiUrl, {
  384. params: {
  385. only_media: true,
  386. max_id: this.max_id
  387. },
  388. }).then(res => {
  389. if (res.data.length && this.loading == false) {
  390. let data = res.data;
  391. this.timeline.push(...data);
  392. let ids = data.map(status => status.id);
  393. this.max_id = Math.min(...ids);
  394. this.loading = false;
  395. $state.loaded();
  396. } else {
  397. $state.complete();
  398. }
  399. });
  400. },
  401. previewUrl(status) {
  402. return status.media_attachments[0].preview_url;
  403. },
  404. previewBackground(status) {
  405. let preview = this.previewUrl(status);
  406. return 'background-image: url(' + preview + ');';
  407. },
  408. switchMode(mode) {
  409. this.mode = _.indexOf(this.modes, mode) ? mode : 'grid';
  410. if(this.mode == 'masonry') {
  411. $('.masonry').masonry({
  412. columnWidth: 200,
  413. itemSelector: '.masonry-item'
  414. });
  415. }
  416. },
  417. reportUrl(status) {
  418. let type = status.in_reply_to ? 'comment' : 'post';
  419. let id = status.id;
  420. return '/i/report?type=' + type + '&id=' + id;
  421. },
  422. commentFocus(status, $event) {
  423. let el = event.target;
  424. let card = el.parentElement.parentElement.parentElement;
  425. let comments = card.getElementsByClassName('comments')[0];
  426. if(comments.children.length == 0) {
  427. comments.classList.add('mb-2');
  428. this.fetchStatusComments(status, card);
  429. }
  430. let footer = card.querySelectorAll('.card-footer')[0];
  431. let input = card.querySelectorAll('.status-reply-input')[0];
  432. if(footer.classList.contains('d-none') == true) {
  433. footer.classList.remove('d-none');
  434. input.focus();
  435. } else {
  436. footer.classList.add('d-none');
  437. input.blur();
  438. }
  439. },
  440. likeStatus(status, $event) {
  441. if($('body').hasClass('loggedIn') == false) {
  442. return;
  443. }
  444. axios.post('/i/like', {
  445. item: status.id
  446. }).then(res => {
  447. status.favourites_count = res.data.count;
  448. if(status.favourited == true) {
  449. status.favourited = false;
  450. } else {
  451. status.favourited = true;
  452. }
  453. }).catch(err => {
  454. swal('Error', 'Something went wrong, please try again later.', 'error');
  455. });
  456. },
  457. shareStatus(status, $event) {
  458. if($('body').hasClass('loggedIn') == false) {
  459. return;
  460. }
  461. axios.post('/i/share', {
  462. item: status.id
  463. }).then(res => {
  464. status.reblogs_count = res.data.count;
  465. if(status.reblogged == true) {
  466. status.reblogged = false;
  467. } else {
  468. status.reblogged = true;
  469. }
  470. }).catch(err => {
  471. swal('Error', 'Something went wrong, please try again later.', 'error');
  472. });
  473. },
  474. timestampFormat(timestamp) {
  475. let ts = new Date(timestamp);
  476. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  477. },
  478. editUrl(status) {
  479. return status.url + '/edit';
  480. },
  481. redirect(url) {
  482. window.location.href = url;
  483. return;
  484. },
  485. replyUrl(status) {
  486. let username = this.profile.username;
  487. let id = status.account.id == this.profile.id ? status.id : status.in_reply_to_id;
  488. return '/p/' + username + '/' + id;
  489. },
  490. mentionUrl(status) {
  491. let username = status.account.username;
  492. let id = status.id;
  493. return '/p/' + username + '/' + id;
  494. },
  495. statusOwner(status) {
  496. let sid = status.account.id;
  497. let uid = this.profile.id;
  498. if(sid == uid) {
  499. return true;
  500. } else {
  501. return false;
  502. }
  503. },
  504. fetchStatusComments(status, card) {
  505. axios.get('/api/v2/status/'+status.id+'/replies')
  506. .then(res => {
  507. let comments = card.querySelectorAll('.comments')[0];
  508. let data = res.data;
  509. data.forEach(function(i, k) {
  510. let username = document.createElement('a');
  511. username.classList.add('font-weight-bold');
  512. username.classList.add('text-dark');
  513. username.classList.add('mr-2');
  514. username.setAttribute('href', i.account.url);
  515. username.textContent = i.account.username;
  516. let text = document.createElement('span');
  517. text.innerHTML = i.content;
  518. let comment = document.createElement('p');
  519. comment.classList.add('read-more');
  520. comment.classList.add('mb-0');
  521. comment.appendChild(username);
  522. comment.appendChild(text);
  523. comments.appendChild(comment);
  524. });
  525. }).catch(err => {
  526. })
  527. },
  528. muteProfile(status) {
  529. if($('body').hasClass('loggedIn') == false) {
  530. return;
  531. }
  532. axios.post('/i/mute', {
  533. type: 'user',
  534. item: status.account.id
  535. }).then(res => {
  536. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  537. swal('Success', 'You have successfully muted ' + status.account.acct, 'success');
  538. }).catch(err => {
  539. swal('Error', 'Something went wrong. Please try again later.', 'error');
  540. });
  541. },
  542. blockProfile(status) {
  543. if($('body').hasClass('loggedIn') == false) {
  544. return;
  545. }
  546. axios.post('/i/block', {
  547. type: 'user',
  548. item: status.account.id
  549. }).then(res => {
  550. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  551. swal('Success', 'You have successfully blocked ' + status.account.acct, 'success');
  552. }).catch(err => {
  553. swal('Error', 'Something went wrong. Please try again later.', 'error');
  554. });
  555. },
  556. deletePost(status, index) {
  557. if($('body').hasClass('loggedIn') == false || status.account.id !== this.profile.id) {
  558. return;
  559. }
  560. axios.post('/i/delete', {
  561. type: 'status',
  562. item: status.id
  563. }).then(res => {
  564. this.feed.splice(index,1);
  565. swal('Success', 'You have successfully deleted this post', 'success');
  566. }).catch(err => {
  567. swal('Error', 'Something went wrong. Please try again later.', 'error');
  568. });
  569. },
  570. commentSubmit(status, $event) {
  571. let id = status.id;
  572. let form = $event.target;
  573. let input = $(form).find('input[name="comment"]');
  574. let comment = input.val();
  575. let comments = form.parentElement.parentElement.getElementsByClassName('comments')[0];
  576. axios.post('/i/comment', {
  577. item: id,
  578. comment: comment
  579. }).then(res => {
  580. input.val('');
  581. input.blur();
  582. let username = document.createElement('a');
  583. username.classList.add('font-weight-bold');
  584. username.classList.add('text-dark');
  585. username.classList.add('mr-2');
  586. username.setAttribute('href', this.user.url);
  587. username.textContent = this.user.username;
  588. let text = document.createElement('span');
  589. text.innerHTML = comment;
  590. let wrapper = document.createElement('p');
  591. wrapper.classList.add('read-more');
  592. wrapper.classList.add('mb-0');
  593. wrapper.appendChild(username);
  594. wrapper.appendChild(text);
  595. comments.insertBefore(wrapper, comments.firstChild);
  596. });
  597. },
  598. statusModal(status) {
  599. this.modalStatus = status;
  600. this.$refs.statusModalRef.show();
  601. },
  602. masonryOrientation(status) {
  603. let o = status.media_attachments[0].orientation;
  604. if(!o) {
  605. o = 'square';
  606. }
  607. return o;
  608. },
  609. followProfile() {
  610. axios.post('/i/follow', {
  611. item: this.profileId
  612. }).then(res => {
  613. if(this.relationship.following) {
  614. this.profile.followers_count--;
  615. if(this.profile.locked == true) {
  616. window.location.href = '/';
  617. }
  618. } else {
  619. this.profile.followers_count++;
  620. }
  621. this.relationship.following = !this.relationship.following;
  622. });
  623. },
  624. followingModal() {
  625. if(this.following.length > 0) {
  626. this.$refs.followingModal.show();
  627. return;
  628. }
  629. axios.get('/api/v1/accounts/'+this.profile.id+'/following', {
  630. params: {
  631. page: this.followingCursor
  632. }
  633. })
  634. .then(res => {
  635. this.following = res.data;
  636. this.followingCursor++;
  637. if(res.data.length < 10) {
  638. this.followingMore = false;
  639. }
  640. });
  641. this.$refs.followingModal.show();
  642. },
  643. followersModal() {
  644. if(this.followers.length > 0) {
  645. this.$refs.followerModal.show();
  646. return;
  647. }
  648. axios.get('/api/v1/accounts/'+this.profile.id+'/followers', {
  649. params: {
  650. page: this.followerCursor
  651. }
  652. })
  653. .then(res => {
  654. this.followers = res.data;
  655. this.followerCursor++;
  656. if(res.data.length < 10) {
  657. this.followerMore = false;
  658. }
  659. })
  660. this.$refs.followerModal.show();
  661. },
  662. followingLoadMore() {
  663. axios.get('/api/v1/accounts/'+this.profile.id+'/following', {
  664. params: {
  665. page: this.followingCursor
  666. }
  667. })
  668. .then(res => {
  669. if(res.data.length > 0) {
  670. this.following.push(...res.data);
  671. this.followingCursor++;
  672. }
  673. if(res.data.length < 10) {
  674. this.followingMore = false;
  675. }
  676. });
  677. },
  678. followersLoadMore() {
  679. axios.get('/api/v1/accounts/'+this.profile.id+'/followers', {
  680. params: {
  681. page: this.followerCursor
  682. }
  683. })
  684. .then(res => {
  685. if(res.data.length > 0) {
  686. this.followers.push(...res.data);
  687. this.followerCursor++;
  688. }
  689. if(res.data.length < 10) {
  690. this.followerMore = false;
  691. }
  692. });
  693. }
  694. }
  695. }
  696. </script>