aboutsummaryrefslogtreecommitdiff
path: root/src/components/follow_request_card/follow_request_card.js
blob: cbd75311e82781b6047b84085acae88fe6d96031 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import BasicUserCard from '../basic_user_card/basic_user_card.vue'
import { notificationsFromStore } from '../../services/notification_utils/notification_utils.js'

const FollowRequestCard = {
  props: ['user'],
  components: {
    BasicUserCard
  },
  methods: {
    findFollowRequestNotificationId () {
      const notif = notificationsFromStore(this.$store).find(
        (notif) => notif.from_profile.id === this.user.id && notif.type === 'follow_request'
      )
      return notif && notif.id
    },
    approveUser () {
      this.$store.state.api.backendInteractor.approveUser({ id: this.user.id })
      this.$store.dispatch('removeFollowRequest', this.user)

      const notifId = this.findFollowRequestNotificationId()
      this.$store.dispatch('markSingleNotificationAsSeen', { id: notifId })
      this.$store.dispatch('updateNotification', {
        id: notifId,
        updater: notification => {
          notification.type = 'follow'
        }
      })
    },
    denyUser () {
      const notifId = this.findFollowRequestNotificationId()
      this.$store.state.api.backendInteractor.denyUser({ id: this.user.id })
        .then(() => {
          this.$store.dispatch('dismissNotificationLocal', { id: notifId })
          this.$store.dispatch('removeFollowRequest', this.user)
        })
    }
  }
}

export default FollowRequestCard