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

508 lines
15 KiB
JavaScript
Raw Normal View History

2025-08-03 21:56:45 +03:00
import merge from 'lodash/merge'
2025-08-05 14:58:53 +03:00
import isEqual from 'lodash/isEqual'
2025-08-03 21:56:45 +03:00
import unescape from 'lodash/unescape'
2025-07-29 17:38:08 +03:00
import ColorInput from 'src/components/color_input/color_input.vue'
import UserAvatar from '../user_avatar/user_avatar.vue'
import RemoteFollow from '../remote_follow/remote_follow.vue'
import ProgressButton from '../progress_button/progress_button.vue'
2019-10-08 10:21:48 +03:00
import FollowButton from '../follow_button/follow_button.vue'
2019-02-18 17:49:32 +03:00
import ModerationTools from '../moderation_tools/moderation_tools.vue'
2019-10-08 10:21:48 +03:00
import AccountActions from '../account_actions/account_actions.vue'
2022-08-20 13:02:27 -04:00
import UserNote from '../user_note/user_note.vue'
import Select from '../select/select.vue'
import UserLink from '../user_link/user_link.vue'
import RichContent from 'src/components/rich_content/rich_content.jsx'
import UserTimedFilterModal from 'src/components/user_timed_filter_modal/user_timed_filter_modal.vue'
2025-08-03 21:56:45 +03:00
import Checkbox from 'src/components/checkbox/checkbox.vue'
import EmojiInput from 'src/components/emoji_input/emoji_input.vue'
2025-08-04 23:15:26 +03:00
import DialogModal from 'src/components/dialog_modal/dialog_modal.vue'
2025-08-04 03:35:09 +03:00
import ImageCropper from 'src/components/image_cropper/image_cropper.vue'
2025-08-03 21:56:45 +03:00
2025-07-29 17:38:08 +03:00
import localeService from 'src/services/locale/locale.service.js'
2025-08-03 21:56:45 +03:00
import suggestor from 'src/components/emoji_input/suggestor.js'
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
import { mapGetters } from 'vuex'
2025-02-10 23:15:39 +02:00
import { usePostStatusStore } from 'src/stores/post_status'
2025-08-03 21:56:45 +03:00
import { propsToNative } from 'src/services/attributes_helper/attributes_helper.service.js'
import { library } from '@fortawesome/fontawesome-svg-core'
import {
faBell,
faRss,
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-03 21:56:45 +03:00
faBirthdayCake,
2025-08-04 03:35:09 +03:00
faSave,
2025-08-04 11:10:43 +03:00
faClockRotateLeft
} from '@fortawesome/free-solid-svg-icons'
2025-02-03 13:02:14 +02:00
2023-04-05 13:55:38 -06:00
import { useMediaViewerStore } from '../../stores/media_viewer'
2023-04-05 21:06:37 -06:00
import { useInterfaceStore } from '../../stores/interface'
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,
2025-08-04 11:10:43 +03: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,
type: Boolean
},
// ID of user to show data of
userId: {
required: true,
type: String
},
// Use a compact layout that hides bio, stats etc.
hideBio: {
required: false,
default: false,
type: Boolean
},
// default - open profile, 'zoom' - zoom, function - call function
avatarAction: {
required: false,
type: String,
default: 'default'
},
// Show note editor if supported
hasNoteEditor: {
required: false,
type: Boolean,
default: false
},
// Show close icon (for popovers)
showClose: {
required: false,
type: Boolean,
default: false
},
// Show close icon (for popovers)
showExpand: {
required: false,
type: Boolean,
default: false
}
},
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,
ImageCropper
},
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
newBio: unescape(user.description),
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,
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,
}
},
created () {
this.$store.dispatch('fetchUserRelationship', this.user.id)
},
computed: {
2025-08-05 14:58:53 +03:00
somethingToSave () {
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
if (!isEqual(
this.newFields,
this.user.fields?.map(field => ({ name: field.name, value: field.value }))
)) return true
return false
},
2025-08-04 13:48:09 +03:00
groupActorAvailable () {
return this.$store.state.instance.groupActorAvailable
},
availableActorTypes () {
return this.groupActorAvailable ? ['Person', 'Service', 'Group'] : ['Person', 'Service']
},
2020-04-21 23:27:51 +03:00
user () {
return this.$store.getters.findUser(this.userId)
},
2025-08-04 13:48:09 +03:00
role () {
return this.user.role
},
2020-04-21 23:27:51 +03:00
relationship () {
return this.$store.getters.relationship(this.userId)
2020-04-21 23:27:51 +03:00
},
2019-03-05 02:32:23 -05:00
style () {
return {
backgroundImage: [
2022-07-31 12:35:48 +03:00
'linear-gradient(to bottom, var(--profileTint), var(--profileTint))',
2025-08-04 11:10:43 +03:00
`url(${this.bannerImgSrc})`
].join(', ')
}
},
isOtherUser () {
return this.user.id !== this.$store.state.users.currentUser.id
},
subscribeUrl () {
const serverUrl = new URL(this.user.statusnet_profile_url)
return `${serverUrl.protocol}//${serverUrl.host}/main/ostatus`
},
loggedIn () {
return this.$store.state.users.currentUser
},
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
},
2025-08-03 21:56:45 +03:00
emoji () {
return this.$store.state.instance.customEmoji.map(e => ({
shortcode: e.displayText,
static_url: e.imageUrl,
url: e.imageUrl
}))
},
userHighlightType: {
2018-06-18 11:36:58 +03: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
},
set (type) {
const data = this.$store.getters.mergedConfig.highlight[this.user.screen_name]
if (type !== 'disabled') {
2019-07-07 00:54:17 +03: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 {
this.$store.dispatch('setHighlight', { user: this.user.screen_name, color: undefined })
2018-06-18 11:36:58 +03:00
}
},
...mapGetters(['mergedConfig'])
2018-06-18 11:36:58 +03:00
},
userHighlightColor: {
get () {
const data = this.$store.getters.mergedConfig.highlight[this.user.screen_name]
return data && data.color
2018-06-18 11:36:58 +03:00
},
set (color) {
this.$store.dispatch('setHighlight', { user: this.user.screen_name, color })
2018-06-18 11:36:58 +03:00
}
},
visibleRole () {
2025-08-04 14:25:14 +03:00
if (!this.newShowRole) { return }
2019-02-18 17:49:32 +03:00
const rights = this.user.rights
if (!rights) { return }
const validRole = rights.admin || rights.moderator
const roleTitle = rights.admin ? 'admin' : 'moderator'
return validRole && roleTitle
},
2019-11-12 10:40:36 -05:00
hideFollowsCount () {
return this.isOtherUser && this.user.hide_follows_count
},
hideFollowersCount () {
return this.isOtherUser && this.user.hide_followers_count
},
showModerationMenu () {
const privileges = this.loggedIn.privileges
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')
},
hasNote () {
return this.relationship.note
},
2022-08-20 13:20:59 -04:00
supportsNote () {
return 'note' in this.relationship
},
2025-07-17 14:53:56 +03:00
muteExpiryAvailable () {
return this.user.mute_expires_at !== undefined
},
muteExpiry () {
return this.user.mute_expires_at == null
? this.$t('user_card.mute_expires_forever')
: this.$t('user_card.mute_expires_at', [new Date(this.user.mute_expires_at).toLocaleString()])
},
2025-07-17 14:53:56 +03:00
blockExpiryAvailable () {
return this.user.block_expires_at !== undefined
},
blockExpiry () {
return this.user.block_expires_at == null
? this.$t('user_card.block_expires_forever')
: this.$t('user_card.block_expires_at', [new Date(this.user.mute_expires_at).toLocaleString()])
},
2025-07-29 17:38:08 +03: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-08-03 21:56:45 +03:00
// Editable stuff
2025-08-04 11:10:43 +03:00
avatarImgSrc () {
2025-08-04 23:15:26 +03:00
const currentUrl = this.user.profile_image_url_original || this.defaultAvatar
const newUrl = this.newAvatar === '' ? this.defaultAvatar : this.newAvatar
return (this.newAvatar === null) ? currentUrl : newUrl
2025-08-04 11:10:43 +03:00
},
bannerImgSrc () {
2025-08-04 23:15:26 +03:00
const currentUrl = this.user.cover_photo || this.defaultBanner
const newUrl = this.newBanner === '' ? this.defaultBanner : this.newBanner
return (this.newBanner === null) ? currentUrl : newUrl
2025-08-04 11:10:43 +03:00
},
2025-08-04 03:35:09 +03:00
defaultAvatar () {
2025-08-04 23:15:26 +03:00
return this.$store.state.instance.server + this.$store.state.instance.defaultAvatar
2025-08-04 03:35:09 +03:00
},
defaultBanner () {
2025-08-04 23:15:26 +03:00
return this.$store.state.instance.server + this.$store.state.instance.defaultBanner
2025-08-04 03:35:09 +03:00
},
isDefaultAvatar () {
const baseAvatar = this.$store.state.instance.defaultAvatar
return !(this.$store.state.users.currentUser.profile_image_url) ||
this.$store.state.users.currentUser.profile_image_url.includes(baseAvatar)
},
isDefaultBanner () {
const baseBanner = this.$store.state.instance.defaultBanner
return !(this.$store.state.users.currentUser.cover_photo) ||
this.$store.state.users.currentUser.cover_photo.includes(baseBanner)
},
2025-08-03 21:56:45 +03:00
fieldsLimits () {
return this.$store.state.instance.fieldsLimits
},
maxFields () {
return this.fieldsLimits ? this.fieldsLimits.maxFields : 0
},
emojiUserSuggestor () {
return suggestor({
emoji: [
...this.$store.getters.standardEmojiList,
...this.$store.state.instance.customEmoji
],
store: this.$store
})
},
emojiSuggestor () {
return suggestor({
emoji: [
...this.$store.getters.standardEmojiList,
...this.$store.state.instance.customEmoji
]
})
},
...mapGetters(['mergedConfig'])
},
methods: {
2019-03-01 11:37:34 -05:00
muteUser () {
this.$refs.timedMuteDialog.optionallyPrompt()
},
2019-03-01 11:37:34 -05:00
unmuteUser () {
this.$store.dispatch('unmuteUser', this.user.id)
},
subscribeUser () {
return this.$store.dispatch('subscribeUser', this.user.id)
},
unsubscribeUser () {
return this.$store.dispatch('unsubscribeUser', this.user.id)
},
2019-07-05 10:02:14 +03: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
},
userProfileLink (user) {
return generateProfileLink(
user.id, user.screen_name,
this.$store.state.instance.restrictedNicknames
)
2019-07-22 16:58:20 -04:00
},
2021-06-17 19:29:58 +00:00
openProfileTab () {
2023-04-05 21:06:37 -06:00
useInterfaceStore().openSettingsModalTab('profile')
2021-06-17 19:29:58 +00:00
},
zoomAvatar () {
2019-07-22 16:58:20 -04:00
const attachment = {
url: this.user.profile_image_url_original,
mimetype: 'image'
}
2023-04-05 13:55:38 -06:00
useMediaViewerStore().setMedia([attachment])
useMediaViewerStore().setCurrentMedia(attachment)
},
mentionUser () {
usePostStatusStore().openPostStatusModal({ profileMention: true, repliedUser: this.user })
},
onAvatarClickHandler (e) {
if (this.onAvatarClick) {
e.preventDefault()
this.onAvatarClick()
}
2025-08-03 21:56:45 +03:00
},
// Editable stuff
2025-08-04 03:35:09 +03:00
changeAvatar () {
this.editImage = 'avatar'
},
changeBanner () {
this.editImage = 'banner'
},
submitImage ({ canvas, file }) {
2025-08-04 11:10:43 +03:00
if (canvas) {
return canvas.toBlob((data) => this.submitImage({ canvas: null, file: data }))
}
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
},
2025-08-04 23:15:26 +03:00
resetImage () {
if (this.editImage === 'avatar') {
this.newAvatar = ''
this.newAvatarFile = ''
} else {
this.newBanner = ''
this.newBannerFile = ''
}
this.editImage = false
},
2025-08-03 21:56:45 +03:00
addField () {
if (this.newFields.length < this.maxFields) {
this.newFields.push({ name: '', value: '' })
}
},
deleteField (index) {
this.newFields.splice(index, 1)
},
propsToNative (props) {
return propsToNative(props)
},
cancelImageText () {
return
},
2025-08-04 23:15:26 +03: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
this.newFields = user.fields.map(field => ({ name: field.name, value: field.value }))
2025-08-04 11:10:43 +03:00
},
2025-08-03 21:56:45 +03:00
updateProfile () {
const params = {
note: this.newBio,
// Backend notation.
display_name: this.newName,
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
})
},
2025-08-04 11:10:43 +03:00
displayUploadError (error) {
useInterfaceStore().pushGlobalNotice({
messageKey: 'upload.error.message',
messageArgs: [error.message],
level: 'error'
})
}
}
}