Skip to content

Commit

Permalink
fixup! feat(federation): manage invitations through the store
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Feb 20, 2024
1 parent 7486bb3 commit 003054b
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions src/stores/federation.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import { defineStore } from 'pinia'
import Vue from 'vue'

import { showError } from '@nextcloud/dialogs'

import { FEDERATION } from '../constants.js'
import { getShares, acceptShare, rejectShare } from '../services/federationService.js'

Expand Down Expand Up @@ -106,16 +108,6 @@ export const useFederationStore = defineStore('federation', {
Vue.set(this.pendingShares, invitation.id, invitation)
},

/**
* Mark an invitation as loading in store.
*
* @param {number} id invitation id
* @param {boolean} value loading state
*/
markInvitationLoading(id, value) {
Vue.set(this.pendingShares[id], 'loading', value)
},

/**
* Mark an invitation as accepted in store.
*
Expand All @@ -126,7 +118,6 @@ export const useFederationStore = defineStore('federation', {
if (!this.pendingShares[id]) {
return
}
Vue.delete(this.pendingShares[id], 'loading')
Vue.set(this.acceptedShares, id, {
...this.pendingShares[id],
accessToken: conversation.remoteAccessToken,
Expand All @@ -146,15 +137,13 @@ export const useFederationStore = defineStore('federation', {
if (!this.pendingShares[id]) {
return
}
this.markInvitationLoading(id, true)
try {
const response = await acceptShare(id)
this.markInvitationLoading(id, false)
this.markInvitationAccepted(id, response.data.ocs.data)
return response.data.ocs.data
} catch (error) {
console.error(error)
this.markInvitationLoading(id, false)
showError(t('spreed', 'An error occurred while accepting an invitation'))
}
},

Expand All @@ -167,13 +156,12 @@ export const useFederationStore = defineStore('federation', {
if (!this.pendingShares[id]) {
return
}
this.markInvitationLoading(id, true)
try {
await rejectShare(id)
Vue.delete(this.pendingShares, id)
} catch (error) {
console.error(error)
this.markInvitationLoading(id, false)
showError(t('spreed', 'An error occurred while rejecting an invitation'))
}
},
},
Expand Down

0 comments on commit 003054b

Please sign in to comment.