RemoteProfile.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. <template>
  2. <div>
  3. <div v-if="relationship && relationship.blocking && warning" class="bg-white pt-3 border-bottom">
  4. <div class="container">
  5. <p class="text-center font-weight-bold">You are blocking this account</p>
  6. <p class="text-center font-weight-bold">Click <a href="#" class="cursor-pointer" @click.prevent="warning = false;">here</a> to view profile</p>
  7. </div>
  8. </div>
  9. <div v-if="loading" style="height: 80vh;" class="d-flex justify-content-center align-items-center">
  10. <img src="/img/pixelfed-icon-grey.svg" class="">
  11. </div>
  12. <div v-if="!loading && !warning" class="container">
  13. <div class="row">
  14. <div class="col-12 col-md-4 pt-5">
  15. <div class="card shadow-none border">
  16. <div class="card-header p-0 m-0">
  17. <img v-if="profile.header_bg" :src="profile.header_bg" style="width: 100%; height: 140px; object-fit: cover;">
  18. <div v-else class="bg-primary" style="width: 100%;height: 140px;"></div>
  19. </div>
  20. <div class="card-body pb-0">
  21. <div class="mt-n5 mb-3">
  22. <img class="rounded-circle p-1 border mt-n4 bg-white shadow" :src="profile.avatar" width="90px" height="90px;">
  23. <span class="float-right mt-n1">
  24. <span>
  25. <button v-if="relationship && relationship.following == false" class="btn btn-outline-light py-0 px-3 mt-n1" style="font-size:13px; font-weight: 500;" @click="followProfile();">Follow</button>
  26. <button v-if="relationship && relationship.following == true" class="btn btn-outline-light py-0 px-3 mt-n1" style="font-size:13px; font-weight: 500;" @click="unfollowProfile();">Unfollow</button>
  27. </span>
  28. <span class="mx-2">
  29. <a :href="'/account/direct/t/' + profile.id" class="btn btn-outline-light btn-sm mt-n1" style="padding-top:2px;padding-bottom:1px;">
  30. <i class="far fa-comment-dots cursor-pointer" style="font-size:13px;"></i>
  31. </a>
  32. </span>
  33. <span>
  34. <button class="btn btn-outline-light btn-sm mt-n1" @click="showCtxMenu()" style="padding-top:2px;padding-bottom:1px;">
  35. <i class="fas fa-cog cursor-pointer" style="font-size:13px;"></i>
  36. </button>
  37. </span>
  38. </span>
  39. </div>
  40. <p class="pl-2 h4 font-weight-bold mb-1">{{profile.display_name}}</p>
  41. <p class="pl-2 font-weight-bold mb-2"><a class="text-muted" :href="profile.url" @click.prevent="urlRedirectHandler(profile.url)">{{profile.acct}}</a></p>
  42. <p class="pl-2 text-muted small d-flex justify-content-between">
  43. <span>
  44. <span class="font-weight-bold text-dark">{{profile.statuses_count}}</span>
  45. <span>Posts</span>
  46. </span>
  47. <span>
  48. <span class="font-weight-bold text-dark">{{profile.following_count}}</span>
  49. <span>Following</span>
  50. </span>
  51. <span>
  52. <span class="font-weight-bold text-dark">{{profile.followers_count}}</span>
  53. <span>Followers</span>
  54. </span>
  55. </p>
  56. <p class="pl-2 text-muted small pt-2" v-html="profile.note"></p>
  57. </div>
  58. </div>
  59. <p class="small text-lighter p-2">Last updated: <time :datetime="profile.last_fetched_at">{{timeAgo(profile.last_fetched_at, 'ago')}}</time></p>
  60. <p class="card border-left-primary card-body small py-2 text-muted font-weight-bold shadow-none border-top border-bottom border-right">You are viewing a profile from a remote server, it may not contain up-to-date information.</p>
  61. </div>
  62. <div class="col-12 col-md-8 pt-5">
  63. <div class="row">
  64. <div class="col-12" v-for="(status, index) in feed" :key="'remprop' + index">
  65. <status-card
  66. :class="{'border-top': index === 0}"
  67. :status="status" />
  68. </div>
  69. <div v-if="feed.length == 0" class="col-12 mb-2">
  70. <div class="d-flex justify-content-center align-items-center bg-white border rounded" style="height:60vh;">
  71. <div class="text-center">
  72. <p class="lead">We haven't seen any posts from this account.</p>
  73. </div>
  74. </div>
  75. </div>
  76. <div v-else class="col-12 mt-4">
  77. <p v-if="showLoadMore" class="text-center mb-0 px-0">
  78. <button @click="loadMorePosts()" class="btn btn-outline-primary btn-block font-weight-bold">
  79. <span v-if="!loadingMore">Load More</span>
  80. <span v-else>
  81. <div class="spinner-border spinner-border-sm" role="status">
  82. <span class="sr-only">Loading...</span>
  83. </div>
  84. </span>
  85. </button>
  86. </p>
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. <b-modal ref="visitorContextMenu"
  92. id="visitor-context-menu"
  93. hide-footer
  94. hide-header
  95. centered
  96. size="sm"
  97. body-class="list-group-flush p-0">
  98. <div class="list-group" v-if="relationship">
  99. <div class="list-group-item cursor-pointer text-center rounded text-dark" @click="copyProfileLink">
  100. Copy Link
  101. </div>
  102. <div v-if="user && !owner && !relationship.muting" class="list-group-item cursor-pointer text-center rounded" @click="muteProfile">
  103. Mute
  104. </div>
  105. <div v-if="user && !owner && relationship.muting" class="list-group-item cursor-pointer text-center rounded" @click="unmuteProfile">
  106. Unmute
  107. </div>
  108. <div v-if="user && !owner" class="list-group-item cursor-pointer text-center rounded text-dark" @click="reportProfile">
  109. Report User
  110. </div>
  111. <div v-if="user && !owner && !relationship.blocking" class="list-group-item cursor-pointer text-center rounded text-dark" @click="blockProfile">
  112. Block
  113. </div>
  114. <div v-if="user && !owner && relationship.blocking" class="list-group-item cursor-pointer text-center rounded text-dark" @click="unblockProfile">
  115. Unblock
  116. </div>
  117. <div class="list-group-item cursor-pointer text-center rounded text-muted" @click="$refs.visitorContextMenu.hide()">
  118. Close
  119. </div>
  120. </div>
  121. </b-modal>
  122. <b-modal ref="ctxModal"
  123. id="ctx-modal"
  124. hide-header
  125. hide-footer
  126. centered
  127. rounded
  128. size="sm"
  129. body-class="list-group-flush p-0 rounded">
  130. <div class="list-group text-center">
  131. <div v-if="ctxMenuStatus && profile.id != profile.id" class="list-group-item rounded cursor-pointer font-weight-bold text-danger" @click="ctxMenuReportPost()">Report inappropriate</div>
  132. <div v-if="ctxMenuStatus && profile.id != profile.id && ctxMenuRelationship && ctxMenuRelationship.following" class="list-group-item rounded cursor-pointer font-weight-bold text-danger" @click="ctxMenuUnfollow()">Unfollow</div>
  133. <div v-if="ctxMenuStatus && profile.id != profile.id && ctxMenuRelationship && !ctxMenuRelationship.following" class="list-group-item rounded cursor-pointer font-weight-bold text-primary" @click="ctxMenuFollow()">Follow</div>
  134. <div class="list-group-item rounded cursor-pointer" @click="ctxMenuGoToPost()">Go to post</div>
  135. <div class="list-group-item rounded cursor-pointer" @click="ctxMenuCopyLink()">Copy Link</div>
  136. <div v-if="profile && profile.is_admin == true" class="list-group-item rounded cursor-pointer" @click="ctxModMenuShow()">Moderation Tools</div>
  137. <div v-if="ctxMenuStatus && (profile.is_admin || profile.id == profile.id)" class="list-group-item rounded cursor-pointer" @click="deletePost(ctxMenuStatus)">Delete</div>
  138. <div class="list-group-item rounded cursor-pointer text-lighter" @click="closeCtxMenu()">Cancel</div>
  139. </div>
  140. </b-modal>
  141. </div>
  142. </div>
  143. </template>
  144. <script type="text/javascript">
  145. import StatusCard from './partials/StatusCard.vue';
  146. export default {
  147. props: [
  148. 'profile-id',
  149. ],
  150. components: {
  151. StatusCard
  152. },
  153. data() {
  154. return {
  155. id: [],
  156. ids: [],
  157. user: false,
  158. profile: {},
  159. feed: [],
  160. min_id: null,
  161. max_id: null,
  162. loading: true,
  163. owner: false,
  164. layoutType: true,
  165. relationship: null,
  166. warning: false,
  167. ctxMenuStatus: false,
  168. ctxMenuRelationship: false,
  169. fetchingRemotePosts: false,
  170. showMutualFollowers: false,
  171. loadingMore: false,
  172. showLoadMore: true
  173. }
  174. },
  175. beforeMount() {
  176. this.fetchRelationships();
  177. this.fetchProfile();
  178. },
  179. updated() {
  180. document.querySelectorAll('.hashtag').forEach(function(i, e) {
  181. i.href = App.util.format.rewriteLinks(i);
  182. });
  183. },
  184. methods: {
  185. fetchProfile() {
  186. axios.get('/api/pixelfed/v1/accounts/verify_credentials').then(res => {
  187. this.user = res.data
  188. window._sharedData.curUser = res.data;
  189. window.App.util.navatar();
  190. });
  191. axios.get('/api/pixelfed/v1/accounts/' + this.profileId)
  192. .then(res => {
  193. this.profile = res.data;
  194. this.fetchPosts();
  195. });
  196. },
  197. fetchPosts() {
  198. let apiUrl = '/api/pixelfed/v1/accounts/' + this.profileId + '/statuses';
  199. axios.get(apiUrl, {
  200. params: {
  201. only_media: true,
  202. min_id: 1,
  203. }
  204. })
  205. .then(res => {
  206. let data = res.data
  207. .filter(status => status.media_attachments.length > 0);
  208. let ids = data.map(status => status.id);
  209. this.ids = ids;
  210. this.min_id = Math.max(...ids);
  211. this.max_id = Math.min(...ids);
  212. this.feed = data;
  213. this.loading = false;
  214. //this.loadSponsor();
  215. }).catch(err => {
  216. swal('Oops, something went wrong',
  217. 'Please release the page.',
  218. 'error');
  219. });
  220. },
  221. loadMorePosts() {
  222. this.loadingMore = true;
  223. let apiUrl = '/api/pixelfed/v1/accounts/' + this.profileId + '/statuses';
  224. axios.get(apiUrl, {
  225. params: {
  226. only_media: true,
  227. max_id: this.max_id,
  228. }
  229. })
  230. .then(res => {
  231. let data = res.data
  232. .filter(status => this.ids.indexOf(status.id) === -1)
  233. .filter(status => status.media_attachments.length > 0)
  234. .map(status => {
  235. return {
  236. id: status.id,
  237. caption: {
  238. text: status.content_text,
  239. html: status.content
  240. },
  241. count: {
  242. likes: status.favourites_count,
  243. shares: status.reblogs_count,
  244. comments: status.reply_count
  245. },
  246. thumb: status.media_attachments[0].url,
  247. media: status.media_attachments,
  248. timestamp: status.created_at,
  249. type: status.pf_type,
  250. url: status.url,
  251. sensitive: status.sensitive,
  252. cw: status.sensitive,
  253. spoiler_text: status.spoiler_text
  254. }
  255. });
  256. let ids = data.map(status => status.id);
  257. this.ids.push(...ids);
  258. this.max_id = Math.min(...ids);
  259. this.feed.push(...data);
  260. this.loadingMore = false;
  261. }).catch(err => {
  262. this.loadingMore = false;
  263. this.showLoadMore = false;
  264. });
  265. },
  266. fetchRelationships() {
  267. if(document.querySelectorAll('body')[0].classList.contains('loggedIn') == false) {
  268. return;
  269. }
  270. axios.get('/api/pixelfed/v1/accounts/relationships', {
  271. params: {
  272. 'id[]': this.profileId
  273. }
  274. }).then(res => {
  275. if(res.data.length) {
  276. this.relationship = res.data[0];
  277. if(res.data[0].blocking == true) {
  278. this.loading = false;
  279. this.warning = true;
  280. }
  281. }
  282. });
  283. },
  284. postPreviewUrl(post) {
  285. return 'background: url("'+post.thumb+'");background-size:cover';
  286. },
  287. timestampFormat(timestamp) {
  288. let ts = new Date(timestamp);
  289. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  290. },
  291. remoteProfileUrl(profile) {
  292. return '/i/web/profile/_/' + profile.id;
  293. },
  294. remotePostUrl(status) {
  295. return '/i/web/post/_/' + this.profile.id + '/' + status.id;
  296. },
  297. followProfile() {
  298. axios.post('/i/follow', {
  299. item: this.profileId
  300. }).then(res => {
  301. swal('Followed', 'You are now following ' + this.profile.username +'!', 'success');
  302. this.relationship.following = true;
  303. }).catch(err => {
  304. swal('Oops!', 'Something went wrong, please try again later.', 'error');
  305. });
  306. },
  307. unfollowProfile() {
  308. axios.post('/i/follow', {
  309. item: this.profileId
  310. }).then(res => {
  311. swal('Unfollowed', 'You are no longer following ' + this.profile.username +'.', 'warning');
  312. this.relationship.following = false;
  313. }).catch(err => {
  314. swal('Oops!', 'Something went wrong, please try again later.', 'error');
  315. });
  316. },
  317. showCtxMenu() {
  318. this.$refs.visitorContextMenu.show();
  319. },
  320. copyProfileLink() {
  321. navigator.clipboard.writeText(window.location.href);
  322. this.$refs.visitorContextMenu.hide();
  323. },
  324. muteProfile() {
  325. let id = this.profileId;
  326. axios.post('/i/mute', {
  327. type: 'user',
  328. item: id
  329. }).then(res => {
  330. this.fetchRelationships();
  331. this.$refs.visitorContextMenu.hide();
  332. swal('Success', 'You have successfully muted ' + this.profile.acct, 'success');
  333. }).catch(err => {
  334. swal('Error', 'Something went wrong. Please try again later.', 'error');
  335. });
  336. this.$refs.visitorContextMenu.hide();
  337. },
  338. unmuteProfile() {
  339. let id = this.profileId;
  340. axios.post('/i/unmute', {
  341. type: 'user',
  342. item: id
  343. }).then(res => {
  344. this.fetchRelationships();
  345. this.$refs.visitorContextMenu.hide();
  346. swal('Success', 'You have successfully unmuted ' + this.profile.acct, 'success');
  347. }).catch(err => {
  348. swal('Error', 'Something went wrong. Please try again later.', 'error');
  349. });
  350. this.$refs.visitorContextMenu.hide();
  351. },
  352. blockProfile() {
  353. let id = this.profileId;
  354. axios.post('/i/block', {
  355. type: 'user',
  356. item: id
  357. }).then(res => {
  358. this.warning = true;
  359. this.fetchRelationships();
  360. this.$refs.visitorContextMenu.hide();
  361. swal('Success', 'You have successfully blocked ' + this.profile.acct, 'success');
  362. }).catch(err => {
  363. swal('Error', 'Something went wrong. Please try again later.', 'error');
  364. });
  365. this.$refs.visitorContextMenu.hide();
  366. },
  367. unblockProfile() {
  368. let id = this.profileId;
  369. axios.post('/i/unblock', {
  370. type: 'user',
  371. item: id
  372. }).then(res => {
  373. this.warning = false;
  374. this.fetchRelationships();
  375. this.$refs.visitorContextMenu.hide();
  376. swal('Success', 'You have successfully unblocked ' + this.profile.acct, 'success');
  377. }).catch(err => {
  378. swal('Error', 'Something went wrong. Please try again later.', 'error');
  379. });
  380. this.$refs.visitorContextMenu.hide();
  381. },
  382. reportProfile() {
  383. window.location.href = '/l/i/report?type=profile&id=' + this.profileId;
  384. this.$refs.visitorContextMenu.hide();
  385. },
  386. ctxMenu(status) {
  387. this.ctxMenuStatus = status;
  388. let self = this;
  389. axios.get('/api/pixelfed/v1/accounts/relationships', {
  390. params: {
  391. 'id[]': self.profileId
  392. }
  393. }).then(res => {
  394. self.ctxMenuRelationship = res.data[0];
  395. self.$refs.ctxModal.show();
  396. });
  397. },
  398. closeCtxMenu() {
  399. this.ctxMenuStatus = false;
  400. this.ctxMenuRelationship = false;
  401. this.$refs.ctxModal.hide();
  402. },
  403. ctxMenuCopyLink() {
  404. let status = this.ctxMenuStatus;
  405. navigator.clipboard.writeText(status.url);
  406. this.closeCtxMenu();
  407. return;
  408. },
  409. ctxMenuGoToPost() {
  410. let status = this.ctxMenuStatus;
  411. window.location.href = this.statusUrl(status);
  412. this.closeCtxMenu();
  413. return;
  414. },
  415. statusUrl(status) {
  416. return '/i/web/post/_/' + this.profile.id + '/' + status.id;
  417. },
  418. deletePost(status) {
  419. if(this.user.is_admin == false) {
  420. return;
  421. }
  422. if(window.confirm('Are you sure you want to delete this post?') == false) {
  423. return;
  424. }
  425. axios.post('/i/delete', {
  426. type: 'status',
  427. item: status.id
  428. }).then(res => {
  429. this.feed = this.feed.filter(s => {
  430. return s.id != status.id;
  431. });
  432. this.$refs.ctxModal.hide();
  433. }).catch(err => {
  434. swal('Error', 'Something went wrong. Please try again later.', 'error');
  435. });
  436. },
  437. manuallyFetchRemotePosts($event) {
  438. this.fetchingRemotePosts = true;
  439. event.target.blur();
  440. swal(
  441. 'Fetching Remote Posts',
  442. 'Check back in a few minutes!',
  443. 'info'
  444. );
  445. },
  446. timeAgo(ts, suffix = false) {
  447. if(ts == null) {
  448. return 'never';
  449. }
  450. suffix = suffix ? ' ' + suffix : '';
  451. return App.util.format.timeAgo(ts) + suffix;
  452. },
  453. urlRedirectHandler(url) {
  454. let p = new URL(url);
  455. let path = '';
  456. if(p.hostname == window.location.hostname) {
  457. path = url;
  458. } else {
  459. path = '/i/redirect?url=';
  460. path += encodeURI(url);
  461. }
  462. window.location.href = path;
  463. }
  464. }
  465. }
  466. </script>
  467. <style type="text/css" scoped>
  468. @media (min-width: 1200px) {
  469. .container {
  470. max-width: 1050px;
  471. }
  472. }
  473. </style>