From 17dd08033ec0354ed1cbee31a7f779066f6f9918 Mon Sep 17 00:00:00 2001 From: AlexNi245 Date: Thu, 21 Nov 2024 11:42:30 +0700 Subject: [PATCH] streamline message related types --- packages/js-sdk/src/conversation/types.ts | 6 +-- packages/js-sdk/src/message/Messages.ts | 6 +-- .../src/message/renderer/renderMessage.ts | 2 +- packages/js-sdk/src/message/types.ts | 37 +++++++++++++++++++ 4 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 packages/js-sdk/src/message/types.ts diff --git a/packages/js-sdk/src/conversation/types.ts b/packages/js-sdk/src/conversation/types.ts index e970d7cc4..469d223e9 100644 --- a/packages/js-sdk/src/conversation/types.ts +++ b/packages/js-sdk/src/conversation/types.ts @@ -3,11 +3,7 @@ import { DeliveryServiceProfile, getAccountDisplayName, } from '@dm3-org/dm3-lib-profile'; - -class Messages { - public readonly list: string[]; - public addMessage(message: string) {} -} +import { Messages } from '../message/Messages'; export interface Contact { name: string; diff --git a/packages/js-sdk/src/message/Messages.ts b/packages/js-sdk/src/message/Messages.ts index 69ddfffed..01fe0d428 100644 --- a/packages/js-sdk/src/message/Messages.ts +++ b/packages/js-sdk/src/message/Messages.ts @@ -2,7 +2,6 @@ import { encryptAsymmetric } from '@dm3-org/dm3-lib-crypto'; import { buildEnvelop, EncryptionEnvelop, - Envelop, getEnvelopSize, Message, MessageState, @@ -13,10 +12,7 @@ import { ProfileKeys, } from '@dm3-org/dm3-lib-profile'; import { sha256, stringify } from '@dm3-org/dm3-lib-shared'; -import { - StorageAPI, - StorageEnvelopContainer as StorageEnvelopContainerNew, -} from '@dm3-org/dm3-lib-storage'; +import { StorageAPI } from '@dm3-org/dm3-lib-storage'; import { submitEnvelopsToReceiversDs } from '../api/ds/submitEnvelopsToReceiversDs'; import { Conversations } from '../conversation/Conversations'; import { Contact } from '../conversation/types'; diff --git a/packages/js-sdk/src/message/renderer/renderMessage.ts b/packages/js-sdk/src/message/renderer/renderMessage.ts index f16dabe96..01701c1de 100644 --- a/packages/js-sdk/src/message/renderer/renderMessage.ts +++ b/packages/js-sdk/src/message/renderer/renderMessage.ts @@ -1,4 +1,4 @@ -import { MessageModel } from '../Messages'; +import { MessageModel } from '../types'; import { renderDelete } from './messageTypes/renderDelete'; import { renderDuplicates } from './messageTypes/renderDuplicates'; import { renderEdit } from './messageTypes/renderEdit'; diff --git a/packages/js-sdk/src/message/types.ts b/packages/js-sdk/src/message/types.ts new file mode 100644 index 000000000..8bf7dabe6 --- /dev/null +++ b/packages/js-sdk/src/message/types.ts @@ -0,0 +1,37 @@ +import { Envelop } from '@dm3-org/dm3-lib-messaging'; +import { + StorageAPI, + StorageEnvelopContainer as StorageEnvelopContainerNew, +} from '@dm3-org/dm3-lib-storage'; +export enum MessageActionType { + NEW = 'NEW', + EDIT = 'EDIT', + DELETE = 'DELETE_REQUEST', + REPLY = 'REPLY', + REACT = 'REACTION', + NONE = 'NONE', +} + +export enum MessageIndicator { + SENT = 'SENT', + RECEIVED = 'RECEIVED', + READED = 'READED', +} +//Message source to identify where a message comes from. This is important to handle pagination of storage messages properly +export enum MessageSource { + //Messages added by the client via addMessage + Client, + //Messages fetched from the storage + Storage, + //Messages fetched from the deliveryService + DeliveryService, + //Messages received from the Websocket + WebSocket, +} + +export type MessageModel = StorageEnvelopContainerNew & { + reactions: Envelop[]; + replyToMessageEnvelop?: Envelop; + source: MessageSource; + indicator?: MessageIndicator; +};