Skip to content

Commit

Permalink
fix: chat implementation (#1349)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammeds1992 authored Jun 12, 2024
1 parent 4aa6e97 commit f5778ba
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/restapi/src/lib/pushapi/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,32 @@ export class Chat {
return historyMessages.map((message: any) => ({ ...message, listType }));
}

async message(
target: string,
options?: {
reference?: string | null;
}
) {
let reference: string;

const { threadHash, intent } = await PUSH_CHAT.conversationHash({
conversationId: target,
account: this.account,
env: this.env,
});

reference = options?.reference || threadHash;

if (!reference) return {};

const historyMessages = await this.history(target, { reference, limit: 1 });
const listType = intent ? 'CHATS' : 'REQUESTS';

return historyMessages.length > 0
? { ...historyMessages[0], listType }
: null;
}

async send(recipient: string, options: Message): Promise<MessageWithCID> {
if (!this.decryptedPgpPvtKey) {
throw new Error(PushAPI.ensureSignerMessage());
Expand Down

0 comments on commit f5778ba

Please sign in to comment.