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

566 lines
16 KiB
JavaScript
Raw Normal View History

2025-08-05 14:58:53 +03:00
import isEqual from 'lodash/isEqual'
2026-01-06 16:23:17 +02:00
import merge from 'lodash/merge'
2026-01-06 17:32:22 +02:00
import ldUnescape from 'lodash/unescape'
2026-01-08 17:26:52 +02:00
import { mapGetters } from 'vuex'
2025-08-03 21:56:45 +03:00
import Checkbox from 'src/components/checkbox/checkbox.vue'
2026-01-06 16:23:17 +02:00
import ColorInput from 'src/components/color_input/color_input.vue'
2025-08-04 23:15:26 +03:00
import DialogModal from 'src/components/dialog_modal/dialog_modal.vue'
2026-01-06 16:23:17 +02:00
import EmojiInput from 'src/components/emoji_input/emoji_input.vue'
import suggestor from 'src/components/emoji_input/suggestor.js'
2025-08-04 03:35:09 +03:00
import ImageCropper from 'src/components/image_cropper/image_cropper.vue'
2026-01-06 16:23:17 +02:00
import RichContent from 'src/components/rich_content/rich_content.jsx'
import UserTimedFilterModal from 'src/components/user_timed_filter_modal/user_timed_filter_modal.vue'
import { propsToNative } from 'src/services/attributes_helper/attributes_helper.service.js'
2025-07-29 17:38:08 +03:00
import localeService from 'src/services/locale/locale.service.js'
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
2025-02-10 23:15:39 +02:00
import { usePostStatusStore } from 'src/stores/post_status'
2023-04-05 21:06:37 -06:00
import { useInterfaceStore } from '../../stores/interface'
2026-01-06 16:23:17 +02:00
import { useMediaViewerStore } from '../../stores/media_viewer'
import AccountActions from '../account_actions/account_actions.vue'
import FollowButton from '../follow_button/follow_button.vue'
import ModerationTools from '../moderation_tools/moderation_tools.vue'
import ProgressButton from '../progress_button/progress_button.vue'
import RemoteFollow from '../remote_follow/remote_follow.vue'
import Select from '../select/select.vue'
import UserAvatar from '../user_avatar/user_avatar.vue'
import UserLink from '../user_link/user_link.vue'
import UserNote from '../user_note/user_note.vue'
2026-01-08 17:26:52 +02:00
import { library } from '@fortawesome/fontawesome-svg-core'
import {
faBell,
faBirthdayCake,
faClockRotateLeft,
faEdit,
faExpandAlt,
faExternalLinkAlt,
faRss,
faSave,
faSearchPlus,
faTimes,
} from '@fortawesome/free-solid-svg-icons'
library.add(
2025-08-03 21:56:45 +03:00
faSave,
faRss,
faBell,
faSearchPlus,
2021-06-17 19:29:58 +00:00
faExternalLinkAlt,
2022-06-16 17:06:16 +03:00
faEdit,
faTimes,
2025-07-29 17:38:08 +03:00
faExpandAlt,
2025-08-04 03:35:09 +03:00
faBirthdayCake,
2026-01-06 16:22:52 +02:00
faClockRotateLeft,
)
export default {
2025-08-05 17:52:30 +03:00
props: {
// Enables all the options for profile editing, used in settings -> profile tab
editable: {
required: false,
default: false,
2026-01-06 16:22:52 +02:00
type: Boolean,
2025-08-05 17:52:30 +03:00
},
// ID of user to show data of
userId: {
required: true,
2026-01-06 16:22:52 +02:00
type: String,
2025-08-05 17:52:30 +03:00
},
// Use a compact layout that hides bio, stats etc.
hideBio: {
required: false,
default: false,
2026-01-06 16:22:52 +02:00
type: Boolean,
2025-08-05 17:52:30 +03:00
},
// default - open profile, 'zoom' - zoom, function - call function
avatarAction: {
required: false,
type: String,
2026-01-06 16:22:52 +02:00
default: 'default',
2025-08-05 17:52:30 +03:00
},
// Show note editor if supported
hasNoteEditor: {
required: false,
type: Boolean,
2026-01-06 16:22:52 +02:00
default: false,
2025-08-05 17:52:30 +03:00
},
// Show close icon (for popovers)
showClose: {
required: false,
type: Boolean,
2026-01-06 16:22:52 +02:00
default: false,
2025-08-05 17:52:30 +03:00
},
// Show close icon (for popovers)
showExpand: {
required: false,
type: Boolean,
2026-01-06 16:22:52 +02:00
default: false,
},
2025-08-05 17:52:30 +03:00
},
components: {
2025-08-04 23:15:26 +03:00
DialogModal,
UserAvatar,
2025-08-03 21:56:45 +03:00
Checkbox,
RemoteFollow,
ModerationTools,
AccountActions,
ProgressButton,
FollowButton,
Select,
RichContent,
UserLink,
UserNote,
2025-07-29 17:38:08 +03:00
UserTimedFilterModal,
2025-08-03 21:56:45 +03:00
ColorInput,
2025-08-04 03:35:09 +03:00
EmojiInput,
2026-01-06 16:22:52 +02:00
ImageCropper,
},
2026-01-06 16:22:52 +02:00
data() {
const user = this.$store.getters.findUser(this.userId)
2025-08-03 21:56:45 +03:00
return {
followRequestInProgress: false,
2022-04-30 11:08:19 -04:00
muteExpiryAmount: 0,
2025-08-03 21:56:45 +03:00
muteExpiryUnit: 'minutes',
// Editable stuff
2025-08-04 23:15:26 +03:00
editImage: false,
2025-08-03 21:56:45 +03:00
newName: user.name_unescaped,
2025-08-04 00:45:13 +03:00
editingName: false,
2025-08-04 23:15:26 +03:00
2026-01-06 17:32:22 +02:00
newBio: ldUnescape(user.description),
2025-08-04 23:15:26 +03:00
editingBio: false,
newAvatar: null,
2025-08-04 11:10:43 +03:00
newAvatarFile: null,
2025-08-04 23:15:26 +03:00
newBanner: null,
2025-08-04 11:10:43 +03:00
newBannerFile: null,
2025-08-04 23:15:26 +03:00
2025-08-04 11:10:43 +03:00
newActorType: user.actor_type,
2025-08-03 21:56:45 +03:00
newBirthday: user.birthday,
newShowBirthday: user.show_birthday,
2025-08-04 23:15:26 +03:00
newShowRole: user.show_role,
2026-01-06 16:22:52 +02:00
newFields: user.fields?.map((field) => ({
name: field.name,
value: field.value,
})),
2025-08-05 14:58:53 +03:00
2025-08-03 21:56:45 +03:00
editingFields: false,
}
},
2026-01-06 16:22:52 +02:00
created() {
this.$store.dispatch('fetchUserRelationship', this.user.id)
},
computed: {
2026-01-06 16:22:52 +02:00
somethingToSave() {
2025-08-05 14:58:53 +03:00
if (this.newName !== this.user.name_unescaped) return true
if (this.newBio !== unescape(this.user.description)) return true
if (this.newAvatar !== null) return true
if (this.newBanner !== null) return true
if (this.newActorType !== this.user.actor_type) return true
if (this.newBirthday !== this.user.birthday) return true
if (this.newShowBirthday !== this.user.show_birthday) return true
if (this.newShowRole !== this.user.show_role) return true
2026-01-06 16:22:52 +02:00
if (
!isEqual(
this.newFields,
this.user.fields?.map((field) => ({
name: field.name,
value: field.value,
})),
)
)
return true
2025-08-05 14:58:53 +03:00
return false
},
2026-01-06 16:22:52 +02:00
groupActorAvailable() {
2025-08-04 13:48:09 +03:00
return this.$store.state.instance.groupActorAvailable
},
2026-01-06 16:22:52 +02:00
availableActorTypes() {
return this.groupActorAvailable
? ['Person', 'Service', 'Group']
: ['Person', 'Service']
2025-08-04 13:48:09 +03:00
},
2026-01-06 16:22:52 +02:00
user() {
2020-04-21 23:27:51 +03:00
return this.$store.getters.findUser(this.userId)
},
2026-01-06 16:22:52 +02:00
role() {
2025-08-04 13:48:09 +03:00
return this.user.role
},
2026-01-06 16:22:52 +02:00
relationship() {
return this.$store.getters.relationship(this.userId)
2020-04-21 23:27:51 +03:00
},
2026-01-06 16:22:52 +02:00
isOtherUser() {
return this.user.id !== this.$store.state.users.currentUser.id
},
2026-01-06 16:22:52 +02:00
subscribeUrl() {
const serverUrl = new URL(this.user.statusnet_profile_url)
return `${serverUrl.protocol}//${serverUrl.host}/main/ostatus`
},
2026-01-06 16:22:52 +02:00
loggedIn() {
return this.$store.state.users.currentUser
},
2026-01-06 16:22:52 +02:00
dailyAvg() {
const days = Math.ceil(
(new Date() - new Date(this.user.created_at)) / (60 * 60 * 24 * 1000),
)
return Math.round(this.user.statuses_count / days)
2018-06-18 11:36:58 +03:00
},
2026-01-06 16:22:52 +02:00
emoji() {
return this.$store.state.instance.customEmoji.map((e) => ({
2025-08-03 21:56:45 +03:00
shortcode: e.displayText,
static_url: e.imageUrl,
2026-01-06 16:22:52 +02:00
url: e.imageUrl,
2025-08-03 21:56:45 +03:00
}))
},
userHighlightType: {
2026-01-06 16:22:52 +02:00
get() {
const data =
this.$store.getters.mergedConfig.highlight[this.user.screen_name]
2019-07-07 00:54:17 +03:00
return (data && data.type) || 'disabled'
2018-06-18 11:36:58 +03:00
},
2026-01-06 16:22:52 +02:00
set(type) {
const data =
this.$store.getters.mergedConfig.highlight[this.user.screen_name]
if (type !== 'disabled') {
2026-01-06 16:22:52 +02:00
this.$store.dispatch('setHighlight', {
user: this.user.screen_name,
color: (data && data.color) || '#FFFFFF',
type,
})
2018-06-18 11:36:58 +03:00
} else {
2026-01-06 16:22:52 +02:00
this.$store.dispatch('setHighlight', {
user: this.user.screen_name,
color: undefined,
})
2018-06-18 11:36:58 +03:00
}
},
2026-01-06 16:22:52 +02:00
...mapGetters(['mergedConfig']),
2018-06-18 11:36:58 +03:00
},
userHighlightColor: {
2026-01-06 16:22:52 +02:00
get() {
const data =
this.$store.getters.mergedConfig.highlight[this.user.screen_name]
return data && data.color
2018-06-18 11:36:58 +03:00
},
2026-01-06 16:22:52 +02:00
set(color) {
this.$store.dispatch('setHighlight', {
user: this.user.screen_name,
color,
})
},
},
2026-01-06 16:22:52 +02:00
visibleRole() {
if (!this.newShowRole) {
return
}
2019-02-18 17:49:32 +03:00
const rights = this.user.rights
2026-01-06 16:22:52 +02:00
if (!rights) {
return
}
2019-02-18 17:49:32 +03:00
const validRole = rights.admin || rights.moderator
const roleTitle = rights.admin ? 'admin' : 'moderator'
return validRole && roleTitle
},
2026-01-06 16:22:52 +02:00
hideFollowsCount() {
2019-11-12 10:40:36 -05:00
return this.isOtherUser && this.user.hide_follows_count
},
2026-01-06 16:22:52 +02:00
hideFollowersCount() {
2019-11-12 10:40:36 -05:00
return this.isOtherUser && this.user.hide_followers_count
},
2026-01-06 16:22:52 +02:00
showModerationMenu() {
const privileges = this.loggedIn.privileges
2026-01-06 16:22:52 +02:00
return (
this.loggedIn.role === 'admin' ||
2025-06-18 17:49:22 +03:00
privileges.includes('users_manage_activation_state') ||
2025-06-18 18:46:33 +00:00
privileges.includes('users_delete') ||
2025-06-18 17:49:22 +03:00
privileges.includes('users_manage_tags')
2026-01-06 16:22:52 +02:00
)
},
2026-01-06 16:22:52 +02:00
hasNote() {
return this.relationship.note
},
2026-01-06 16:22:52 +02:00
supportsNote() {
2022-08-20 13:20:59 -04:00
return 'note' in this.relationship
},
2026-01-06 16:22:52 +02:00
muteExpiryAvailable() {
2025-07-17 14:53:56 +03:00
return this.user.mute_expires_at !== undefined
},
2026-01-06 16:22:52 +02:00
muteExpiry() {
return this.user.mute_expires_at == null
? this.$t('user_card.mute_expires_forever')
2026-01-06 16:22:52 +02:00
: this.$t('user_card.mute_expires_at', [
new Date(this.user.mute_expires_at).toLocaleString(),
])
},
2026-01-06 16:22:52 +02:00
blockExpiryAvailable() {
2025-07-17 14:53:56 +03:00
return this.user.block_expires_at !== undefined
},
2026-01-06 16:22:52 +02:00
blockExpiry() {
return this.user.block_expires_at == null
? this.$t('user_card.block_expires_forever')
2026-01-06 16:22:52 +02:00
: this.$t('user_card.block_expires_at', [
new Date(this.user.mute_expires_at).toLocaleString(),
])
},
2026-01-06 16:22:52 +02:00
formattedBirthday() {
const browserLocale = localeService.internalToBrowserLocale(
this.$i18n.locale,
)
return (
this.user.birthday &&
new Date(Date.parse(this.user.birthday)).toLocaleDateString(
browserLocale,
{ timeZone: 'UTC', day: 'numeric', month: 'long', year: 'numeric' },
)
)
2025-07-29 17:38:08 +03:00
},
2025-08-03 21:56:45 +03:00
// Editable stuff
2026-01-06 16:22:52 +02:00
avatarImgSrc() {
const currentUrl =
this.user.profile_image_url_original || this.defaultAvatar
if (!this.editable) return currentUrl
2026-01-06 16:22:52 +02:00
const newUrl =
this.newAvatar === null ? this.defaultAvatar : this.newAvatar
return this.newAvatar === null ? currentUrl : newUrl
2025-08-04 11:10:43 +03:00
},
2026-01-06 16:22:52 +02:00
bannerImgSrc() {
2025-08-04 23:15:26 +03:00
const currentUrl = this.user.cover_photo || this.defaultBanner
if (!this.editable) return currentUrl
2026-01-06 16:22:52 +02:00
const newUrl =
this.newBanner === null ? this.defaultBanner : this.newBanner
return this.newBanner === null ? currentUrl : newUrl
},
defaultAvatar() {
return (
this.$store.state.instance.server +
this.$store.state.instance.defaultAvatar
)
2025-08-04 03:35:09 +03:00
},
2026-01-06 16:22:52 +02:00
defaultBanner() {
return (
this.$store.state.instance.server +
this.$store.state.instance.defaultBanner
)
2025-08-04 03:35:09 +03:00
},
2026-01-06 16:22:52 +02:00
isDefaultAvatar() {
2025-08-04 03:35:09 +03:00
const baseAvatar = this.$store.state.instance.defaultAvatar
2026-01-06 16:22:52 +02:00
return (
!this.$store.state.users.currentUser.profile_image_url ||
this.$store.state.users.currentUser.profile_image_url.includes(
baseAvatar,
)
)
2025-08-04 03:35:09 +03:00
},
2026-01-06 16:22:52 +02:00
isDefaultBanner() {
2025-08-04 03:35:09 +03:00
const baseBanner = this.$store.state.instance.defaultBanner
2026-01-06 16:22:52 +02:00
return (
!this.$store.state.users.currentUser.cover_photo ||
this.$store.state.users.currentUser.cover_photo.includes(baseBanner)
)
2025-08-04 03:35:09 +03:00
},
2026-01-06 16:22:52 +02:00
fieldsLimits() {
2025-08-03 21:56:45 +03:00
return this.$store.state.instance.fieldsLimits
},
2026-01-06 16:22:52 +02:00
maxFields() {
2025-08-03 21:56:45 +03:00
return this.fieldsLimits ? this.fieldsLimits.maxFields : 0
},
2026-01-06 16:22:52 +02:00
emojiUserSuggestor() {
2025-08-03 21:56:45 +03:00
return suggestor({
emoji: [
...this.$store.getters.standardEmojiList,
2026-01-06 16:22:52 +02:00
...this.$store.state.instance.customEmoji,
2025-08-03 21:56:45 +03:00
],
2026-01-06 16:22:52 +02:00
store: this.$store,
2025-08-03 21:56:45 +03:00
})
},
2026-01-06 16:22:52 +02:00
emojiSuggestor() {
2025-08-03 21:56:45 +03:00
return suggestor({
emoji: [
...this.$store.getters.standardEmojiList,
2026-01-06 16:22:52 +02:00
...this.$store.state.instance.customEmoji,
],
2025-08-03 21:56:45 +03:00
})
},
2026-01-06 16:22:52 +02:00
...mapGetters(['mergedConfig']),
},
methods: {
2026-01-06 16:22:52 +02:00
muteUser() {
this.$refs.timedMuteDialog.optionallyPrompt()
},
2026-01-06 16:22:52 +02:00
unmuteUser() {
this.$store.dispatch('unmuteUser', this.user.id)
},
2026-01-06 16:22:52 +02:00
subscribeUser() {
return this.$store.dispatch('subscribeUser', this.user.id)
},
2026-01-06 16:22:52 +02:00
unsubscribeUser() {
return this.$store.dispatch('unsubscribeUser', this.user.id)
},
2026-01-06 16:22:52 +02:00
linkClicked({ target }) {
if (target.tagName === 'SPAN') {
target = target.parentNode
}
if (target.tagName === 'A') {
window.open(target.href, '_blank')
}
2018-12-15 06:16:44 +03:00
},
2026-01-06 16:22:52 +02:00
userProfileLink(user) {
return generateProfileLink(
2026-01-06 16:22:52 +02:00
user.id,
user.screen_name,
this.$store.state.instance.restrictedNicknames,
)
2019-07-22 16:58:20 -04:00
},
2026-01-06 16:22:52 +02:00
openProfileTab() {
2023-04-05 21:06:37 -06:00
useInterfaceStore().openSettingsModalTab('profile')
2021-06-17 19:29:58 +00:00
},
2026-01-06 16:22:52 +02:00
zoomAvatar() {
2019-07-22 16:58:20 -04:00
const attachment = {
url: this.user.profile_image_url_original,
2026-01-06 16:22:52 +02:00
mimetype: 'image',
2019-07-22 16:58:20 -04:00
}
2023-04-05 13:55:38 -06:00
useMediaViewerStore().setMedia([attachment])
useMediaViewerStore().setCurrentMedia(attachment)
},
2026-01-06 16:22:52 +02:00
mentionUser() {
usePostStatusStore().openPostStatusModal({
profileMention: true,
repliedUser: this.user,
})
},
2026-01-06 16:22:52 +02:00
onAvatarClickHandler(e) {
if (this.onAvatarClick) {
e.preventDefault()
this.onAvatarClick()
}
2025-08-03 21:56:45 +03:00
},
// Editable stuff
2026-01-06 16:22:52 +02:00
changeAvatar() {
2025-08-04 03:35:09 +03:00
this.editImage = 'avatar'
},
2026-01-06 16:22:52 +02:00
changeBanner() {
2025-08-04 03:35:09 +03:00
this.editImage = 'banner'
},
2026-01-06 16:22:52 +02:00
submitImage({ canvas, file }) {
2025-08-04 11:10:43 +03:00
if (canvas) {
2026-01-06 16:22:52 +02:00
return canvas.toBlob((data) =>
this.submitImage({ canvas: null, file: data }),
)
2025-08-04 11:10:43 +03:00
}
const reader = new window.FileReader()
reader.onload = (e) => {
const dataUrl = e.target.result
if (this.editImage === 'avatar') {
this.newAvatar = dataUrl
this.newAvatarFile = file
} else {
this.newBanner = dataUrl
this.newBannerFile = file
2025-08-04 03:35:09 +03:00
}
2025-08-04 11:10:43 +03:00
this.editImage = false
2025-08-04 03:35:09 +03:00
}
2025-08-04 11:10:43 +03:00
reader.readAsDataURL(file)
2025-08-04 03:35:09 +03:00
},
2026-01-06 16:22:52 +02:00
resetImage() {
2025-08-04 23:15:26 +03:00
if (this.editImage === 'avatar') {
this.newAvatar = null
this.newAvatarFile = null
2025-08-04 23:15:26 +03:00
} else {
this.newBanner = null
this.newBannerFile = null
2025-08-04 23:15:26 +03:00
}
this.editImage = false
},
2026-01-06 16:22:52 +02:00
addField() {
2025-08-03 21:56:45 +03:00
if (this.newFields.length < this.maxFields) {
this.newFields.push({ name: '', value: '' })
}
},
2026-01-06 16:22:52 +02:00
deleteField(index) {
2025-08-03 21:56:45 +03:00
this.newFields.splice(index, 1)
},
2026-01-06 16:22:52 +02:00
propsToNative(props) {
2025-08-03 21:56:45 +03:00
return propsToNative(props)
},
2026-01-06 16:22:52 +02:00
cancelImageText() {
return
},
2026-01-06 16:22:52 +02:00
resetState() {
2025-08-04 11:10:43 +03:00
const user = this.$store.state.users.currentUser
this.newName = user.name_unescaped
2025-08-04 23:15:26 +03:00
this.newBio = unescape(user.description)
this.newAvatar = null
2025-08-04 11:10:43 +03:00
this.newAvatarFile = null
2025-08-04 23:15:26 +03:00
this.newBanner = null
2025-08-04 11:10:43 +03:00
this.newBannerFile = null
2025-08-04 23:15:26 +03:00
2025-08-04 11:10:43 +03:00
this.newActorType = user.actor_type
this.newBirthday = user.birthday
this.newShowBirthday = user.show_birthday
this.newShowRole = user.show_role
2025-08-04 23:15:26 +03:00
2026-01-06 16:22:52 +02:00
this.newFields = user.fields.map((field) => ({
name: field.name,
value: field.value,
}))
2025-08-04 11:10:43 +03:00
},
2026-01-06 16:22:52 +02:00
updateProfile() {
2025-08-03 21:56:45 +03:00
const params = {
note: this.newBio,
// Backend notation.
display_name: this.newName,
2026-01-06 16:22:52 +02:00
fields_attributes: this.newFields.filter((el) => el != null),
show_role: !!this.newShowRole,
2025-08-03 21:56:45 +03:00
birthday: this.newBirthday || '',
2025-08-05 17:52:30 +03:00
show_birthday: !!this.newShowBirthday,
2025-08-04 11:10:43 +03:00
}
if (this.actorType) {
params.actor_type = this.actorType
}
2025-08-04 23:15:26 +03:00
if (this.newAvatarFile !== null) {
2025-08-04 11:10:43 +03:00
params.avatar = this.newAvatarFile
}
2025-08-04 23:15:26 +03:00
if (this.newBannerFile !== null) {
2025-08-04 11:10:43 +03:00
params.header = this.newBannerFile
2025-08-03 21:56:45 +03:00
}
this.$store.state.api.backendInteractor
.updateProfile({ params })
.then((user) => {
2025-08-04 11:10:43 +03:00
this.newFields.splice(this.newFields.length)
2025-08-03 21:56:45 +03:00
merge(this.newFields, user.fields)
this.$store.commit('addNewUsers', [user])
this.$store.commit('setCurrentUser', user)
2025-08-04 23:15:26 +03:00
this.resetState()
2025-08-04 11:10:43 +03:00
})
.catch((error) => {
this.displayUploadError(error)
2025-08-03 21:56:45 +03:00
})
},
2026-01-06 16:22:52 +02:00
displayUploadError(error) {
2025-08-04 11:10:43 +03:00
useInterfaceStore().pushGlobalNotice({
messageKey: 'upload.error.message',
messageArgs: [error.message],
2026-01-06 16:22:52 +02:00
level: 'error',
2025-08-04 11:10:43 +03:00
})
2026-01-06 16:22:52 +02:00
},
},
}