Skip to content

Commit

Permalink
feat: allow numeric timestamp in listMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
peterferguson authored Oct 27, 2023
1 parent c262034 commit 98de258
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DecodedMessage[]> {
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) => {
Expand All @@ -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",
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DecodedMessage[]> {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Query.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 98de258

Please sign in to comment.