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

174 lines
4.8 KiB
JavaScript
Raw Permalink Normal View History

2020-05-26 00:01:25 +02:00
import StatusContent from '../status_content/status_content.vue'
2020-05-07 15:10:53 +02:00
import { mapState } from 'vuex'
import Status from '../status/status.vue'
import UserAvatar from '../user_avatar/user_avatar.vue'
2019-03-05 20:01:49 +01:00
import UserCard from '../user_card/user_card.vue'
2019-06-18 22:28:31 +02:00
import Timeago from '../timeago/timeago.vue'
2021-01-11 18:32:58 +01:00
import Report from '../report/report.vue'
import UserLink from '../user_link/user_link.vue'
import RichContent from 'src/components/rich_content/rich_content.jsx'
import UserPopover from '../user_popover/user_popover.vue'
import ConfirmModal from '../confirm_modal/confirm_modal.vue'
import { isStatusNotification } from '../../services/notification_utils/notification_utils.js'
import { highlightClass, highlightStyle } from '../../services/user_highlighter/user_highlighter.js'
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
import { library } from '@fortawesome/fontawesome-svg-core'
import {
faCheck,
faTimes,
faStar,
faRetweet,
faUserPlus,
faEyeSlash,
faUser,
faSuitcaseRolling,
faExpandAlt,
faCompressAlt
} from '@fortawesome/free-solid-svg-icons'
library.add(
faCheck,
faTimes,
faStar,
faRetweet,
faUserPlus,
faUser,
faEyeSlash,
faSuitcaseRolling,
faExpandAlt,
faCompressAlt
)
const Notification = {
data () {
return {
statusExpanded: false,
betterShadow: this.$store.state.interface.browserSupport.cssFilter,
unmuted: false,
showingApproveConfirmDialog: false,
showingDenyConfirmDialog: false
}
},
2022-07-31 11:35:48 +02:00
props: ['notification'],
emits: ['interacted'],
components: {
2020-05-26 00:01:25 +02:00
StatusContent,
2019-06-18 22:28:31 +02:00
UserAvatar,
UserCard,
2020-05-26 00:01:25 +02:00
Timeago,
2021-01-11 18:32:58 +01:00
Status,
Report,
RichContent,
UserPopover,
UserLink,
ConfirmModal
},
methods: {
toggleStatusExpanded () {
this.statusExpanded = !this.statusExpanded
2018-12-17 00:52:27 +01:00
},
generateUserProfileLink (user) {
return generateProfileLink(user.id, user.screen_name, this.$store.state.instance.restrictedNicknames)
2019-02-18 15:49:32 +01:00
},
getUser (notification) {
2019-04-12 09:49:22 +02:00
return this.$store.state.users.usersObject[notification.from_profile.id]
},
interacted () {
this.$emit('interacted')
},
toggleMute () {
this.unmuted = !this.unmuted
},
showApproveConfirmDialog () {
this.showingApproveConfirmDialog = true
},
hideApproveConfirmDialog () {
this.showingApproveConfirmDialog = false
},
showDenyConfirmDialog () {
this.showingDenyConfirmDialog = true
},
hideDenyConfirmDialog () {
this.showingDenyConfirmDialog = false
},
approveUser () {
if (this.shouldConfirmApprove) {
this.showApproveConfirmDialog()
} else {
this.doApprove()
}
},
doApprove () {
this.$emit('interacted')
this.$store.state.api.backendInteractor.approveUser({ id: this.user.id })
this.$store.dispatch('removeFollowRequest', this.user)
this.$store.dispatch('markSingleNotificationAsSeen', { id: this.notification.id })
this.$store.dispatch('updateNotification', {
id: this.notification.id,
updater: notification => {
notification.type = 'follow'
}
})
this.hideApproveConfirmDialog()
},
denyUser () {
if (this.shouldConfirmDeny) {
this.showDenyConfirmDialog()
} else {
this.doDeny()
}
},
doDeny () {
this.$emit('interacted')
this.$store.state.api.backendInteractor.denyUser({ id: this.user.id })
.then(() => {
this.$store.dispatch('dismissNotificationLocal', { id: this.notification.id })
this.$store.dispatch('removeFollowRequest', this.user)
})
this.hideDenyConfirmDialog()
}
},
computed: {
userClass () {
2019-04-01 03:59:18 +02:00
return highlightClass(this.notification.from_profile)
},
userStyle () {
const highlight = this.$store.getters.mergedConfig.highlight
2019-04-01 03:59:18 +02:00
const user = this.notification.from_profile
return highlightStyle(highlight[user.screen_name])
2019-04-01 16:26:13 +02:00
},
user () {
2019-12-11 10:48:18 +01:00
return this.$store.getters.findUser(this.notification.from_profile.id)
},
userProfileLink () {
2019-09-10 22:21:52 +02:00
return this.generateUserProfileLink(this.user)
},
2019-12-10 20:02:25 +01:00
targetUser () {
2019-12-11 10:48:18 +01:00
return this.$store.getters.findUser(this.notification.target.id)
2019-12-10 20:02:25 +01:00
},
targetUserProfileLink () {
return this.generateUserProfileLink(this.targetUser)
},
needMute () {
return this.$store.getters.relationship(this.user.id).muting
},
isStatusNotification () {
return isStatusNotification(this.notification.type)
2020-05-07 15:10:53 +02:00
},
mergedConfig () {
return this.$store.getters.mergedConfig
},
shouldConfirmApprove () {
return this.mergedConfig.modalOnApproveFollow
},
shouldConfirmDeny () {
return this.mergedConfig.modalOnDenyFollow
},
2020-05-07 15:10:53 +02:00
...mapState({
currentUser: state => state.users.currentUser
})
}
}
export default Notification