From 98de258b0e19a9190bc112217f9a92322ac8cd6a Mon Sep 17 00:00:00 2001 From: Peter Ferguson Date: Fri, 27 Oct 2023 08:57:22 +0100 Subject: [PATCH] feat: allow numeric timestamp in listMessages --- src/index.ts | 12 ++++++------ src/lib/Conversation.ts | 4 ++-- src/lib/Query.ts | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/index.ts b/src/index.ts index 22ed13739..58867f50c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -117,16 +117,16 @@ export async function listMessages( clientAddress: string, conversationTopic: string, limit?: number | undefined, - before?: Date | undefined, - after?: Date | undefined, + before?: number | Date | undefined, + after?: number | Date | undefined, direction?: "SORT_DIRECTION_ASCENDING" | "SORT_DIRECTION_DESCENDING" | undefined, ): Promise { const messages = await XMTPModule.loadMessages( clientAddress, conversationTopic, limit, - before?.getTime(), - after?.getTime(), + typeof before === 'number' ? before : before?.getTime(), + typeof after === 'number' ? after : after?.getTime(), direction || "SORT_DIRECTION_DESCENDING", ); return messages.map((json: string) => { @@ -142,8 +142,8 @@ export async function listBatchMessages( return JSON.stringify({ limit: item.pageSize || 0, topic: item.contentTopic, - after: item.startTime?.getTime() || 0, - before: item.endTime?.getTime() || 0, + after: (typeof item.startTime === 'number' ? item.startTime : item.startTime?.getTime()) || 0, + before: (typeof item.endTime === 'number' ? item.endTime : item.endTime?.getTime()) || 0, direction: item.direction || "SORT_DIRECTION_DESCENDING", }); }); diff --git a/src/lib/Conversation.ts b/src/lib/Conversation.ts index c400f285a..59f475106 100644 --- a/src/lib/Conversation.ts +++ b/src/lib/Conversation.ts @@ -39,8 +39,8 @@ export class Conversation { // TODO: Support pagination and conversation ID here async messages( limit?: number | undefined, - before?: Date | undefined, - after?: Date | undefined, + before?: number | Date | undefined, + after?: number | Date | undefined, direction?: "SORT_DIRECTION_ASCENDING" | "SORT_DIRECTION_DESCENDING" | undefined, ): Promise { try { diff --git a/src/lib/Query.ts b/src/lib/Query.ts index cacb975df..9ff918c16 100644 --- a/src/lib/Query.ts +++ b/src/lib/Query.ts @@ -1,6 +1,6 @@ export type Query = { - startTime?: Date | undefined; - endTime?: Date | undefined; + startTime?: number | Date | undefined; + endTime?: number | Date | undefined; contentTopic: string; pageSize?: number | undefined; direction?: "SORT_DIRECTION_ASCENDING" | "SORT_DIRECTION_DESCENDING" | undefined;