1
0

Profile.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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" :href="profile.url + '/followers'">
  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" :href="profile.url + '/following'">
  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. </div>
  213. </template>
  214. <!-- <style type="text/css" scoped="">
  215. .modal-body {
  216. padding: 0;
  217. margin: 0;
  218. }
  219. @media (min-width: 992px) {
  220. .modal-lg, .modal-xl {
  221. max-width: 900px;
  222. }
  223. }
  224. </style> -->
  225. <style type="text/css" scoped>
  226. .o-square {
  227. max-width: 320px;
  228. }
  229. .o-portrait {
  230. max-width: 320px;
  231. }
  232. .o-landscape {
  233. max-width: 320px;
  234. }
  235. .post-icon {
  236. color: #fff;
  237. position:relative;
  238. margin-top: 10px;
  239. z-index: 999999;
  240. opacity: 0.6;
  241. text-shadow: 3px 3px 16px #272634;
  242. }
  243. </style>
  244. <script type="text/javascript">
  245. export default {
  246. props: [
  247. 'profile-id'
  248. ],
  249. data() {
  250. return {
  251. profile: {},
  252. user: {},
  253. timeline: [],
  254. timelinePage: 2,
  255. loading: true,
  256. owner: false,
  257. mode: 'grid',
  258. modes: ['grid', 'list', 'masonry'],
  259. modalStatus: false,
  260. relationship: {}
  261. }
  262. },
  263. beforeMount() {
  264. this.fetchProfile();
  265. },
  266. mounted() {
  267. },
  268. updated() {
  269. },
  270. methods: {
  271. fetchProfile() {
  272. axios.get('/api/v1/accounts/' + this.profileId).then(res => {
  273. this.profile = res.data;
  274. });
  275. axios.get('/api/v1/accounts/verify_credentials').then(res => {
  276. this.user = res.data;
  277. });
  278. axios.get('/api/v1/accounts/relationships', {
  279. params: {
  280. 'id[]': this.profileId
  281. }
  282. }).then(res => {
  283. this.relationship = res.data[0];
  284. });
  285. let apiUrl = '/api/v1/accounts/' + this.profileId + '/statuses';
  286. axios.get(apiUrl, {
  287. params: {
  288. only_media: true,
  289. page: 1,
  290. }
  291. })
  292. .then(res => {
  293. this.timeline = res.data;
  294. this.modalStatus = _.first(res.data);
  295. this.loading = false;
  296. this.ownerCheck();
  297. }).catch(err => {
  298. swal(
  299. 'Oops, something went wrong',
  300. 'Please release the page.',
  301. 'error'
  302. );
  303. });
  304. },
  305. ownerCheck() {
  306. this.owner = this.profile.id === this.user.id;
  307. },
  308. infiniteTimeline($state) {
  309. let apiUrl = '/api/v1/accounts/' + this.profileId + '/statuses';
  310. axios.get(apiUrl, {
  311. params: {
  312. page: this.timelinePage,
  313. only_media: true
  314. },
  315. }).then(res => {
  316. if (res.data.length && this.loading == false) {
  317. let data = res.data;
  318. this.timeline.push(...data);
  319. this.timelinePage += 1;
  320. $state.loaded();
  321. this.loading = false;
  322. } else {
  323. $state.complete();
  324. }
  325. });
  326. },
  327. previewUrl(status) {
  328. return status.media_attachments[0].preview_url;
  329. },
  330. previewBackground(status) {
  331. let preview = this.previewUrl(status);
  332. return 'background-image: url(' + preview + ');';
  333. },
  334. switchMode(mode) {
  335. this.mode = _.indexOf(this.modes, mode) ? mode : 'grid';
  336. if(this.mode == 'masonry') {
  337. $('.masonry').masonry({
  338. columnWidth: 200,
  339. itemSelector: '.masonry-item'
  340. });
  341. }
  342. },
  343. reportUrl(status) {
  344. let type = status.in_reply_to ? 'comment' : 'post';
  345. let id = status.id;
  346. return '/i/report?type=' + type + '&id=' + id;
  347. },
  348. commentFocus(status, $event) {
  349. let el = event.target;
  350. let card = el.parentElement.parentElement.parentElement;
  351. let comments = card.getElementsByClassName('comments')[0];
  352. if(comments.children.length == 0) {
  353. comments.classList.add('mb-2');
  354. this.fetchStatusComments(status, card);
  355. }
  356. let footer = card.querySelectorAll('.card-footer')[0];
  357. let input = card.querySelectorAll('.status-reply-input')[0];
  358. if(footer.classList.contains('d-none') == true) {
  359. footer.classList.remove('d-none');
  360. input.focus();
  361. } else {
  362. footer.classList.add('d-none');
  363. input.blur();
  364. }
  365. },
  366. likeStatus(status, $event) {
  367. if($('body').hasClass('loggedIn') == false) {
  368. return;
  369. }
  370. axios.post('/i/like', {
  371. item: status.id
  372. }).then(res => {
  373. status.favourites_count = res.data.count;
  374. if(status.favourited == true) {
  375. status.favourited = false;
  376. } else {
  377. status.favourited = true;
  378. }
  379. }).catch(err => {
  380. swal('Error', 'Something went wrong, please try again later.', 'error');
  381. });
  382. },
  383. shareStatus(status, $event) {
  384. if($('body').hasClass('loggedIn') == false) {
  385. return;
  386. }
  387. axios.post('/i/share', {
  388. item: status.id
  389. }).then(res => {
  390. status.reblogs_count = res.data.count;
  391. if(status.reblogged == true) {
  392. status.reblogged = false;
  393. } else {
  394. status.reblogged = true;
  395. }
  396. }).catch(err => {
  397. swal('Error', 'Something went wrong, please try again later.', 'error');
  398. });
  399. },
  400. timestampFormat(timestamp) {
  401. let ts = new Date(timestamp);
  402. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  403. },
  404. editUrl(status) {
  405. return status.url + '/edit';
  406. },
  407. redirect(url) {
  408. window.location.href = url;
  409. return;
  410. },
  411. replyUrl(status) {
  412. let username = this.profile.username;
  413. let id = status.account.id == this.profile.id ? status.id : status.in_reply_to_id;
  414. return '/p/' + username + '/' + id;
  415. },
  416. mentionUrl(status) {
  417. let username = status.account.username;
  418. let id = status.id;
  419. return '/p/' + username + '/' + id;
  420. },
  421. statusOwner(status) {
  422. let sid = status.account.id;
  423. let uid = this.profile.id;
  424. if(sid == uid) {
  425. return true;
  426. } else {
  427. return false;
  428. }
  429. },
  430. fetchStatusComments(status, card) {
  431. axios.get('/api/v2/status/'+status.id+'/replies')
  432. .then(res => {
  433. let comments = card.querySelectorAll('.comments')[0];
  434. let data = res.data;
  435. data.forEach(function(i, k) {
  436. let username = document.createElement('a');
  437. username.classList.add('font-weight-bold');
  438. username.classList.add('text-dark');
  439. username.classList.add('mr-2');
  440. username.setAttribute('href', i.account.url);
  441. username.textContent = i.account.username;
  442. let text = document.createElement('span');
  443. text.innerHTML = i.content;
  444. let comment = document.createElement('p');
  445. comment.classList.add('read-more');
  446. comment.classList.add('mb-0');
  447. comment.appendChild(username);
  448. comment.appendChild(text);
  449. comments.appendChild(comment);
  450. });
  451. }).catch(err => {
  452. })
  453. },
  454. muteProfile(status) {
  455. if($('body').hasClass('loggedIn') == false) {
  456. return;
  457. }
  458. axios.post('/i/mute', {
  459. type: 'user',
  460. item: status.account.id
  461. }).then(res => {
  462. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  463. swal('Success', 'You have successfully muted ' + status.account.acct, 'success');
  464. }).catch(err => {
  465. swal('Error', 'Something went wrong. Please try again later.', 'error');
  466. });
  467. },
  468. blockProfile(status) {
  469. if($('body').hasClass('loggedIn') == false) {
  470. return;
  471. }
  472. axios.post('/i/block', {
  473. type: 'user',
  474. item: status.account.id
  475. }).then(res => {
  476. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  477. swal('Success', 'You have successfully blocked ' + status.account.acct, 'success');
  478. }).catch(err => {
  479. swal('Error', 'Something went wrong. Please try again later.', 'error');
  480. });
  481. },
  482. deletePost(status, index) {
  483. if($('body').hasClass('loggedIn') == false || status.account.id !== this.profile.id) {
  484. return;
  485. }
  486. axios.post('/i/delete', {
  487. type: 'status',
  488. item: status.id
  489. }).then(res => {
  490. this.feed.splice(index,1);
  491. swal('Success', 'You have successfully deleted this post', 'success');
  492. }).catch(err => {
  493. swal('Error', 'Something went wrong. Please try again later.', 'error');
  494. });
  495. },
  496. commentSubmit(status, $event) {
  497. let id = status.id;
  498. let form = $event.target;
  499. let input = $(form).find('input[name="comment"]');
  500. let comment = input.val();
  501. let comments = form.parentElement.parentElement.getElementsByClassName('comments')[0];
  502. axios.post('/i/comment', {
  503. item: id,
  504. comment: comment
  505. }).then(res => {
  506. input.val('');
  507. input.blur();
  508. let username = document.createElement('a');
  509. username.classList.add('font-weight-bold');
  510. username.classList.add('text-dark');
  511. username.classList.add('mr-2');
  512. username.setAttribute('href', this.user.url);
  513. username.textContent = this.user.username;
  514. let text = document.createElement('span');
  515. text.innerHTML = comment;
  516. let wrapper = document.createElement('p');
  517. wrapper.classList.add('read-more');
  518. wrapper.classList.add('mb-0');
  519. wrapper.appendChild(username);
  520. wrapper.appendChild(text);
  521. comments.insertBefore(wrapper, comments.firstChild);
  522. });
  523. },
  524. statusModal(status) {
  525. this.modalStatus = status;
  526. this.$refs.statusModalRef.show();
  527. },
  528. masonryOrientation(status) {
  529. let o = status.media_attachments[0].orientation;
  530. if(!o) {
  531. o = 'square';
  532. }
  533. return o;
  534. },
  535. followProfile() {
  536. axios.post('/i/follow', {
  537. item: this.profileId
  538. }).then(res => {
  539. if(this.relationship.following) {
  540. this.profile.followers_count--;
  541. } else {
  542. this.profile.followers_count++;
  543. }
  544. this.relationship.following = !this.relationship.following;
  545. });
  546. }
  547. }
  548. }
  549. </script>