Browse Source

fix(federation): ensure federation invites appear in store

Signed-off-by: Antreesy <antreesy.web@gmail.com>
pull/13149/head
Antreesy 1 year ago
parent
commit
57c6e9a6b3
  1. 4
      src/App.vue
  2. 4
      src/services/federationService.ts
  3. 2
      src/stores/__tests__/federation.spec.js
  4. 8
      src/stores/federation.ts
  5. 2
      src/types/index.ts

4
src/App.vue

@ -543,6 +543,7 @@ export default {
if (event.notification.objectType === 'remote_talk_share') {
try {
event.cancelAction = true
this.federationStore.addInvitationFromNotification(event.notification)
const conversation = await this.federationStore.acceptShare(event.notification.objectId)
if (conversation.token) {
this.$store.dispatch('addConversation', conversation)
@ -559,7 +560,8 @@ export default {
if (event.notification.objectType === 'remote_talk_share') {
try {
event.cancelAction = true
this.federationStore.rejectShare(event.notification.objectId)
this.federationStore.addInvitationFromNotification(event.notification)
await this.federationStore.rejectShare(event.notification.objectId)
} catch (error) {
console.error(error)
}

4
src/services/federationService.ts

@ -23,7 +23,7 @@ const getShares = async function(options?: object): getSharesResponse {
* @param id invitation id;
* @param [options] options;
*/
const acceptShare = async function(id: number, options?: object): acceptShareResponse {
const acceptShare = async function(id: string | number, options?: object): acceptShareResponse {
return axios.post(generateOcsUrl('apps/spreed/api/v1/federation/invitation/{id}', { id }, options), {}, options)
}
@ -33,7 +33,7 @@ const acceptShare = async function(id: number, options?: object): acceptShareRes
* @param id invitation id;
* @param [options] options;
*/
const rejectShare = async function(id: number, options?: object): rejectShareResponse {
const rejectShare = async function(id: string | number, options?: object): rejectShareResponse {
return axios.delete(generateOcsUrl('apps/spreed/api/v1/federation/invitation/{id}', { id }, options), options)
}

2
src/stores/__tests__/federation.spec.js

@ -168,7 +168,7 @@ describe('federationStore', () => {
// Assert
expect(federationStore.pendingShares).toMatchObject({
[invites[0].id]: invites[0],
[notifications[1].objectId]: { id: notifications[1].objectId },
[notifications[1].objectId]: { id: +notifications[1].objectId },
})
expect(federationStore.acceptedShares).toMatchObject({ [invites[1].id]: invites[1] })
expect(federationStore.pendingSharesCount).toBe(2)

8
src/stores/federation.ts

@ -62,7 +62,7 @@ export const useFederationStore = defineStore('federation', {
const [remoteServerUrl, remoteToken] = notification.messageRichParameters.roomName.id.split('::')
const { id, name } = notification.messageRichParameters.user1
const invitation: FederationInvite = {
id: notification.objectId,
id: +notification.objectId,
localToken: '',
localCloudId: notification.user + '@' + getBaseUrl().replace('https://', ''),
remoteAttendeeId: 0,
@ -84,7 +84,7 @@ export const useFederationStore = defineStore('federation', {
* @param id invitation id
* @param conversation conversation object
*/
markInvitationAccepted(id: number, conversation: Conversation) {
markInvitationAccepted(id: string | number, conversation: Conversation) {
if (!this.pendingShares[id]) {
return
}
@ -102,7 +102,7 @@ export const useFederationStore = defineStore('federation', {
*
* @param id invitation id
*/
async acceptShare(id: number): Promise<Conversation | undefined> {
async acceptShare(id: string | number): Promise<Conversation | undefined> {
if (!this.pendingShares[id]) {
return
}
@ -128,7 +128,7 @@ export const useFederationStore = defineStore('federation', {
*
* @param id invitation id
*/
async rejectShare(id: number) {
async rejectShare(id: string | number) {
if (!this.pendingShares[id]) {
return
}

2
src/types/index.ts

@ -33,7 +33,7 @@ export type Notification<T = Record<string, RichObject & Record<string, unknown>
user: string,
datetime: string,
objectType: string,
objectId: number,
objectId: string,
subject: string,
message: string,
link: string,

Loading…
Cancel
Save