GroupProfile.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <template>
  2. <div class="group-profile-component w-100 h-100">
  3. <div v-if="!loaded" class="w-100 h-100">
  4. <div class="d-flex justify-content-center align-items-center mt-5">
  5. <div class="spinner-border" role="status">
  6. <span class="sr-only">Loading...</span>
  7. </div>
  8. </div>
  9. </div>
  10. <template v-else>
  11. <div class="bg-white mb-3 border-bottom">
  12. <div class="container-xl header">
  13. <div class="header-jumbotron"></div>
  14. <div class="header-profile-card">
  15. <img :src="profile.avatar" class="avatar" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'">
  16. <p class="name">
  17. {{ profile.display_name }}
  18. </p>
  19. <p class="username text-muted">
  20. <span v-if="profile.local">&commat;{{ profile.username }}</span>
  21. <span v-else>{{ profile.acct }}</span>
  22. <span v-if="profile.is_admin" class="text-danger ml-1" title="Site administrator" data-toggle="tooltip" data-placement="bottom"><i class="far fa-users-crown"></i></span>
  23. </p>
  24. </div>
  25. <!-- <hr> -->
  26. <div class="header-navbar">
  27. <div></div>
  28. <div>
  29. <a
  30. v-if="currentProfile.id === profile.id"
  31. class="btn btn-light font-weight-bold mr-2"
  32. href="/settings/home">
  33. <i class="fas fa-edit mr-1"></i> Edit Profile
  34. </a>
  35. <a
  36. v-if="relationship.following"
  37. class="btn btn-primary font-weight-bold mr-2"
  38. :href="profile.url">
  39. <i class="far fa-comment-alt-dots mr-1"></i> Message
  40. </a>
  41. <a
  42. v-if="relationship.following"
  43. class="btn btn-light font-weight-bold mr-2"
  44. :href="profile.url">
  45. <i class="fas fa-user-check mr-1"></i> {{ relationship.followed_by ? 'Friends' : 'Following' }}
  46. </a>
  47. <a
  48. v-if="!relationship.following"
  49. class="btn btn-light font-weight-bold mr-2"
  50. :href="profile.url">
  51. <i class="fas fa-user mr-1"></i> View Main Profile
  52. </a>
  53. <div class="dropdown">
  54. <button class="btn btn-light font-weight-bold dropdown-toggle" type="button" id="amenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  55. <i class="fas fa-ellipsis-h"></i>
  56. </button>
  57. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="amenu">
  58. <a v-if="currentProfile.id != profile.id" class="dropdown-item font-weight-bold" :href="`/i/report?type=user&id=${profile.id}`">Report</a>
  59. <a v-if="currentProfile.id == profile.id" class="dropdown-item font-weight-bold" href="#">Leave Group</a>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. <div class="w-100 h-100 group-profile-feed">
  67. <div class="container-xl">
  68. <div class="row">
  69. <div class="col-12 col-md-5">
  70. <div class="card card-body shadow-sm infolet">
  71. <h5 class="font-weight-bold mb-3">Intro</h5>
  72. <div v-if="!profile.local" class="media mb-3 align-items-center">
  73. <div class="media-icon">
  74. <i class="far fa-globe" title="User is from a remote server" data-toggle="tooltip" data-placement="bottom"></i>
  75. </div>
  76. <div class="media-body">
  77. Remote member from <strong>{{ profile.acct.split('@')[1] }}</strong>
  78. </div>
  79. </div>
  80. <!-- <div v-if="profile.note.length" class="media mb-3 align-items-center">
  81. <i class="far fa-book-user fa-lg text-lighter mr-3" title="User bio" data-toggle="tooltip" data-placement="bottom"></i>
  82. <div class="media-body">
  83. <span v-html="profile.note"></span>
  84. </div>
  85. </div> -->
  86. <div class="media align-items-center">
  87. <div class="media-icon">
  88. <i class="fas fa-users" title="User joined group on this date" data-toggle="tooltip" data-placement="bottom"></i>
  89. </div>
  90. <div class="media-body">
  91. {{ roleTitle }} of <strong>{{ group.name }}</strong> since {{ formatJoinedDate(profile.group?.joined) }}
  92. </div>
  93. </div>
  94. </div>
  95. <div v-if="canIntersect" class="card card-body shadow-sm infolet">
  96. <h5 class="font-weight-bold mb-3">Things in Common</h5>
  97. <div v-if="commonIntersects.friends.length" class="media mb-3 align-items-center" v-once>
  98. <div class="media-icon">
  99. <i class="far fa-user-friends"></i>
  100. </div>
  101. <div class="media-body">
  102. {{ commonIntersects.friends_count }} mutual friend<span v-if="commonIntersects.friends.length > 1">s</span> including
  103. <span v-for="(friend, index) in commonIntersects.friends"><a :href="friend.url" class="text-dark font-weight-bold">{{ friend.acct }}</a><span v-if="commonIntersects.friends.length > index + 1">, </span><span v-else> </span></span>
  104. <!-- <a href="#" class="text-dark font-weight-bold">dansup</a>, <a href="#" class="text-dark font-weight-bold">admin</a> and 1 other -->
  105. </div>
  106. </div>
  107. <!-- <div class="media mb-3 align-items-center">
  108. <div class="media-icon">
  109. <i class="fas fa-home"></i>
  110. </div>
  111. <div class="media-body">
  112. Lives in <strong>Canada</strong>
  113. </div>
  114. </div> -->
  115. <div v-if="commonIntersects.groups.length" class="media mb-3 align-items-center">
  116. <div class="media-icon">
  117. <i class="fas fa-users"></i>
  118. </div>
  119. <div class="media-body">
  120. Also member of <a :href="commonIntersects.groups[0].url" class="text-dark font-weight-bold">{{ commonIntersects.groups[0].name }}</a> and {{ commonIntersects.groups_count }} other groups
  121. </div>
  122. </div>
  123. <div v-if="commonIntersects.topics.length" class="media mb-0 align-items-center">
  124. <div class="media-icon">
  125. <i class="far fa-thumbs-up fa-lg text-lighter"></i>
  126. </div>
  127. <div class="media-body">
  128. Also interested in topics containing
  129. <span v-for="(topic, index) in commonIntersects.topics">
  130. <span v-if="commonIntersects.topics.length - 1 == index"> and </span><a :href="topic.url" class="font-weight-bold text-dark">#{{ topic.name }}</a><span v-if="commonIntersects.topics.length > index + 2">, </span>
  131. </span> hashtags
  132. </div>
  133. </div>
  134. </div>
  135. </div>
  136. <div class="col-12 col-md-7">
  137. <div class="card card-body shadow-sm">
  138. <h5 class="font-weight-bold mb-0">Group Posts</h5>
  139. </div>
  140. <div v-if="feedEmpty" class="pt-5 text-center">
  141. <h5>No New Posts</h5>
  142. <p>{{ profile.username }} hasn't posted anything yet in <strong>{{ group.name }}</strong>.</p>
  143. <a :href="group.url" class="font-weight-bold">Go Back</a>
  144. </div>
  145. <div v-if="feedLoaded" class="mt-2">
  146. <group-status
  147. v-for="(status, index) in feed"
  148. :key="'gps:' + status.id"
  149. :permalinkMode="true"
  150. :showGroupChevron="true"
  151. :group="group"
  152. :prestatus="status"
  153. :profile="profile"
  154. :group-id="group.id" />
  155. <div v-if="feed.length >= 1" :distance="800">
  156. <infinite-loading @infinite="infiniteFeed">
  157. <div slot="no-more"></div>
  158. <div slot="no-results"></div>
  159. </infinite-loading>
  160. </div>
  161. </div>
  162. </div>
  163. </div>
  164. </div>
  165. </div>
  166. </template>
  167. </div>
  168. </template>
  169. <script type="text/javascript">
  170. import GroupStatus from '@/groups/partials/GroupStatus.vue';
  171. export default {
  172. props: {
  173. gid: {
  174. type: String
  175. },
  176. pid: {
  177. type: String
  178. }
  179. },
  180. components: {
  181. 'group-status': GroupStatus
  182. },
  183. data() {
  184. return {
  185. loaded: false,
  186. currentProfile: {},
  187. roleTitle: 'Member',
  188. group: {},
  189. profile: {},
  190. relationship: {
  191. following: false,
  192. },
  193. feed: [],
  194. ids: [],
  195. feedLoaded: false,
  196. feedEmpty: false,
  197. page: 1,
  198. canIntersect: false,
  199. commonIntersects: []
  200. }
  201. },
  202. beforeMount() {
  203. $('body').css('background-color', '#f0f2f5');
  204. },
  205. mounted() {
  206. this.fetchGroup();
  207. this.$nextTick(() => {
  208. $('[data-toggle="tooltip"]').tooltip();
  209. });
  210. },
  211. methods: {
  212. fetchGroup() {
  213. axios.get('/api/v0/groups/' + this.gid)
  214. .then(res => {
  215. this.group = res.data;
  216. })
  217. .finally(() => {
  218. this.fetchSelfProfile();
  219. })
  220. },
  221. fetchSelfProfile() {
  222. axios.get('/api/pixelfed/v1/accounts/verify_credentials')
  223. .then(res => {
  224. this.currentProfile = res.data;
  225. })
  226. .catch(err => {
  227. this.$router.push('/groups/' + this.gid)
  228. })
  229. .finally(() => {
  230. this.fetchProfile();
  231. })
  232. this.$nextTick(() => {
  233. $('[data-toggle="tooltip"]').tooltip();
  234. });
  235. },
  236. fetchProfile() {
  237. axios.get('/api/v0/groups/accounts/' + this.gid + '/' + this.pid)
  238. .then(res => {
  239. this.profile = res.data;
  240. if(res.data.group.role == 'founder') {
  241. this.roleTitle = 'Admin';
  242. }
  243. })
  244. if(window._sharedData.user.id == this.pid) {
  245. this.fetchInitialFeed();
  246. return;
  247. }
  248. axios.get('/api/v1/accounts/relationships?id[]=' + this.pid)
  249. .then(res => {
  250. this.relationship = res.data[0];
  251. })
  252. .finally(() => {
  253. this.fetchInitialFeed();
  254. })
  255. },
  256. fetchInitialFeed() {
  257. if(window._sharedData.user && window._sharedData.user.id != this.pid) {
  258. this.fetchCommonIntersections();
  259. }
  260. axios.get(`/api/v0/groups/${this.gid}/user/${this.pid}/feed`)
  261. .then(res => {
  262. this.feed = res.data.filter(s => {
  263. return s.pf_type != 'reply:text' || s.account.id != this.profile.id;
  264. });
  265. this.feedLoaded = true;
  266. this.feedEmpty = this.feed.length == 0;
  267. this.page++;
  268. this.loaded = true;
  269. })
  270. .catch(err => {
  271. this.$router.push('/groups/' + this.gid);
  272. console.log(err)
  273. });
  274. },
  275. infiniteFeed($state) {
  276. if(this.feed.length == 0) {
  277. $state.complete();
  278. return;
  279. }
  280. axios.get(`/api/v0/groups/${this.group.id}/user/${this.profile.id}/feed`, {
  281. params: {
  282. page: this.page
  283. },
  284. }).then(res => {
  285. if (res.data.length) {
  286. let data = res.data.filter(s => {
  287. return s.pf_type != 'reply:text' || s.account.id != this.profile.id;
  288. });
  289. let self = this;
  290. data.forEach(d => {
  291. if(self.ids.indexOf(d.id) == -1) {
  292. self.ids.push(d.id);
  293. self.feed.push(d);
  294. }
  295. });
  296. $state.loaded();
  297. this.page++;
  298. } else {
  299. $state.complete();
  300. }
  301. });
  302. },
  303. fetchCommonIntersections() {
  304. axios.get('/api/v0/groups/member/intersect/common', {
  305. params: {
  306. gid: this.gid,
  307. pid: this.pid
  308. }
  309. }).then(res => {
  310. this.commonIntersects = res.data;
  311. this.canIntersect = res.data.groups.length || res.data.topics.length;
  312. });
  313. },
  314. formatJoinedDate(ts) {
  315. let date = new Date(ts);
  316. let options = { year: 'numeric', month: 'long' };
  317. let formatter = new Intl.DateTimeFormat('en-US', options);
  318. return formatter.format(date);
  319. }
  320. }
  321. }
  322. </script>
  323. <style lang="scss">
  324. .group-profile-component {
  325. background-color: #f0f2f5;
  326. .header {
  327. &-jumbotron {
  328. background-color: #F3F4F6;
  329. height: 320px;
  330. border-bottom-left-radius: 20px;
  331. border-bottom-right-radius: 20px;
  332. }
  333. &-profile-card {
  334. display: flex;
  335. flex-direction: column;
  336. justify-content: center;
  337. align-items: center;
  338. .avatar {
  339. width: 170px;
  340. height: 170px;
  341. border-radius: 50%;
  342. margin-top: -150px;
  343. margin-bottom: 20px;
  344. }
  345. .name {
  346. font-size: 30px;
  347. line-height: 30px;
  348. font-weight: 700;
  349. text-align: center;
  350. margin-bottom: 6px;
  351. }
  352. .username {
  353. font-size: 16px;
  354. font-weight: 500;
  355. text-align: center;
  356. }
  357. }
  358. &-navbar {
  359. display: flex;
  360. justify-content: space-between;
  361. align-items: center;
  362. height: 60px;
  363. border-top: 1px solid #F3F4F6;
  364. .dropdown {
  365. display: inline-block;
  366. &-toggle:after {
  367. display: none;
  368. }
  369. }
  370. }
  371. }
  372. .group-profile-feed {
  373. min-height: 500px;
  374. }
  375. .infolet {
  376. margin-bottom: 1rem;
  377. .media {
  378. &-icon {
  379. display: flex;
  380. justify-content: center;
  381. width: 30px;
  382. margin-right: 10px;
  383. i {
  384. font-size: 1.1rem;
  385. color: #D1D5DB !important;
  386. }
  387. }
  388. }
  389. }
  390. .btn-light {
  391. border-color: #F3F4F6;
  392. }
  393. }
  394. </style>