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

171 lines
4.3 KiB
JavaScript
Raw Normal View History

2026-02-23 20:14:39 +02:00
import { mapState as mapPiniaState } from 'pinia'
2026-01-06 16:23:17 +02:00
import { defineAsyncComponent } from 'vue'
2021-06-07 16:16:10 +03:00
import { mapGetters, mapState } from 'vuex'
2026-01-08 17:26:52 +02:00
2026-01-06 16:22:52 +02:00
import {
highlightClass,
highlightStyle,
} from '../../services/user_highlighter/user_highlighter.js'
import UnicodeDomainIndicator from '../unicode_domain_indicator/unicode_domain_indicator.vue'
2026-01-06 16:23:17 +02:00
import UserAvatar from '../user_avatar/user_avatar.vue'
2026-02-23 20:14:39 +02:00
import { useSyncConfigStore } from 'src/stores/sync_config.js'
2026-03-16 18:45:57 +02:00
import { useUserHighlightStore } from 'src/stores/user_highlight.js'
2026-02-23 20:14:39 +02:00
2026-01-29 20:40:00 +02:00
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
2026-01-08 17:26:52 +02:00
import { library } from '@fortawesome/fontawesome-svg-core'
import { faAt } from '@fortawesome/free-solid-svg-icons'
2026-01-06 16:22:52 +02:00
library.add(faAt)
2021-06-07 16:16:10 +03:00
const MentionLink = {
name: 'MentionLink',
components: {
UserAvatar,
UnicodeDomainIndicator,
2026-01-06 16:22:52 +02:00
UserPopover: defineAsyncComponent(
() => import('../user_popover/user_popover.vue'),
),
},
2021-06-07 16:16:10 +03:00
props: {
url: {
required: true,
2026-01-06 16:22:52 +02:00
type: String,
2021-06-07 16:16:10 +03:00
},
content: {
required: true,
2026-01-06 16:22:52 +02:00
type: String,
2021-06-07 16:16:10 +03:00
},
2021-06-08 17:04:57 +03:00
userId: {
required: false,
2026-01-06 16:22:52 +02:00
type: String,
2021-06-08 17:04:57 +03:00
},
userScreenName: {
required: false,
2026-01-06 16:22:52 +02:00
type: String,
},
2021-06-07 16:16:10 +03:00
},
2026-01-06 16:22:52 +02:00
data() {
return {
2026-01-06 16:22:52 +02:00
hasSelection: false,
}
},
2021-06-07 16:16:10 +03:00
methods: {
2026-01-06 16:22:52 +02:00
onClick() {
if (this.shouldShowTooltip) return
2021-06-08 17:04:57 +03:00
const link = generateProfileLink(
this.userId || this.user.id,
2026-01-06 16:22:52 +02:00
this.userScreenName || this.user.screen_name,
2021-06-08 17:04:57 +03:00
)
2021-06-07 16:16:10 +03:00
this.$router.push(link)
},
2026-01-06 16:22:52 +02:00
handleSelection() {
2024-12-22 16:41:42 +02:00
if (this.$refs.full) {
2026-01-06 16:22:52 +02:00
this.hasSelection = document
.getSelection()
.containsNode(this.$refs.full, true)
2024-12-22 16:41:42 +02:00
}
2026-01-06 16:22:52 +02:00
},
2021-06-07 16:16:10 +03:00
},
2026-01-06 16:22:52 +02:00
mounted() {
document.addEventListener('selectionchange', this.handleSelection)
},
2026-01-06 16:22:52 +02:00
unmounted() {
document.removeEventListener('selectionchange', this.handleSelection)
},
2021-06-07 16:16:10 +03:00
computed: {
2026-01-06 16:22:52 +02:00
user() {
return (
this.url && this.$store && this.$store.getters.findUserByUrl(this.url)
)
2021-06-07 16:16:10 +03:00
},
2026-01-06 16:22:52 +02:00
isYou() {
2021-06-07 16:16:10 +03:00
// FIXME why user !== currentUser???
return this.user && this.user.id === this.currentUser.id
2021-06-07 16:16:10 +03:00
},
2026-01-06 16:22:52 +02:00
userName() {
2021-06-08 17:04:57 +03:00
return this.user && this.userNameFullUi.split('@')[0]
2021-06-07 16:16:10 +03:00
},
2026-01-06 16:22:52 +02:00
serverName() {
// XXX assumed that domain does not contain @
2026-01-06 16:22:52 +02:00
return (
this.user &&
(this.userNameFullUi.split('@')[1] ||
this.$store.getters.instanceDomain)
)
},
2026-01-06 16:22:52 +02:00
userNameFull() {
2021-06-08 17:04:57 +03:00
return this.user && this.user.screen_name
2021-06-07 16:16:10 +03:00
},
2026-01-06 16:22:52 +02:00
userNameFullUi() {
2021-06-08 17:04:57 +03:00
return this.user && this.user.screen_name_ui
2021-06-07 16:16:10 +03:00
},
2026-03-16 18:45:57 +02:00
highlightData() {
return this.highlight[this.user?.screen_name]
2021-06-07 16:16:10 +03:00
},
2026-01-06 16:22:52 +02:00
highlightType() {
2026-03-16 18:45:57 +02:00
return this.highlightData && '-' + this.highlightData.type
2021-06-07 16:16:10 +03:00
},
2026-01-06 16:22:52 +02:00
highlightClass() {
return this.highlightData && highlightClass(this.user)
2021-06-07 16:16:10 +03:00
},
2026-01-06 16:22:52 +02:00
style() {
2026-03-16 18:45:57 +02:00
if (this.highlightData) {
2021-06-07 23:42:04 +03:00
const {
backgroundColor,
backgroundPosition,
backgroundImage,
...rest
2026-03-16 18:45:57 +02:00
} = highlightStyle(this.highlightData)
2021-06-07 23:42:04 +03:00
return rest
}
2021-06-07 16:16:10 +03:00
},
2026-01-06 16:22:52 +02:00
classnames() {
2021-06-08 11:38:44 +03:00
return [
{
'-you': this.isYou && this.shouldBoldenYou,
2026-03-16 18:45:57 +02:00
'-highlighted': !!this.highlightData,
2026-01-06 16:22:52 +02:00
'-has-selection': this.hasSelection,
2021-06-08 11:38:44 +03:00
},
2026-01-06 16:22:52 +02:00
this.highlightType,
2021-06-08 11:38:44 +03:00
]
},
2026-01-06 16:22:52 +02:00
isRemote() {
return this.userName !== this.userNameFull
},
2026-01-06 16:22:52 +02:00
shouldShowFullUserName() {
const conf = this.mergedConfig.mentionLinkDisplay
if (conf === 'short') {
return false
} else if (conf === 'full') {
return true
2026-01-06 16:22:52 +02:00
} else {
// full_for_remote
return this.isRemote
}
},
2026-01-06 16:22:52 +02:00
shouldShowTooltip() {
return this.mergedConfig.mentionLinkShowTooltip
},
2026-01-06 16:22:52 +02:00
shouldShowAvatar() {
return this.mergedConfig.mentionLinkShowAvatar
},
2026-01-06 16:22:52 +02:00
shouldShowYous() {
return this.mergedConfig.mentionLinkShowYous
},
2026-01-06 16:22:52 +02:00
shouldBoldenYou() {
return this.mergedConfig.mentionLinkBoldenYou
},
2026-01-06 16:22:52 +02:00
shouldFadeDomain() {
return this.mergedConfig.mentionLinkFadeDomain
},
2026-02-23 19:55:43 +02:00
...mapPiniaState(useSyncConfigStore, ['mergedConfig']),
2026-03-16 18:45:57 +02:00
...mapPiniaState(useUserHighlightStore, ['highlight']),
2021-06-07 16:16:10 +03:00
...mapState({
2026-01-06 16:22:52 +02:00
currentUser: (state) => state.users.currentUser,
}),
},
2021-06-07 16:16:10 +03:00
}
export default MentionLink