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
|
|
|
|
|
|
|
|
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
|
2026-01-06 16:22:52 +02:00
|
|
|
import {
|
|
|
|
|
highlightClass,
|
|
|
|
|
highlightStyle,
|
|
|
|
|
} from '../../services/user_highlighter/user_highlighter.js'
|
2022-08-29 18:46:41 -04:00
|
|
|
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'
|
2021-06-10 13:29:59 +03:00
|
|
|
|
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',
|
2022-01-10 02:05:41 -05:00
|
|
|
components: {
|
2022-06-12 16:31:56 +03:00
|
|
|
UserAvatar,
|
2022-08-29 18:46:41 -04:00
|
|
|
UnicodeDomainIndicator,
|
2026-01-06 16:22:52 +02:00
|
|
|
UserPopover: defineAsyncComponent(
|
|
|
|
|
() => import('../user_popover/user_popover.vue'),
|
|
|
|
|
),
|
2022-01-10 02:05:41 -05:00
|
|
|
},
|
2021-06-07 16:16:10 +03:00
|
|
|
props: {
|
|
|
|
|
url: {
|
2021-06-10 12:08:31 +03:00
|
|
|
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() {
|
2022-06-27 14:26:47 +03:00
|
|
|
return {
|
2026-01-06 16:22:52 +02:00
|
|
|
hasSelection: false,
|
2022-06-27 14:26:47 +03:00
|
|
|
}
|
|
|
|
|
},
|
2021-06-07 16:16:10 +03:00
|
|
|
methods: {
|
2026-01-06 16:22:52 +02:00
|
|
|
onClick() {
|
2022-06-12 16:31:56 +03:00
|
|
|
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)
|
2022-06-27 14:26:47 +03:00
|
|
|
},
|
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() {
|
2022-06-27 14:26:47 +03:00
|
|
|
document.addEventListener('selectionchange', this.handleSelection)
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
unmounted() {
|
2022-06-27 14:26:47 +03:00
|
|
|
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???
|
2021-08-15 02:41:53 +03:00
|
|
|
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() {
|
2022-01-10 01:16:33 -05:00
|
|
|
// 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)
|
|
|
|
|
)
|
2022-01-10 01:16:33 -05:00
|
|
|
},
|
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-01-06 16:22:52 +02:00
|
|
|
highlight() {
|
2021-06-08 17:04:57 +03:00
|
|
|
return this.user && this.mergedConfig.highlight[this.user.screen_name]
|
2021-06-07 16:16:10 +03:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
highlightType() {
|
|
|
|
|
return this.highlight && '-' + this.highlight.type
|
2021-06-07 16:16:10 +03:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
highlightClass() {
|
2021-06-07 23:42:04 +03:00
|
|
|
if (this.highlight) return highlightClass(this.user)
|
2021-06-07 16:16:10 +03:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
style() {
|
2021-06-07 23:42:04 +03:00
|
|
|
if (this.highlight) {
|
|
|
|
|
const {
|
|
|
|
|
backgroundColor,
|
|
|
|
|
backgroundPosition,
|
|
|
|
|
backgroundImage,
|
|
|
|
|
...rest
|
|
|
|
|
} = highlightStyle(this.highlight)
|
|
|
|
|
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 [
|
|
|
|
|
{
|
2022-02-03 22:34:57 +02:00
|
|
|
'-you': this.isYou && this.shouldBoldenYou,
|
2022-06-27 14:26:47 +03:00
|
|
|
'-highlighted': this.highlight,
|
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() {
|
2022-01-10 01:16:33 -05:00
|
|
|
return this.userName !== this.userNameFull
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
shouldShowFullUserName() {
|
2022-01-10 01:16:33 -05:00
|
|
|
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
|
2022-01-10 01:16:33 -05:00
|
|
|
return this.isRemote
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
shouldShowTooltip() {
|
2022-06-12 16:31:56 +03:00
|
|
|
return this.mergedConfig.mentionLinkShowTooltip
|
2022-01-10 01:16:33 -05:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
shouldShowAvatar() {
|
2022-01-10 02:05:41 -05:00
|
|
|
return this.mergedConfig.mentionLinkShowAvatar
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
shouldShowYous() {
|
2022-02-03 22:34:57 +02:00
|
|
|
return this.mergedConfig.mentionLinkShowYous
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
shouldBoldenYou() {
|
2022-02-03 22:34:57 +02:00
|
|
|
return this.mergedConfig.mentionLinkBoldenYou
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
shouldFadeDomain() {
|
2022-01-10 02:31:26 -05:00
|
|
|
return this.mergedConfig.mentionLinkFadeDomain
|
|
|
|
|
},
|
2021-06-07 16:16:10 +03:00
|
|
|
...mapGetters(['mergedConfig']),
|
|
|
|
|
...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
|