chore: handle notification on guest when host cancels invite (#2537)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user