2019-02-26 04:34:24 +00:00
|
|
|
import BasicUserCard from '../basic_user_card/basic_user_card.vue'
|
2022-08-26 11:58:33 +00:00
|
|
|
import ConfirmModal from '../confirm_modal/confirm_modal.vue'
|
2020-05-02 07:19:47 +00:00
|
|
|
import { notificationsFromStore } from '../../services/notification_utils/notification_utils.js'
|
2019-02-26 04:34:24 +00:00
|
|
|
|
|
|
|
const FollowRequestCard = {
|
|
|
|
props: ['user'],
|
|
|
|
components: {
|
2022-08-26 11:58:33 +00:00
|
|
|
BasicUserCard,
|
|
|
|
ConfirmModal
|
|
|
|
},
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
showingApproveConfirmDialog: false,
|
|
|
|
showingDenyConfirmDialog: false
|
|
|
|
}
|
2019-02-26 04:34:24 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2020-05-02 07:19:47 +00:00
|
|
|
findFollowRequestNotificationId () {
|
|
|
|
const notif = notificationsFromStore(this.$store).find(
|
|
|
|
(notif) => notif.from_profile.id === this.user.id && notif.type === 'follow_request'
|
|
|
|
)
|
|
|
|
return notif && notif.id
|
|
|
|
},
|
2022-08-26 11:58:33 +00:00
|
|
|
showApproveConfirmDialog () {
|
|
|
|
this.showingApproveConfirmDialog = true
|
|
|
|
},
|
|
|
|
hideApproveConfirmDialog () {
|
|
|
|
this.showingApproveConfirmDialog = false
|
|
|
|
},
|
|
|
|
showDenyConfirmDialog () {
|
|
|
|
this.showingDenyConfirmDialog = true
|
|
|
|
},
|
|
|
|
hideDenyConfirmDialog () {
|
|
|
|
this.showingDenyConfirmDialog = false
|
|
|
|
},
|
2019-02-26 04:34:24 +00:00
|
|
|
approveUser () {
|
2022-08-26 11:58:33 +00:00
|
|
|
if (this.shouldConfirmApprove) {
|
|
|
|
this.showApproveConfirmDialog()
|
|
|
|
} else {
|
|
|
|
this.doApprove()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
doApprove () {
|
2019-11-24 11:57:46 +00:00
|
|
|
this.$store.state.api.backendInteractor.approveUser({ id: this.user.id })
|
2019-02-26 04:34:24 +00:00
|
|
|
this.$store.dispatch('removeFollowRequest', this.user)
|
2020-05-02 07:19:47 +00:00
|
|
|
|
|
|
|
const notifId = this.findFollowRequestNotificationId()
|
2020-05-02 07:52:57 +00:00
|
|
|
this.$store.dispatch('markSingleNotificationAsSeen', { id: notifId })
|
2020-05-02 07:19:47 +00:00
|
|
|
this.$store.dispatch('updateNotification', {
|
|
|
|
id: notifId,
|
|
|
|
updater: notification => {
|
|
|
|
notification.type = 'follow'
|
|
|
|
}
|
|
|
|
})
|
2022-08-26 11:58:33 +00:00
|
|
|
this.hideApproveConfirmDialog()
|
2019-02-26 04:34:24 +00:00
|
|
|
},
|
|
|
|
denyUser () {
|
2022-08-26 11:58:33 +00:00
|
|
|
if (this.shouldConfirmDeny) {
|
|
|
|
this.showDenyConfirmDialog()
|
|
|
|
} else {
|
|
|
|
this.doDeny()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
doDeny () {
|
2020-05-02 07:19:47 +00:00
|
|
|
const notifId = this.findFollowRequestNotificationId()
|
2020-05-02 08:51:39 +00:00
|
|
|
this.$store.state.api.backendInteractor.denyUser({ id: this.user.id })
|
|
|
|
.then(() => {
|
|
|
|
this.$store.dispatch('dismissNotificationLocal', { id: notifId })
|
|
|
|
this.$store.dispatch('removeFollowRequest', this.user)
|
|
|
|
})
|
2022-08-26 11:58:33 +00:00
|
|
|
this.hideDenyConfirmDialog()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
mergedConfig () {
|
|
|
|
return this.$store.getters.mergedConfig
|
|
|
|
},
|
|
|
|
shouldConfirmApprove () {
|
|
|
|
return this.mergedConfig.modalOnApproveFollow
|
|
|
|
},
|
|
|
|
shouldConfirmDeny () {
|
|
|
|
return this.mergedConfig.modalOnDenyFollow
|
2019-02-26 04:34:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default FollowRequestCard
|