RemoteProfile.vue 14 KB

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