fix: use date for timestamps

This commit is contained in:
Richard Ramos 2023-01-03 13:48:29 -04:00
parent 84838f4ef8
commit 31ef19c3da
No known key found for this signature in database
GPG Key ID: 1CE87DB518195760
2 changed files with 15 additions and 8 deletions

View File

@ -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'

View File

@ -20,19 +20,20 @@ export function multiply(a: number, b: number): Promise<number> {
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<ContentFilter> = Array()
startTime: Number = 0
endTime: Number = 0
startTime?: Date = undefined
endTime?: Date = undefined
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.contentFilters = contentFilters
this.startTime = startTime
@ -558,7 +559,13 @@ export class StoreQuery {
*/
export function storeQuery(query: StoreQuery, peerID: String = "", timeoutMs: Number = 0): Promise<any> {
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));
if(response.error){