Profile.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  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="!owner && 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. <infinite-loading @infinite="infiniteTimeline">
  203. <div slot="no-more"></div>
  204. <div slot="no-results"></div>
  205. </infinite-loading>
  206. </div>
  207. </div>
  208. </div>
  209. <!-- <b-modal id="statusModal" ref="statusModalRef" hide-footer hide-header v-if="modalStatus" size="lg" v-on:hide.native="closeModal()" lazy class="border-0">
  210. <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>
  211. </b-modal> -->
  212. <b-modal ref="followingModal"
  213. id="following-modal"
  214. hide-footer
  215. centered
  216. title="Following"
  217. body-class="list-group-flush p-0">
  218. <div class="list-group">
  219. <div class="list-group-item border-0" v-for="(user, index) in following" :key="'following_'+index">
  220. <div class="media">
  221. <a :href="user.url">
  222. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  223. </a>
  224. <div class="media-body">
  225. <p class="mb-0" style="font-size: 14px">
  226. <a :href="user.url" class="font-weight-bold text-dark">
  227. {{user.username}}
  228. </a>
  229. </p>
  230. <p class="text-muted mb-0" style="font-size: 14px">
  231. {{user.display_name}}
  232. </p>
  233. </div>
  234. </div>
  235. </div>
  236. <div v-if="followingMore" class="list-group-item text-center" v-on:click="followingLoadMore()">
  237. <p class="mb-0 small text-muted font-weight-light cursor-pointer">Load more</p>
  238. </div>
  239. </div>
  240. </b-modal>
  241. <b-modal ref="followerModal"
  242. id="follower-modal"
  243. hide-footer
  244. centered
  245. title="Followers"
  246. body-class="list-group-flush p-0">
  247. <div class="list-group">
  248. <div class="list-group-item border-0" v-for="(user, index) in followers" :key="'follower_'+index">
  249. <div class="media">
  250. <a :href="user.url">
  251. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  252. </a>
  253. <div class="media-body">
  254. <p class="mb-0" style="font-size: 14px">
  255. <a :href="user.url" class="font-weight-bold text-dark">
  256. {{user.username}}
  257. </a>
  258. </p>
  259. <p class="text-muted mb-0" style="font-size: 14px">
  260. {{user.display_name}}
  261. </p>
  262. </div>
  263. </div>
  264. </div>
  265. <div v-if="followerMore" class="list-group-item text-center" v-on:click="followersLoadMore()">
  266. <p class="mb-0 small text-muted font-weight-light cursor-pointer">Load more</p>
  267. </div>
  268. </div>
  269. </b-modal>
  270. </div>
  271. </template>
  272. <!-- <style type="text/css" scoped="">
  273. .modal-body {
  274. padding: 0;
  275. margin: 0;
  276. }
  277. @media (min-width: 992px) {
  278. .modal-lg, .modal-xl {
  279. max-width: 900px;
  280. }
  281. }
  282. </style> -->
  283. <style type="text/css" scoped>
  284. .o-square {
  285. max-width: 320px;
  286. }
  287. .o-portrait {
  288. max-width: 320px;
  289. }
  290. .o-landscape {
  291. max-width: 320px;
  292. }
  293. .post-icon {
  294. color: #fff;
  295. position:relative;
  296. margin-top: 10px;
  297. z-index: 9;
  298. opacity: 0.6;
  299. text-shadow: 3px 3px 16px #272634;
  300. }
  301. </style>
  302. <script type="text/javascript">
  303. export default {
  304. props: [
  305. 'profile-id'
  306. ],
  307. data() {
  308. return {
  309. profile: {},
  310. user: {},
  311. timeline: [],
  312. timelinePage: 2,
  313. loading: true,
  314. owner: false,
  315. mode: 'grid',
  316. modes: ['grid', 'list', 'masonry'],
  317. modalStatus: false,
  318. relationship: {},
  319. followers: [],
  320. followerCursor: 1,
  321. followerMore: true,
  322. following: [],
  323. followingCursor: 1,
  324. followingMore: true
  325. }
  326. },
  327. beforeMount() {
  328. this.fetchProfile();
  329. },
  330. mounted() {
  331. },
  332. updated() {
  333. },
  334. methods: {
  335. fetchProfile() {
  336. axios.get('/api/v1/accounts/' + this.profileId).then(res => {
  337. this.profile = res.data;
  338. this.loading = false;
  339. });
  340. axios.get('/api/v1/accounts/verify_credentials').then(res => {
  341. this.user = res.data;
  342. });
  343. axios.get('/api/v1/accounts/relationships', {
  344. params: {
  345. 'id[]': this.profileId
  346. }
  347. }).then(res => {
  348. this.relationship = res.data[0];
  349. });
  350. let apiUrl = '/api/v1/accounts/' + this.profileId + '/statuses';
  351. axios.get(apiUrl, {
  352. params: {
  353. only_media: true,
  354. page: 1,
  355. }
  356. })
  357. .then(res => {
  358. this.timeline = res.data;
  359. this.modalStatus = _.first(res.data);
  360. this.loading = false;
  361. this.ownerCheck();
  362. }).catch(err => {
  363. swal(
  364. 'Oops, something went wrong',
  365. 'Please release the page.',
  366. 'error'
  367. );
  368. });
  369. },
  370. ownerCheck() {
  371. this.owner = this.profile.id === this.user.id;
  372. },
  373. infiniteTimeline($state) {
  374. let apiUrl = '/api/v1/accounts/' + this.profileId + '/statuses';
  375. axios.get(apiUrl, {
  376. params: {
  377. page: this.timelinePage,
  378. only_media: true
  379. },
  380. }).then(res => {
  381. if (res.data.length && this.loading == false) {
  382. let data = res.data;
  383. this.timeline.push(...data);
  384. this.timelinePage += 1;
  385. $state.loaded();
  386. } else {
  387. $state.complete();
  388. }
  389. });
  390. },
  391. previewUrl(status) {
  392. return status.media_attachments[0].preview_url;
  393. },
  394. previewBackground(status) {
  395. let preview = this.previewUrl(status);
  396. return 'background-image: url(' + preview + ');';
  397. },
  398. switchMode(mode) {
  399. this.mode = _.indexOf(this.modes, mode) ? mode : 'grid';
  400. if(this.mode == 'masonry') {
  401. $('.masonry').masonry({
  402. columnWidth: 200,
  403. itemSelector: '.masonry-item'
  404. });
  405. }
  406. },
  407. reportUrl(status) {
  408. let type = status.in_reply_to ? 'comment' : 'post';
  409. let id = status.id;
  410. return '/i/report?type=' + type + '&id=' + id;
  411. },
  412. commentFocus(status, $event) {
  413. let el = event.target;
  414. let card = el.parentElement.parentElement.parentElement;
  415. let comments = card.getElementsByClassName('comments')[0];
  416. if(comments.children.length == 0) {
  417. comments.classList.add('mb-2');
  418. this.fetchStatusComments(status, card);
  419. }
  420. let footer = card.querySelectorAll('.card-footer')[0];
  421. let input = card.querySelectorAll('.status-reply-input')[0];
  422. if(footer.classList.contains('d-none') == true) {
  423. footer.classList.remove('d-none');
  424. input.focus();
  425. } else {
  426. footer.classList.add('d-none');
  427. input.blur();
  428. }
  429. },
  430. likeStatus(status, $event) {
  431. if($('body').hasClass('loggedIn') == false) {
  432. return;
  433. }
  434. axios.post('/i/like', {
  435. item: status.id
  436. }).then(res => {
  437. status.favourites_count = res.data.count;
  438. if(status.favourited == true) {
  439. status.favourited = false;
  440. } else {
  441. status.favourited = true;
  442. }
  443. }).catch(err => {
  444. swal('Error', 'Something went wrong, please try again later.', 'error');
  445. });
  446. },
  447. shareStatus(status, $event) {
  448. if($('body').hasClass('loggedIn') == false) {
  449. return;
  450. }
  451. axios.post('/i/share', {
  452. item: status.id
  453. }).then(res => {
  454. status.reblogs_count = res.data.count;
  455. if(status.reblogged == true) {
  456. status.reblogged = false;
  457. } else {
  458. status.reblogged = true;
  459. }
  460. }).catch(err => {
  461. swal('Error', 'Something went wrong, please try again later.', 'error');
  462. });
  463. },
  464. timestampFormat(timestamp) {
  465. let ts = new Date(timestamp);
  466. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  467. },
  468. editUrl(status) {
  469. return status.url + '/edit';
  470. },
  471. redirect(url) {
  472. window.location.href = url;
  473. return;
  474. },
  475. replyUrl(status) {
  476. let username = this.profile.username;
  477. let id = status.account.id == this.profile.id ? status.id : status.in_reply_to_id;
  478. return '/p/' + username + '/' + id;
  479. },
  480. mentionUrl(status) {
  481. let username = status.account.username;
  482. let id = status.id;
  483. return '/p/' + username + '/' + id;
  484. },
  485. statusOwner(status) {
  486. let sid = status.account.id;
  487. let uid = this.profile.id;
  488. if(sid == uid) {
  489. return true;
  490. } else {
  491. return false;
  492. }
  493. },
  494. fetchStatusComments(status, card) {
  495. axios.get('/api/v2/status/'+status.id+'/replies')
  496. .then(res => {
  497. let comments = card.querySelectorAll('.comments')[0];
  498. let data = res.data;
  499. data.forEach(function(i, k) {
  500. let username = document.createElement('a');
  501. username.classList.add('font-weight-bold');
  502. username.classList.add('text-dark');
  503. username.classList.add('mr-2');
  504. username.setAttribute('href', i.account.url);
  505. username.textContent = i.account.username;
  506. let text = document.createElement('span');
  507. text.innerHTML = i.content;
  508. let comment = document.createElement('p');
  509. comment.classList.add('read-more');
  510. comment.classList.add('mb-0');
  511. comment.appendChild(username);
  512. comment.appendChild(text);
  513. comments.appendChild(comment);
  514. });
  515. }).catch(err => {
  516. })
  517. },
  518. muteProfile(status) {
  519. if($('body').hasClass('loggedIn') == false) {
  520. return;
  521. }
  522. axios.post('/i/mute', {
  523. type: 'user',
  524. item: status.account.id
  525. }).then(res => {
  526. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  527. swal('Success', 'You have successfully muted ' + status.account.acct, 'success');
  528. }).catch(err => {
  529. swal('Error', 'Something went wrong. Please try again later.', 'error');
  530. });
  531. },
  532. blockProfile(status) {
  533. if($('body').hasClass('loggedIn') == false) {
  534. return;
  535. }
  536. axios.post('/i/block', {
  537. type: 'user',
  538. item: status.account.id
  539. }).then(res => {
  540. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  541. swal('Success', 'You have successfully blocked ' + status.account.acct, 'success');
  542. }).catch(err => {
  543. swal('Error', 'Something went wrong. Please try again later.', 'error');
  544. });
  545. },
  546. deletePost(status, index) {
  547. if($('body').hasClass('loggedIn') == false || status.account.id !== this.profile.id) {
  548. return;
  549. }
  550. axios.post('/i/delete', {
  551. type: 'status',
  552. item: status.id
  553. }).then(res => {
  554. this.feed.splice(index,1);
  555. swal('Success', 'You have successfully deleted this post', 'success');
  556. }).catch(err => {
  557. swal('Error', 'Something went wrong. Please try again later.', 'error');
  558. });
  559. },
  560. commentSubmit(status, $event) {
  561. let id = status.id;
  562. let form = $event.target;
  563. let input = $(form).find('input[name="comment"]');
  564. let comment = input.val();
  565. let comments = form.parentElement.parentElement.getElementsByClassName('comments')[0];
  566. axios.post('/i/comment', {
  567. item: id,
  568. comment: comment
  569. }).then(res => {
  570. input.val('');
  571. input.blur();
  572. let username = document.createElement('a');
  573. username.classList.add('font-weight-bold');
  574. username.classList.add('text-dark');
  575. username.classList.add('mr-2');
  576. username.setAttribute('href', this.user.url);
  577. username.textContent = this.user.username;
  578. let text = document.createElement('span');
  579. text.innerHTML = comment;
  580. let wrapper = document.createElement('p');
  581. wrapper.classList.add('read-more');
  582. wrapper.classList.add('mb-0');
  583. wrapper.appendChild(username);
  584. wrapper.appendChild(text);
  585. comments.insertBefore(wrapper, comments.firstChild);
  586. });
  587. },
  588. statusModal(status) {
  589. this.modalStatus = status;
  590. this.$refs.statusModalRef.show();
  591. },
  592. masonryOrientation(status) {
  593. let o = status.media_attachments[0].orientation;
  594. if(!o) {
  595. o = 'square';
  596. }
  597. return o;
  598. },
  599. followProfile() {
  600. axios.post('/i/follow', {
  601. item: this.profileId
  602. }).then(res => {
  603. if(this.relationship.following) {
  604. this.profile.followers_count--;
  605. } else {
  606. this.profile.followers_count++;
  607. }
  608. this.relationship.following = !this.relationship.following;
  609. });
  610. },
  611. followingModal() {
  612. if(this.following.length > 0) {
  613. this.$refs.followingModal.show();
  614. return;
  615. }
  616. axios.get('/api/v1/accounts/'+this.profile.id+'/following', {
  617. params: {
  618. page: this.followingCursor
  619. }
  620. })
  621. .then(res => {
  622. this.following = res.data;
  623. this.followingCursor++;
  624. if(res.data.length < 10) {
  625. this.followingMore = false;
  626. }
  627. });
  628. this.$refs.followingModal.show();
  629. },
  630. followersModal() {
  631. if(this.followers.length > 0) {
  632. this.$refs.followerModal.show();
  633. return;
  634. }
  635. axios.get('/api/v1/accounts/'+this.profile.id+'/followers', {
  636. params: {
  637. page: this.followerCursor
  638. }
  639. })
  640. .then(res => {
  641. this.followers = res.data;
  642. this.followerCursor++;
  643. if(res.data.length < 10) {
  644. this.followerMore = false;
  645. }
  646. })
  647. this.$refs.followerModal.show();
  648. },
  649. followingLoadMore() {
  650. axios.get('/api/v1/accounts/'+this.profile.id+'/following', {
  651. params: {
  652. page: this.followingCursor
  653. }
  654. })
  655. .then(res => {
  656. if(res.data.length > 0) {
  657. this.following.push(...res.data);
  658. this.followingCursor++;
  659. }
  660. if(res.data.length < 10) {
  661. this.followingMore = false;
  662. }
  663. });
  664. },
  665. followersLoadMore() {
  666. axios.get('/api/v1/accounts/'+this.profile.id+'/followers', {
  667. params: {
  668. page: this.followerCursor
  669. }
  670. })
  671. .then(res => {
  672. if(res.data.length > 0) {
  673. this.followers.push(...res.data);
  674. this.followerCursor++;
  675. }
  676. if(res.data.length < 10) {
  677. this.followerMore = false;
  678. }
  679. });
  680. }
  681. }
  682. }
  683. </script>