Profile.vue 19 KB

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