Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: chat implementation #1349

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading