From 46c0a58c431a57e61763879897cb33ba43773db0 Mon Sep 17 00:00:00 2001 From: Alexey Tsymbal Date: Fri, 8 Mar 2024 14:21:52 +0300 Subject: [PATCH] expose metadata in messages --- .../dialect-cloud-api/data-service-dapps-api.ts | 2 +- .../dialect-cloud-api/data-service-dialects-api.ts | 13 ++++++++++++- .../internal/dapp/data-service-dapp-messages.ts | 2 +- .../internal/messaging/data-service-messaging.ts | 4 +++- packages/sdk/src/messaging/messaging.interface.ts | 14 ++++++++++++++ 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/packages/sdk/src/dialect-cloud-api/data-service-dapps-api.ts b/packages/sdk/src/dialect-cloud-api/data-service-dapps-api.ts index 300529c3..4308cb05 100644 --- a/packages/sdk/src/dialect-cloud-api/data-service-dapps-api.ts +++ b/packages/sdk/src/dialect-cloud-api/data-service-dapps-api.ts @@ -193,7 +193,7 @@ class SendDappMessageCommand { message!: string; notificationTypeId?: string; addressTypes?: AddressTypeDto[]; - tags?: string[]; + // tags?: string[]; actions?: DappMessageActionDto[]; } diff --git a/packages/sdk/src/dialect-cloud-api/data-service-dialects-api.ts b/packages/sdk/src/dialect-cloud-api/data-service-dialects-api.ts index 5a30ea5f..c78cd6a2 100644 --- a/packages/sdk/src/dialect-cloud-api/data-service-dialects-api.ts +++ b/packages/sdk/src/dialect-cloud-api/data-service-dialects-api.ts @@ -4,7 +4,6 @@ import { withReThrowingDataServiceError, } from './data-service-api'; import axios from 'axios'; - export interface DataServiceDialectsApi { create(command: CreateDialectCommand): Promise; @@ -256,11 +255,23 @@ export enum MemberScopeDto { WRITE = 'WRITE', } +export class MessageActionDto { + label!: string; + url!: string; +} +export class MessageMetadataDto { + title?: string; + tags?: string[]; + actions?: MessageActionDto[]; + notificationTypeId?: string; +} + export interface MessageDto { readonly owner: string; readonly text: number[]; readonly timestamp: number; readonly deduplicationId?: string; + readonly metadata?: MessageMetadataDto; } export interface MessagesDto { diff --git a/packages/sdk/src/internal/dapp/data-service-dapp-messages.ts b/packages/sdk/src/internal/dapp/data-service-dapp-messages.ts index 09553539..336f497a 100644 --- a/packages/sdk/src/internal/dapp/data-service-dapp-messages.ts +++ b/packages/sdk/src/internal/dapp/data-service-dapp-messages.ts @@ -50,7 +50,7 @@ export class DataServiceDappMessages implements DappMessages { addressTypes: command?.addressTypes?.map((addr) => toAddressTypeDto(addr), ), - tags: command.tags, + // tags: command.tags, actions: command.actions, }), ); diff --git a/packages/sdk/src/internal/messaging/data-service-messaging.ts b/packages/sdk/src/internal/messaging/data-service-messaging.ts index c67bfd56..ca2c2adf 100644 --- a/packages/sdk/src/internal/messaging/data-service-messaging.ts +++ b/packages/sdk/src/internal/messaging/data-service-messaging.ts @@ -182,6 +182,7 @@ export class DataServiceMessaging implements Messaging { ? thisThreadMember : otherMembersPks[lastMessage.owner]!, deduplicationId: lastMessage.deduplicationId, + metadata: lastMessage.metadata, }; } @@ -311,7 +312,7 @@ export class DataServiceThread implements Thread { const { messages } = await withErrorParsing( this.dataServiceDialectsApi.getMessages(this.address.toString()), ); - const threadMessages = messages.map((it) => ({ + const threadMessages: ThreadMessage[] = messages.map((it) => ({ author: it.owner === this.me.address.toString() ? this.me @@ -319,6 +320,7 @@ export class DataServiceThread implements Thread { timestamp: new Date(it.timestamp), text: this.textSerde.deserialize(new Uint8Array(it.text)), deduplicationId: it.deduplicationId, + metadata: it.metadata, })); this.lastMessage = threadMessages[0] ?? null; return threadMessages; diff --git a/packages/sdk/src/messaging/messaging.interface.ts b/packages/sdk/src/messaging/messaging.interface.ts index f8a33b62..d2e23703 100644 --- a/packages/sdk/src/messaging/messaging.interface.ts +++ b/packages/sdk/src/messaging/messaging.interface.ts @@ -36,10 +36,24 @@ export interface SendMessageCommand { deduplicationId?: string; } +export interface MessageAction { + label: string; + url: string; +} + +export interface MessageMetadata { + title?: string; + // tags?: string[]; + actions?: MessageAction[]; + notificationTypeId?: string; + notificationTypeHumanReadableId?: string; +} + export interface ThreadMessage { text: string; timestamp: Date; author: ThreadMember; + metadata?: MessageMetadata; deduplicationId?: string; }