Skip to content

Commit

Permalink
fix(federation): ensure federation invites appear in store
Browse files Browse the repository at this point in the history
Signed-off-by: Antreesy <[email protected]>
  • Loading branch information
Antreesy committed Aug 27, 2024
1 parent 5c238ad commit 57c6e9a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/federationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion src/stores/__tests__/federation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/stores/federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 57c6e9a

Please sign in to comment.