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

174 lines
4.5 KiB
JavaScript
Raw Normal View History

2026-09-03 21:21:08 +03:00
import { mapActions, mapState } from 'pinia'
2026-01-08 17:26:52 +02:00
import Report from 'src/components/report/report.vue'
import StatusContent from 'src/components/status_content/status_content.vue'
import Timeago from 'src/components/timeago/timeago.vue'
import UserAvatar from 'src/components/user_avatar/user_avatar.vue'
import UserLink from 'src/components/user_link/user_link.vue'
import UserPopover from 'src/components/user_popover/user_popover.vue'
2026-08-11 16:33:43 +03:00
import { isStatusNotification } from '../../services/notification_utils/notification_utils_sw.js'
2026-06-04 21:59:09 +03:00
import {
highlightClass,
highlightStyle,
} from '../../services/user_highlighter/user_highlighter.js'
2026-09-02 17:27:30 +03:00
import { useFollowRequestsStore } from 'src/stores/follow_requests.js'
2026-01-29 20:40:00 +02:00
import { useInstanceStore } from 'src/stores/instance.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useStatusesStore } from 'src/stores/statuses.js'
2026-03-06 15:21:30 +02:00
import { useUserHighlightStore } from 'src/stores/user_highlight.js'
2026-08-10 15:00:59 +03:00
import { useUsersStore } from 'src/stores/users.js'
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 {
faCheck,
faCompressAlt,
faExpandAlt,
faEyeSlash,
faRetweet,
faStar,
faSuitcaseRolling,
faTimes,
faUser,
faUserPlus,
} from '@fortawesome/free-solid-svg-icons'
library.add(
faCheck,
faTimes,
faStar,
faRetweet,
faUserPlus,
faUser,
faEyeSlash,
faSuitcaseRolling,
faExpandAlt,
2026-01-06 16:22:52 +02:00
faCompressAlt,
)
const Notification = {
2026-01-06 16:22:52 +02:00
data() {
return {
2025-08-19 17:28:19 +03:00
selecting: false,
statusExpanded: false,
unmuted: false,
}
},
2022-07-31 12:35:48 +03:00
props: ['notification'],
emits: ['interacted'],
components: {
2020-05-26 01:01:25 +03:00
StatusContent,
2019-06-18 20:28:31 +00:00
UserAvatar,
2020-05-26 01:01:25 +03:00
Timeago,
Report,
UserPopover,
UserLink,
},
2026-01-06 16:22:52 +02:00
mounted() {
2025-08-19 17:28:19 +03:00
document.addEventListener('selectionchange', this.onContentSelect)
},
2026-01-06 16:22:52 +02:00
unmounted() {
2025-08-19 17:28:19 +03:00
document.removeEventListener('selectionchange', this.onContentSelect)
},
methods: {
2026-01-06 16:22:52 +02:00
toggleStatusExpanded() {
if (!this.expandable) return
this.statusExpanded = !this.statusExpanded
2018-12-17 02:52:27 +03:00
},
2026-01-06 16:22:52 +02:00
onContentSelect() {
2025-08-19 17:28:19 +03:00
const { isCollapsed, anchorNode, offsetNode } = document.getSelection()
if (isCollapsed) {
this.selecting = false
return
}
2026-01-06 16:22:52 +02:00
const within =
this.$refs.root.contains(anchorNode) ||
this.$refs.root.contains(offsetNode)
2025-08-19 17:28:19 +03:00
if (within) {
this.selecting = true
} else {
this.selecting = false
}
},
2026-01-06 16:22:52 +02:00
onContentClick(e) {
if (
!this.selecting &&
!e.target.closest('a') &&
!e.target.closest('button')
) {
2025-08-19 17:28:19 +03:00
this.toggleStatusExpanded()
}
},
2026-01-06 16:22:52 +02:00
generateUserProfileLink(user) {
return generateProfileLink(
user.id,
user.screen_name,
useInstanceStore().restrictedNicknames,
2026-01-06 16:22:52 +02:00
)
2019-02-18 17:49:32 +03:00
},
2026-01-06 16:22:52 +02:00
interacted() {
this.$emit('interacted')
},
2026-01-06 16:22:52 +02:00
toggleMute() {
this.unmuted = !this.unmuted
},
2026-09-03 21:21:08 +03:00
...mapActions(useFollowRequestsStore, ['approve', 'deny']),
},
computed: {
status() {
2026-08-18 18:00:36 +03:00
// Used for StatusContent
if (this.notification.status) {
return useStatusesStore().allStatuses.get(this.notification.status.id)
}
},
2026-01-06 16:22:52 +02:00
userClass() {
2019-03-31 21:59:18 -04:00
return highlightClass(this.notification.from_profile)
},
2026-01-06 16:22:52 +02:00
userStyle() {
2026-03-06 15:44:13 +02:00
const user = this.notification.from_profile.screen_name
2026-03-06 15:21:30 +02:00
return highlightStyle(useUserHighlightStore().get(user))
2019-04-01 07:26:13 -07:00
},
2026-01-06 16:22:52 +02:00
expandable() {
return new Set(['like', 'pleroma:emoji_reaction', 'repeat', 'poll']).has(
this.notification.type,
)
},
2026-01-06 16:22:52 +02:00
user() {
2026-08-10 15:00:59 +03:00
return useUsersStore().findUser(this.notification.from_profile.id)
},
2026-01-06 16:22:52 +02:00
userProfileLink() {
2019-09-10 16:21:52 -04:00
return this.generateUserProfileLink(this.user)
},
2026-01-06 16:22:52 +02:00
targetUser() {
2026-08-10 15:00:59 +03:00
return useUsersStore().findUser(this.notification.target.id)
2019-12-11 04:02:25 +09:00
},
2026-01-06 16:22:52 +02:00
targetUserProfileLink() {
2019-12-11 04:02:25 +09:00
return this.generateUserProfileLink(this.targetUser)
},
2026-01-06 16:22:52 +02:00
needMute() {
2026-08-10 15:00:59 +03:00
return useUsersStore().relationship(this.user.id).muting
},
2026-01-06 16:22:52 +02:00
isStatusNotification() {
return isStatusNotification(this.notification.type)
2020-05-07 16:10:53 +03:00
},
2026-01-06 16:22:52 +02:00
mergedConfig() {
return useMergedConfigStore().mergedConfig
},
2026-05-10 17:21:49 +03:00
allowNonSquareEmoji() {
return this.mergedConfig.nonSquareEmoji
},
2026-07-07 11:40:37 +03:00
pauseMfm() {
return this.mergedConfig.pauseMfm
},
scaleMfm() {
return this.mergedConfig.scaleMfm
},
2026-08-10 15:00:59 +03:00
...mapState(useUsersStore, ['currentUser']),
2026-01-06 16:22:52 +02:00
},
}
export default Notification