From 31ef19c3da0748264a18c948c9f43bcf98bc48a8 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 3 Jan 2023 13:48:29 -0400 Subject: [PATCH] fix: use date for timestamps --- example/App.js | 4 ++-- src/index.tsx | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/example/App.js b/example/App.js index 2e9c5bc..e127996 100644 --- a/example/App.js +++ b/example/App.js @@ -82,7 +82,7 @@ export default function App() { let msg = new WakuMessage(); msg.contentTopic = 'ABC'; msg.payload = new Uint8Array([1, 2, 3, 4, 5]); - msg.timestamp = Date.now(); + msg.timestamp = new Date(); msg.version = 0; let messageID = await relayPublish(msg); @@ -92,7 +92,7 @@ export default function App() { // TO RETRIEVE HISTORIC MESSAGES: console.log('Retrieving messages from store node'); const query = new StoreQuery(); - query.contentFilters.push(new ContentFilter('/toy-chat/2/luzhou/proto')); + query.contentFilters.push(new ContentFilter('test-rramos')); const queryResult = await storeQuery( query, '16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm' diff --git a/src/index.tsx b/src/index.tsx index c6d157e..ef9f292 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -20,19 +20,20 @@ export function multiply(a: number, b: number): Promise { return ReactNative.multiply(a, b); } +const OneMillion = BigInt(1_000_000); export class WakuMessage { payload: Uint8Array = new Uint8Array(); contentTopic: String | null = ""; version: Number | null = 0; - timestamp: Number | null = null; + timestamp?: Date = undefined; toJSON(){ const b64encoded = encode(String.fromCharCode(...this.payload)); return { contentTopic: this.contentTopic, version: this.version, - timestamp: this.timestamp, + timestamp: this.timestamp ? (BigInt(this.timestamp.valueOf()) * OneMillion).toString(10) : 0, payload: b64encoded } } @@ -536,11 +537,11 @@ export class ContentFilter { export class StoreQuery { pubsubTopic: String | null = null contentFilters: Array = Array() - startTime: Number = 0 - endTime: Number = 0 + startTime?: Date = undefined + endTime?: Date = undefined pagingOptions: PagingOptions | null = null - constructor(pubsubTopic: String | null = null, contentFilters: Array = Array(), startTime: Number = 0, endTime: Number = 0, pagingOptions: PagingOptions | null = null) { + constructor(pubsubTopic: String | null = null, contentFilters: Array = Array(), startTime: Date | undefined = undefined, endTime: Date | undefined = undefined, pagingOptions: PagingOptions | null = null) { this.pubsubTopic = pubsubTopic this.contentFilters = contentFilters this.startTime = startTime @@ -558,7 +559,13 @@ export class StoreQuery { */ export function storeQuery(query: StoreQuery, peerID: String = "", timeoutMs: Number = 0): Promise { return new Promise(async (resolve, reject) => { - let queryJSON = JSON.stringify(query) + let queryJSON = JSON.stringify({ + pubsubTopic: query.pubsubTopic, + contentFilters: query.contentFilters, + startTime: query.startTime ? (BigInt(query.startTime.valueOf()) * OneMillion).toString(10) : 0, + endTime: query.endTime ? (BigInt(query.endTime.valueOf()) * OneMillion).toString(10) : 0, + pagingOptions: query.pagingOptions + }) let response = JSON.parse(await ReactNative.storeQuery(queryJSON, peerID, timeoutMs)); if(response.error){