Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/services/src/Domain/VaultInvite/VaultInviteService.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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)
}
Expand Down
Expand Up @@ -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)
Expand Down
Expand Up @@ -17,6 +17,7 @@ import {
RoleName,
ProtocolVersion,
compareVersions,
VaultInviteServiceEvent,
} from '@standardnotes/snjs'
import VaultItem from './Vaults/VaultItem'
import Button from '@/Components/Button/Button'
Expand Down Expand Up @@ -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())
Expand Down