fix: use date for timestamps

This commit is contained in:
Richard Ramos 2023-01-03 13:48:29 -04:00 committed by RichΛrd
parent 84838f4ef8
commit 3ab9bb046b
2 changed files with 15 additions and 8 deletions

View File

@ -82,7 +82,7 @@ export default function App() {
let msg = new WakuMessage(); let msg = new WakuMessage();
msg.contentTopic = 'ABC'; msg.contentTopic = 'ABC';
msg.payload = new Uint8Array([1, 2, 3, 4, 5]); msg.payload = new Uint8Array([1, 2, 3, 4, 5]);
msg.timestamp = Date.now(); msg.timestamp = new Date();
msg.version = 0; msg.version = 0;
let messageID = await relayPublish(msg); let messageID = await relayPublish(msg);
@ -92,7 +92,7 @@ export default function App() {
// TO RETRIEVE HISTORIC MESSAGES: // TO RETRIEVE HISTORIC MESSAGES:
console.log('Retrieving messages from store node'); console.log('Retrieving messages from store node');
const query = new StoreQuery(); 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( const queryResult = await storeQuery(
query, query,
'16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm' '16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm'

View File

@ -20,19 +20,20 @@ export function multiply(a: number, b: number): Promise<number> {
return ReactNative.multiply(a, b); return ReactNative.multiply(a, b);
} }
const OneMillion = BigInt(1_000_000);
export class WakuMessage { export class WakuMessage {
payload: Uint8Array = new Uint8Array(); payload: Uint8Array = new Uint8Array();
contentTopic: String | null = ""; contentTopic: String | null = "";
version: Number | null = 0; version: Number | null = 0;
timestamp: Number | null = null; timestamp?: Date = undefined;
toJSON(){ toJSON(){
const b64encoded = encode(String.fromCharCode(...this.payload)); const b64encoded = encode(String.fromCharCode(...this.payload));
return { return {
contentTopic: this.contentTopic, contentTopic: this.contentTopic,
version: this.version, version: this.version,
timestamp: this.timestamp, timestamp: this.timestamp ? (BigInt(this.timestamp.valueOf()) * OneMillion).toString(10) : 0,
payload: b64encoded payload: b64encoded
} }
} }
@ -536,11 +537,11 @@ export class ContentFilter {
export class StoreQuery { export class StoreQuery {
pubsubTopic: String | null = null pubsubTopic: String | null = null
contentFilters: Array<ContentFilter> = Array() contentFilters: Array<ContentFilter> = Array()
startTime: Number = 0 startTime?: Date = undefined
endTime: Number = 0 endTime?: Date = undefined
pagingOptions: PagingOptions | null = null pagingOptions: PagingOptions | null = null
constructor(pubsubTopic: String | null = null, contentFilters: Array<ContentFilter> = Array(), startTime: Number = 0, endTime: Number = 0, pagingOptions: PagingOptions | null = null) { constructor(pubsubTopic: String | null = null, contentFilters: Array<ContentFilter> = Array(), startTime: Date | undefined = undefined, endTime: Date | undefined = undefined, pagingOptions: PagingOptions | null = null) {
this.pubsubTopic = pubsubTopic this.pubsubTopic = pubsubTopic
this.contentFilters = contentFilters this.contentFilters = contentFilters
this.startTime = startTime this.startTime = startTime
@ -558,7 +559,13 @@ export class StoreQuery {
*/ */
export function storeQuery(query: StoreQuery, peerID: String = "", timeoutMs: Number = 0): Promise<any> { export function storeQuery(query: StoreQuery, peerID: String = "", timeoutMs: Number = 0): Promise<any> {
return new Promise<string>(async (resolve, reject) => { return new Promise<string>(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)); let response = JSON.parse(await ReactNative.storeQuery(queryJSON, peerID, timeoutMs));
if(response.error){ if(response.error){