RemoteProfile.vue 15 KB

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