Skip to content

Commit

Permalink
expose metadata in messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmbl committed Mar 8, 2024
1 parent 4e7b686 commit 46c0a58
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class SendDappMessageCommand {
message!: string;
notificationTypeId?: string;
addressTypes?: AddressTypeDto[];
tags?: string[];
// tags?: string[];
actions?: DappMessageActionDto[];
}

Expand Down
13 changes: 12 additions & 1 deletion packages/sdk/src/dialect-cloud-api/data-service-dialects-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
withReThrowingDataServiceError,
} from './data-service-api';
import axios from 'axios';

export interface DataServiceDialectsApi {
create(command: CreateDialectCommand): Promise<DialectAccountDto>;

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export class DataServiceMessaging implements Messaging {
? thisThreadMember
: otherMembersPks[lastMessage.owner]!,
deduplicationId: lastMessage.deduplicationId,
metadata: lastMessage.metadata,
};
}

Expand Down Expand Up @@ -311,14 +312,15 @@ 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
: this.otherMembersPks[it.owner]!,
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;
Expand Down
14 changes: 14 additions & 0 deletions packages/sdk/src/messaging/messaging.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 46c0a58

Please sign in to comment.