chore: handle messages via websockets (#2473)
* chore: handle messages via websockets * chore: update domain events * fix: specs * fix: adjust server revision creation delay
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
import { Either } from '@standardnotes/common'
|
||||
import { UserRolesChangedEventPayload, NotificationAddedForUserEventPayload } from '@standardnotes/domain-events'
|
||||
|
||||
export interface WebSocketsEventData {
|
||||
type: string
|
||||
payload: Either<UserRolesChangedEventPayload, NotificationAddedForUserEventPayload>
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
export enum WebSocketsServiceEvent {
|
||||
UserRoleMessageReceived = 'WebSocketMessageReceived',
|
||||
NotificationAddedForUser = 'NotificationAddedForUser',
|
||||
MessageSentToUser = 'MessageSentToUser',
|
||||
}
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
import { isErrorResponse } from '@standardnotes/responses'
|
||||
import {
|
||||
DomainEventInterface,
|
||||
UserRolesChangedEvent,
|
||||
NotificationAddedForUserEvent,
|
||||
} from '@standardnotes/domain-events'
|
||||
import { DomainEventInterface } from '@standardnotes/domain-events'
|
||||
import { WebSocketApiServiceInterface } from '@standardnotes/api'
|
||||
import { WebSocketsServiceEvent } from './WebSocketsServiceEvent'
|
||||
import { StorageServiceInterface } from '../Storage/StorageServiceInterface'
|
||||
import { InternalEventBusInterface } from '../Internal/InternalEventBusInterface'
|
||||
import { AbstractService } from '../Service/AbstractService'
|
||||
import { StorageKey } from '../Storage/StorageKeys'
|
||||
import { WebSocketsEventData } from './WebSocketsEventData'
|
||||
|
||||
export class WebSocketsService extends AbstractService<WebSocketsServiceEvent, WebSocketsEventData> {
|
||||
export class WebSocketsService extends AbstractService<WebSocketsServiceEvent, DomainEventInterface> {
|
||||
private webSocket?: WebSocket
|
||||
|
||||
constructor(
|
||||
@@ -68,13 +63,13 @@ export class WebSocketsService extends AbstractService<WebSocketsServiceEvent, W
|
||||
const eventData: DomainEventInterface = JSON.parse(messageEvent.data)
|
||||
switch (eventData.type) {
|
||||
case 'USER_ROLES_CHANGED':
|
||||
void this.notifyEvent(WebSocketsServiceEvent.UserRoleMessageReceived, eventData as UserRolesChangedEvent)
|
||||
void this.notifyEvent(WebSocketsServiceEvent.UserRoleMessageReceived, eventData)
|
||||
break
|
||||
case 'NOTIFICATION_ADDED_FOR_USER':
|
||||
void this.notifyEvent(
|
||||
WebSocketsServiceEvent.NotificationAddedForUser,
|
||||
eventData as NotificationAddedForUserEvent,
|
||||
)
|
||||
void this.notifyEvent(WebSocketsServiceEvent.NotificationAddedForUser, eventData)
|
||||
break
|
||||
case 'MESSAGE_SENT_TO_USER':
|
||||
void this.notifyEvent(WebSocketsServiceEvent.MessageSentToUser, eventData)
|
||||
break
|
||||
default:
|
||||
break
|
||||
|
||||
@@ -90,6 +90,7 @@ describe('AsymmetricMessageService', () => {
|
||||
encrypted_message: 'encrypted_message',
|
||||
created_at_timestamp: 2,
|
||||
updated_at_timestamp: 2,
|
||||
replaceability_identifier: null,
|
||||
},
|
||||
{
|
||||
uuid: 'misc-message',
|
||||
@@ -98,6 +99,7 @@ describe('AsymmetricMessageService', () => {
|
||||
encrypted_message: 'encrypted_message',
|
||||
created_at_timestamp: 1,
|
||||
updated_at_timestamp: 1,
|
||||
replaceability_identifier: null,
|
||||
},
|
||||
]
|
||||
|
||||
@@ -135,6 +137,7 @@ describe('AsymmetricMessageService', () => {
|
||||
encrypted_message: 'encrypted_message',
|
||||
created_at_timestamp: 2,
|
||||
updated_at_timestamp: 2,
|
||||
replaceability_identifier: null,
|
||||
}
|
||||
|
||||
const decryptedMessagePayload: AsymmetricMessageTrustedContactShare = {
|
||||
@@ -168,6 +171,7 @@ describe('AsymmetricMessageService', () => {
|
||||
encrypted_message: 'encrypted_message',
|
||||
created_at_timestamp: 2,
|
||||
updated_at_timestamp: 2,
|
||||
replaceability_identifier: null,
|
||||
},
|
||||
{
|
||||
uuid: 'older-message',
|
||||
@@ -176,6 +180,7 @@ describe('AsymmetricMessageService', () => {
|
||||
encrypted_message: 'encrypted_message',
|
||||
created_at_timestamp: 1,
|
||||
updated_at_timestamp: 1,
|
||||
replaceability_identifier: null,
|
||||
},
|
||||
]
|
||||
|
||||
@@ -202,6 +207,7 @@ describe('AsymmetricMessageService', () => {
|
||||
encrypted_message: 'encrypted_message',
|
||||
created_at_timestamp: 2,
|
||||
updated_at_timestamp: 2,
|
||||
replaceability_identifier: null,
|
||||
}
|
||||
|
||||
const decryptedMessagePayload: AsymmetricMessageTrustedContactShare = {
|
||||
@@ -230,6 +236,7 @@ describe('AsymmetricMessageService', () => {
|
||||
encrypted_message: 'encrypted_message',
|
||||
created_at_timestamp: 2,
|
||||
updated_at_timestamp: 2,
|
||||
replaceability_identifier: null,
|
||||
}
|
||||
|
||||
const decryptedMessagePayload: AsymmetricMessageSenderKeypairChanged = {
|
||||
@@ -259,6 +266,7 @@ describe('AsymmetricMessageService', () => {
|
||||
encrypted_message: 'encrypted_message',
|
||||
created_at_timestamp: 2,
|
||||
updated_at_timestamp: 2,
|
||||
replaceability_identifier: null,
|
||||
}
|
||||
|
||||
const decryptedMessagePayload: AsymmetricMessageSharedVaultRootKeyChanged = {
|
||||
@@ -287,6 +295,7 @@ describe('AsymmetricMessageService', () => {
|
||||
encrypted_message: 'encrypted_message',
|
||||
created_at_timestamp: 2,
|
||||
updated_at_timestamp: 2,
|
||||
replaceability_identifier: null,
|
||||
}
|
||||
|
||||
const decryptedMessagePayload: AsymmetricMessageSharedVaultMetadataChanged = {
|
||||
@@ -317,6 +326,7 @@ describe('AsymmetricMessageService', () => {
|
||||
encrypted_message: 'encrypted_message',
|
||||
created_at_timestamp: 2,
|
||||
updated_at_timestamp: 2,
|
||||
replaceability_identifier: null,
|
||||
}
|
||||
|
||||
const decryptedMessagePayload: AsymmetricMessageSharedVaultInvite = {
|
||||
@@ -343,6 +353,7 @@ describe('AsymmetricMessageService', () => {
|
||||
encrypted_message: 'encrypted_message',
|
||||
created_at_timestamp: 2,
|
||||
updated_at_timestamp: 2,
|
||||
replaceability_identifier: null,
|
||||
}
|
||||
|
||||
const decryptedMessagePayload: AsymmetricMessageTrustedContactShare = {
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
import { GetKeyPairs } from './../Encryption/UseCase/GetKeyPairs'
|
||||
import { SyncServiceInterface } from './../Sync/SyncServiceInterface'
|
||||
import { SessionsClientInterface } from './../Session/SessionsClientInterface'
|
||||
import { MutatorClientInterface } from './../Mutator/MutatorClientInterface'
|
||||
import { MessageSentToUserEvent } from '@standardnotes/domain-events'
|
||||
import { AsymmetricMessageServerHash } from '@standardnotes/responses'
|
||||
import { SyncEvent, SyncEventReceivedAsymmetricMessagesData } from '../Event/SyncEvent'
|
||||
import { InternalEventBusInterface } from '../Internal/InternalEventBusInterface'
|
||||
import { InternalEventHandlerInterface } from '../Internal/InternalEventHandlerInterface'
|
||||
import { InternalEventInterface } from '../Internal/InternalEventInterface'
|
||||
import { AbstractService } from '../Service/AbstractService'
|
||||
import { GetTrustedPayload } from './UseCase/GetTrustedPayload'
|
||||
import { AsymmetricMessageServer } from '@standardnotes/api'
|
||||
import {
|
||||
AsymmetricMessageSharedVaultRootKeyChanged,
|
||||
AsymmetricMessagePayloadType,
|
||||
@@ -21,8 +13,19 @@ import {
|
||||
PayloadEmitSource,
|
||||
VaultListingInterface,
|
||||
} from '@standardnotes/models'
|
||||
import { Result } from '@standardnotes/domain-core'
|
||||
|
||||
import { GetKeyPairs } from './../Encryption/UseCase/GetKeyPairs'
|
||||
import { SyncServiceInterface } from './../Sync/SyncServiceInterface'
|
||||
import { SessionsClientInterface } from './../Session/SessionsClientInterface'
|
||||
import { MutatorClientInterface } from './../Mutator/MutatorClientInterface'
|
||||
import { SyncEvent, SyncEventReceivedAsymmetricMessagesData } from '../Event/SyncEvent'
|
||||
import { InternalEventBusInterface } from '../Internal/InternalEventBusInterface'
|
||||
import { InternalEventHandlerInterface } from '../Internal/InternalEventHandlerInterface'
|
||||
import { InternalEventInterface } from '../Internal/InternalEventInterface'
|
||||
import { AbstractService } from '../Service/AbstractService'
|
||||
import { GetTrustedPayload } from './UseCase/GetTrustedPayload'
|
||||
import { HandleRootKeyChangedMessage } from './UseCase/HandleRootKeyChangedMessage'
|
||||
import { AsymmetricMessageServer } from '@standardnotes/api'
|
||||
import { GetOutboundMessages } from './UseCase/GetOutboundMessages'
|
||||
import { GetInboundMessages } from './UseCase/GetInboundMessages'
|
||||
import { GetVault } from '../Vault/UseCase/GetVault'
|
||||
@@ -32,7 +35,7 @@ import { FindContact } from '../Contacts/UseCase/FindContact'
|
||||
import { CreateOrEditContact } from '../Contacts/UseCase/CreateOrEditContact'
|
||||
import { ReplaceContactData } from '../Contacts/UseCase/ReplaceContactData'
|
||||
import { EncryptionProviderInterface } from '../Encryption/EncryptionProviderInterface'
|
||||
import { Result } from '@standardnotes/domain-core'
|
||||
import { WebSocketsServiceEvent } from '../Api/WebSocketsServiceEvent'
|
||||
|
||||
export class AsymmetricMessageService
|
||||
extends AbstractService
|
||||
@@ -82,6 +85,9 @@ export class AsymmetricMessageService
|
||||
case SyncEvent.ReceivedAsymmetricMessages:
|
||||
void this.handleRemoteReceivedAsymmetricMessages(event.payload as SyncEventReceivedAsymmetricMessagesData)
|
||||
break
|
||||
case WebSocketsServiceEvent.MessageSentToUser:
|
||||
void this.handleRemoteReceivedAsymmetricMessages([(event as MessageSentToUserEvent).payload.message])
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ export class ResendMessage implements UseCaseInterface<void> {
|
||||
const sendMessageResult = await this.sendMessage.execute({
|
||||
recipientUuid: params.recipient.contactUuid,
|
||||
encryptedMessage: encryptedMessage.getValue(),
|
||||
replaceabilityIdentifier: params.rawMessage.replaceabilityIdentifier,
|
||||
replaceabilityIdentifier: params.rawMessage.replaceability_identifier || undefined,
|
||||
})
|
||||
|
||||
return sendMessageResult
|
||||
|
||||
@@ -4,7 +4,6 @@ export * from './Api/ApiServiceEventData'
|
||||
export * from './Api/LegacyApiServiceInterface'
|
||||
export * from './Api/MetaReceivedData'
|
||||
export * from './Api/SessionRefreshedData'
|
||||
export * from './Api/WebSocketsEventData'
|
||||
export * from './Api/WebsocketsService'
|
||||
export * from './Api/WebSocketsServiceEvent'
|
||||
export * from './Application/AppGroupManagedApplication'
|
||||
|
||||
Reference in New Issue
Block a user