pleroma-fe/src/components/user_profile/user_profile.js

180 lines
4.9 KiB
JavaScript
Raw Normal View History

import { get } from 'lodash'
2026-01-08 17:26:52 +02:00
import FollowCard from 'src/components/follow_card/follow_card.vue'
import List from 'src/components/list/list.vue'
2026-06-04 21:59:09 +03:00
import TabSwitcher from 'src/components/tab_switcher/tab_switcher.jsx'
import Timeline from 'src/components/timeline/timeline.vue'
import UserCard from 'src/components/user_card/user_card.vue'
2020-10-21 00:01:28 +03:00
import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js'
2026-06-05 14:53:33 +03:00
import { useInterfaceStore } from 'src/stores/interface.js'
2026-05-13 16:12:52 +03:00
import { useMergedConfigStore } from 'src/stores/merged_config.js'
2026-08-11 20:25:43 +03:00
import { useTimelinesStore } from 'src/stores/timelines.js'
2026-08-10 15:00:59 +03:00
import { useUsersStore } from 'src/stores/users.js'
2026-01-29 20:40:00 +02:00
2026-01-08 17:26:52 +02:00
import { library } from '@fortawesome/fontawesome-svg-core'
import { faCircleNotch } from '@fortawesome/free-solid-svg-icons'
2026-01-06 16:22:52 +02:00
library.add(faCircleNotch)
2019-02-25 04:51:23 -05:00
const defaultTabKey = 'statuses'
2016-11-30 23:32:22 +01:00
const UserProfile = {
2026-01-06 16:22:52 +02:00
data() {
return {
error: false,
userId: null,
tab: defaultTabKey,
2026-01-06 16:22:52 +02:00
footerRef: null,
}
},
2026-01-06 16:22:52 +02:00
created() {
2019-04-15 11:08:28 -04:00
const routeParams = this.$route.params
this.load({ name: routeParams.name, id: routeParams.id })
this.tab = get(this.$route, 'query.tab', defaultTabKey)
2026-06-01 21:56:09 +03:00
useInterfaceStore().setForeignProfileBackground(this.user?.background_image)
},
updated() {
useInterfaceStore().setForeignProfileBackground(this.user?.background_image)
2017-06-12 16:00:46 +02:00
},
2026-01-06 16:22:52 +02:00
unmounted() {
2026-06-01 21:56:09 +03:00
useInterfaceStore().setForeignProfileBackground(null)
2026-08-18 03:20:09 +03:00
useUsersStore().clearFollowLists(this.userId)
},
2016-11-30 23:32:22 +01:00
computed: {
2026-01-06 16:22:52 +02:00
favorites() {
2026-08-11 18:54:54 +03:00
return useTimelinesStore().favorites
},
2026-01-06 16:22:52 +02:00
media() {
2026-08-11 18:54:54 +03:00
return useTimelinesStore().media
2019-01-24 10:48:40 +00:00
},
2026-01-06 16:22:52 +02:00
isUs() {
return (
this.userId &&
2026-08-10 15:00:59 +03:00
useUsersStore().currentUser.id &&
this.userId === useUsersStore().currentUser.id
2026-01-06 16:22:52 +02:00
)
2019-01-17 22:11:51 +03:00
},
2026-01-06 16:22:52 +02:00
user() {
2026-08-10 15:00:59 +03:00
return useUsersStore().findUser(this.userId)
2018-12-15 06:16:44 +03:00
},
2026-01-06 16:22:52 +02:00
isExternal() {
2018-12-15 06:16:44 +03:00
return this.$route.name === 'external-user-profile'
2019-02-03 12:52:04 -05:00
},
2026-01-06 16:22:52 +02:00
followsTabVisible() {
2019-02-07 10:53:36 -05:00
return this.isUs || !this.user.hide_follows
2019-02-03 12:52:04 -05:00
},
2026-01-06 16:22:52 +02:00
followersTabVisible() {
2019-02-03 12:52:04 -05:00
return this.isUs || !this.user.hide_followers
},
2026-01-06 16:22:52 +02:00
favoritesTabVisible() {
return (
this.isUs ||
(useInstanceCapabilitiesStore().pleromaPublicFavouritesAvailable &&
2026-01-06 16:22:52 +02:00
!this.user.hide_favorites)
)
},
compactProfiles() {
return useMergedConfigStore().mergedConfig.compactProfiles
},
friends() {
2026-08-13 01:12:48 +03:00
return [
...useUsersStore().relationshipsLists.friends.get(this.user).keys(),
].map((id) => useUsersStore().findUser(id))
2026-06-08 04:13:17 +03:00
},
followers() {
2026-08-13 01:12:48 +03:00
return [
...useUsersStore().relationshipsLists.followers.get(this.user).keys(),
].map((id) => useUsersStore().findUser(id))
2026-06-08 04:13:17 +03:00
},
},
methods: {
setFooterRef(el) {
this.footerRef = el
},
fetchUsers(group) {
2026-06-08 20:31:42 +03:00
return () =>
2026-08-13 01:12:48 +03:00
useUsersStore()
['fetch' + group](this.userId)
2026-06-08 20:31:42 +03:00
.then((result) => ({ items: result }))
},
2026-01-06 16:22:52 +02:00
load(userNameOrId) {
const loadById = (userId) => {
this.userId = userId
}
// Reset view
this.userId = null
this.error = false
const maybeId = userNameOrId.id
const maybeName = userNameOrId.name
2019-04-15 11:08:28 -04:00
// Check if user data is already loaded in store
2026-01-06 16:22:52 +02:00
const user = maybeId
2026-08-10 15:00:59 +03:00
? useUsersStore().findUser(maybeId)
: useUsersStore().findUserByName(maybeName)
2026-08-11 18:54:54 +03:00
2019-04-15 11:08:28 -04:00
if (user) {
loadById(user.id)
} else {
2026-08-11 20:25:43 +03:00
const promise = maybeId
? useUsersStore().fetchUser(maybeId)
: useUsersStore().fetchUserByName(maybeName)
promise
.then(({ id }) => loadById(id))
2019-04-15 11:08:28 -04:00
.catch((reason) => {
const errorMessage = get(reason, 'error.error')
2026-01-06 16:22:52 +02:00
if (errorMessage === 'No user with such user_id') {
// Known error
2019-04-15 11:08:28 -04:00
this.error = this.$t('user_profile.profile_does_not_exist')
} else if (errorMessage) {
this.error = errorMessage
} else {
this.error = this.$t('user_profile.profile_loading_error')
}
})
}
},
2026-01-06 16:22:52 +02:00
switchUser(userNameOrId) {
this.load(userNameOrId)
},
2026-01-06 16:22:52 +02:00
onTabSwitch(tab) {
this.tab = tab
this.$router.replace({ query: { tab } })
2019-11-16 03:12:16 +09:00
},
2026-01-06 16:22:52 +02:00
linkClicked({ target }) {
2019-11-16 03:12:16 +09:00
if (target.tagName === 'SPAN') {
target = target.parentNode
}
if (target.tagName === 'A') {
window.open(target.href, '_blank')
}
2026-01-06 16:22:52 +02:00
},
},
watch: {
2019-04-15 11:08:28 -04:00
'$route.params.id': function (newVal) {
if (newVal) {
this.switchUser({ id: newVal })
}
2019-03-03 13:38:48 -05:00
},
2019-04-15 11:08:28 -04:00
'$route.params.name': function (newVal) {
if (newVal) {
this.switchUser({ name: newVal })
}
},
'$route.query': function (newVal) {
this.tab = newVal.tab || defaultTabKey
2026-01-06 16:22:52 +02:00
},
},
2016-11-30 23:32:22 +01:00
components: {
2019-03-05 14:01:49 -05:00
UserCard,
Timeline,
2026-06-08 04:13:17 +03:00
List,
FollowCard,
TabSwitcher,
2026-01-06 16:22:52 +02:00
},
2016-11-30 23:32:22 +01:00
}
export default UserProfile