chore: handle notification on guest when host cancels invite (#2537)

This commit is contained in:
Aman Harwara
2023-09-26 15:53:18 +05:30
committed by GitHub
parent 3777a5389e
commit b2ead8fc84
3 changed files with 24 additions and 1 deletions

View File

@@ -6,7 +6,7 @@ import {
isClientDisplayableError,
isErrorResponse,
} from '@standardnotes/responses'
import { ContentType, Result } from '@standardnotes/domain-core'
import { ContentType, NotificationType, Result } from '@standardnotes/domain-core'
import { SharedVaultInvitesServer } from '@standardnotes/api'
import {
AsymmetricMessageSharedVaultInvite,
@@ -40,6 +40,7 @@ import { DecryptErroredPayloads } from '../Encryption/UseCase/DecryptErroredPayl
import { StatusServiceInterface } from '../Status/StatusServiceInterface'
import { ApplicationEvent } from '../Event/ApplicationEvent'
import { WebSocketsServiceEvent } from '../Api/WebSocketsServiceEvent'
import { NotificationServiceEvent, NotificationServiceEventPayload } from '../UserEvent/NotificationServiceEvent'
export class VaultInviteService
extends AbstractService<VaultInviteServiceEvent>
@@ -124,12 +125,25 @@ export class VaultInviteService
}
void this.downloadInboundInvites()
break
case NotificationServiceEvent.NotificationReceived:
await this.handleNotification(event.payload as NotificationServiceEventPayload)
break
case WebSocketsServiceEvent.UserInvitedToSharedVault:
await this.processInboundInvites([(event as UserInvitedToSharedVaultEvent).payload.invite])
break
}
}
private async handleNotification(event: NotificationServiceEventPayload): Promise<void> {
switch (event.eventPayload.props.type.value) {
case NotificationType.TYPES.SharedVaultInviteCanceled: {
this.removePendingInvite(event.eventPayload.props.primaryIdentifier.value)
void this.notifyEvent(VaultInviteServiceEvent.InvitesReloaded)
break
}
}
}
public getCachedPendingInviteRecords(): InviteRecord[] {
return Object.values(this.pendingInvites)
}

View File

@@ -31,6 +31,7 @@ export function RegisterApplicationServicesEvents(container: Dependencies, event
events.addEventHandler(container.get(TYPES.SessionManager), ApiServiceEvent.SessionRefreshed)
events.addEventHandler(container.get(TYPES.SessionManager), ApplicationEvent.ApplicationStageChanged)
events.addEventHandler(container.get(TYPES.SharedVaultService), NotificationServiceEvent.NotificationReceived)
events.addEventHandler(container.get(TYPES.VaultInviteService), NotificationServiceEvent.NotificationReceived)
events.addEventHandler(container.get(TYPES.SharedVaultService), SessionEvent.UserKeyPairChanged)
events.addEventHandler(container.get(TYPES.SharedVaultService), SyncEvent.ReceivedRemoteSharedVaults)
events.addEventHandler(container.get(TYPES.SubscriptionManager), ApplicationEvent.ApplicationStageChanged)

View File

@@ -17,6 +17,7 @@ import {
RoleName,
ProtocolVersion,
compareVersions,
VaultInviteServiceEvent,
} from '@standardnotes/snjs'
import VaultItem from './Vaults/VaultItem'
import Button from '@/Components/Button/Button'
@@ -70,6 +71,13 @@ const Vaults = observer(() => {
const updateInvites = useCallback(async () => {
setInvites(application.vaultInvites.getCachedPendingInviteRecords())
}, [application.vaultInvites])
useEffect(() => {
return application.vaultInvites.addEventObserver((event) => {
if (event === VaultInviteServiceEvent.InvitesReloaded) {
void updateInvites()
}
})
}, [application.vaultInvites, updateInvites])
const updateContacts = useCallback(async () => {
setContacts(contactService.getAllContacts())