RemoteProfile.vue 16 KB

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