Profile.vue 24 KB

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