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
|
||||
|
||||
Reference in New Issue
Block a user