diff --git a/eth-pm/package.json b/eth-pm/package.json index c1ccc69..c8abefb 100644 --- a/eth-pm/package.json +++ b/eth-pm/package.json @@ -8,9 +8,9 @@ "@ethersproject/providers": "5.7.0", "@material-ui/core": "^4.12.3", "@material-ui/icons": "^4.11.2", - "ethers": "5.7.0", + "ethers": "5.7.1", "fontsource-roboto": "^4.0.0", - "js-waku": "0.27.0", + "js-waku": "0.28.0", "protobufjs": "^7.1.0", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/eth-pm/pnpm-lock.yaml b/eth-pm/pnpm-lock.yaml index e432093..5d47765 100644 --- a/eth-pm/pnpm-lock.yaml +++ b/eth-pm/pnpm-lock.yaml @@ -12,9 +12,9 @@ specifiers: '@types/react-dom': ^18.0.6 cspell: ^6.0.0 eslint: ^8.9.0 - ethers: 5.7.0 + ethers: 5.7.1 fontsource-roboto: ^4.0.0 - js-waku: 0.27.0 + js-waku: 0.28.0 npm-run-all: ^4.1.5 prettier: ^2.5.1 protobufjs: ^7.1.0 @@ -29,9 +29,9 @@ dependencies: '@ethersproject/providers': 5.7.0 '@material-ui/core': 4.12.4_zxljzmqdrxwnuenbkrz77w74uy '@material-ui/icons': 4.11.3_upnjamd3tbaukgopcqqdlc7jbm - ethers: 5.7.0 + ethers: 5.7.1 fontsource-roboto: 4.0.0 - js-waku: 0.27.0_undici@5.10.0 + js-waku: 0.28.0_undici@5.10.0 protobufjs: 7.1.0 react: 18.2.0 react-dom: 18.2.0_react@18.2.0 @@ -2099,10 +2099,10 @@ packages: '@ethersproject/bignumber': 5.7.0 '@ethersproject/bytes': 5.7.0 '@ethersproject/logger': 5.7.0 - '@ethersproject/networks': 5.7.0 + '@ethersproject/networks': 5.7.1 '@ethersproject/properties': 5.7.0 '@ethersproject/transactions': 5.7.0 - '@ethersproject/web': 5.7.0 + '@ethersproject/web': 5.7.1 dev: false /@ethersproject/abstract-signer/5.7.0: @@ -2239,6 +2239,12 @@ packages: '@ethersproject/logger': 5.7.0 dev: false + /@ethersproject/networks/5.7.1: + resolution: {integrity: sha512-n/MufjFYv3yFcUyfhnXotyDlNdFb7onmkSy8aQERi2PjNcnWQ66xXxa3XlS8nCcA8aJKJjIIMNJTC7tu80GwpQ==} + dependencies: + '@ethersproject/logger': 5.7.0 + dev: false + /@ethersproject/pbkdf2/5.7.0: resolution: {integrity: sha512-oR/dBRZR6GTyaofd86DehG72hY6NpAjhabkhxgr3X2FpJtJuodEl2auADWBZfhDHgVCbu3/H/Ocq2uC6dpNjjw==} dependencies: @@ -2280,6 +2286,34 @@ packages: - utf-8-validate dev: false + /@ethersproject/providers/5.7.1: + resolution: {integrity: sha512-vZveG/DLyo+wk4Ga1yx6jSEHrLPgmTt+dFv0dv8URpVCRf0jVhalps1jq/emN/oXnMRsC7cQgAF32DcXLL7BPQ==} + dependencies: + '@ethersproject/abstract-provider': 5.7.0 + '@ethersproject/abstract-signer': 5.7.0 + '@ethersproject/address': 5.7.0 + '@ethersproject/base64': 5.7.0 + '@ethersproject/basex': 5.7.0 + '@ethersproject/bignumber': 5.7.0 + '@ethersproject/bytes': 5.7.0 + '@ethersproject/constants': 5.7.0 + '@ethersproject/hash': 5.7.0 + '@ethersproject/logger': 5.7.0 + '@ethersproject/networks': 5.7.1 + '@ethersproject/properties': 5.7.0 + '@ethersproject/random': 5.7.0 + '@ethersproject/rlp': 5.7.0 + '@ethersproject/sha2': 5.7.0 + '@ethersproject/strings': 5.7.0 + '@ethersproject/transactions': 5.7.0 + '@ethersproject/web': 5.7.1 + bech32: 1.1.4 + ws: 7.4.6 + transitivePeerDependencies: + - bufferutil + - utf-8-validate + dev: false + /@ethersproject/random/5.7.0: resolution: {integrity: sha512-19WjScqRA8IIeWclFme75VMXSBvi4e6InrUNuaR4s5pTF2qNhcGdCUwdxUVGtDDqC00sDLCO93jPQoDUH4HVmQ==} dependencies: @@ -2388,6 +2422,16 @@ packages: '@ethersproject/strings': 5.7.0 dev: false + /@ethersproject/web/5.7.1: + resolution: {integrity: sha512-Gueu8lSvyjBWL4cYsWsjh6MtMwM0+H4HvqFPZfB6dV8ctbP9zFAO73VG1cMWae0FLPCtz0peKPpZY8/ugJJX2w==} + dependencies: + '@ethersproject/base64': 5.7.0 + '@ethersproject/bytes': 5.7.0 + '@ethersproject/logger': 5.7.0 + '@ethersproject/properties': 5.7.0 + '@ethersproject/strings': 5.7.0 + dev: false + /@ethersproject/wordlists/5.7.0: resolution: {integrity: sha512-S2TFNJNfHWVHNE6cNDjbVlZ6MgE17MIxMbMg2zv3wn+3XSJGosL1m9ZVv3GXCf/2ymSsQ+hRI5IzoMJTG6aoVA==} dependencies: @@ -6559,8 +6603,8 @@ packages: engines: {node: '>= 0.6'} dev: true - /ethers/5.7.0: - resolution: {integrity: sha512-5Xhzp2ZQRi0Em+0OkOcRHxPzCfoBfgtOQA+RUylSkuHbhTEaQklnYi2hsWbRgs3ztJsXVXd9VKBcO1ScWL8YfA==} + /ethers/5.7.1: + resolution: {integrity: sha512-5krze4dRLITX7FpU8J4WscXqADiKmyeNlylmmDLbS95DaZpBhDe2YSwRQwKXWNyXcox7a3gBgm/MkGXV1O1S/Q==} dependencies: '@ethersproject/abi': 5.7.0 '@ethersproject/abstract-provider': 5.7.0 @@ -6577,10 +6621,10 @@ packages: '@ethersproject/json-wallets': 5.7.0 '@ethersproject/keccak256': 5.7.0 '@ethersproject/logger': 5.7.0 - '@ethersproject/networks': 5.7.0 + '@ethersproject/networks': 5.7.1 '@ethersproject/pbkdf2': 5.7.0 '@ethersproject/properties': 5.7.0 - '@ethersproject/providers': 5.7.0 + '@ethersproject/providers': 5.7.1 '@ethersproject/random': 5.7.0 '@ethersproject/rlp': 5.7.0 '@ethersproject/sha2': 5.7.0 @@ -6590,7 +6634,7 @@ packages: '@ethersproject/transactions': 5.7.0 '@ethersproject/units': 5.7.0 '@ethersproject/wallet': 5.7.0 - '@ethersproject/web': 5.7.0 + '@ethersproject/web': 5.7.1 '@ethersproject/wordlists': 5.7.0 transitivePeerDependencies: - bufferutil @@ -8443,8 +8487,8 @@ packages: /js-tokens/4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} - /js-waku/0.27.0_undici@5.10.0: - resolution: {integrity: sha512-uIh1h2Gu+aEyrGb4qmyk2Sc91in3fMfOil0kdtrps9HnA7ESbC5c6d148LeJaxqH5rfOkrfXXIhw1zwA3hlauw==} + /js-waku/0.28.0_undici@5.10.0: + resolution: {integrity: sha512-MEIFugvio2IaQMQT+g+bn24BvlJ5S4PdSKD0AGVZlR7q1BhECwlpRoytyz0A/hC1+EJWhrZB8cpIAmxwtYWTBw==} engines: {node: '>=16'} dependencies: '@chainsafe/libp2p-gossipsub': 4.1.1_undici@5.10.0 diff --git a/light-js/index.html b/light-js/index.html index 56c30db..a13a456 100644 --- a/light-js/index.html +++ b/light-js/index.html @@ -18,16 +18,18 @@

Remote Peer Id

+
- - + +
+ - +
@@ -35,13 +37,13 @@ import { utils, WakuMessage - } from 'https://unpkg.com/js-waku@0.27.0/bundle/index.js'; + } from 'https://unpkg.com/js-waku@0.28.0/bundle/index.js'; import { createLightNode - } from 'https://unpkg.com/js-waku@0.27.0/bundle/lib/create_waku.js' + } from 'https://unpkg.com/js-waku@0.28.0/bundle/lib/create_waku.js' import { waitForRemotePeer - } from 'https://unpkg.com/js-waku@0.27.0/bundle/lib/wait_for_remote_peer.js' + } from 'https://unpkg.com/js-waku@0.28.0/bundle/lib/wait_for_remote_peer.js' const peerIdDiv = document.getElementById('peer-id'); const remotePeerIdDiv = document.getElementById('remote-peer-id'); diff --git a/relay-angular-chat/package.json b/relay-angular-chat/package.json index 65173b5..c6fe5aa 100644 --- a/relay-angular-chat/package.json +++ b/relay-angular-chat/package.json @@ -21,7 +21,7 @@ "@angular/platform-browser": "~14.2.0", "@angular/platform-browser-dynamic": "~14.2.0", "@angular/router": "~14.2.0", - "js-waku": "0.27.0", + "js-waku": "0.28.0", "protobufjs": "^7.1.0", "rxjs": "~7.5.0", "tslib": "^2.3.0", diff --git a/relay-angular-chat/pnpm-lock.yaml b/relay-angular-chat/pnpm-lock.yaml index d2da80a..1d4eac8 100644 --- a/relay-angular-chat/pnpm-lock.yaml +++ b/relay-angular-chat/pnpm-lock.yaml @@ -16,7 +16,7 @@ specifiers: '@types/node': ^17.0.21 is-ci-cli: ^2.2.0 jasmine-core: ~4.3.0 - js-waku: 0.27.0 + js-waku: 0.28.0 karma: ~6.4.0 karma-chrome-launcher: ~3.1.0 karma-coverage: ~2.2.0 @@ -37,7 +37,7 @@ dependencies: '@angular/platform-browser': 14.2.0_afytwol7hs4qio34buyx2grhfa '@angular/platform-browser-dynamic': 14.2.0_owch6soaoexeadly32xw5vendq '@angular/router': 14.2.0_6lk4yxyxfaqzosenawf2bqx6vy - js-waku: 0.27.0 + js-waku: 0.28.0 protobufjs: 7.1.0 rxjs: 7.5.6 tslib: 2.4.0 @@ -5440,8 +5440,8 @@ packages: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} dev: true - /js-waku/0.27.0: - resolution: {integrity: sha512-uIh1h2Gu+aEyrGb4qmyk2Sc91in3fMfOil0kdtrps9HnA7ESbC5c6d148LeJaxqH5rfOkrfXXIhw1zwA3hlauw==} + /js-waku/0.28.0: + resolution: {integrity: sha512-MEIFugvio2IaQMQT+g+bn24BvlJ5S4PdSKD0AGVZlR7q1BhECwlpRoytyz0A/hC1+EJWhrZB8cpIAmxwtYWTBw==} engines: {node: '>=16'} dependencies: '@chainsafe/libp2p-gossipsub': 4.1.1 diff --git a/relay-js/index.html b/relay-js/index.html index cf7e55e..e55d92d 100644 --- a/relay-js/index.html +++ b/relay-js/index.html @@ -12,9 +12,9 @@

Waku Node Status

+ - +

Messages

@@ -28,13 +28,13 @@ import { WakuMessage - } from 'https://unpkg.com/js-waku@0.27.0/bundle/index.js'; + } from 'https://unpkg.com/js-waku@0.28.0/bundle/index.js'; import { - createWaku - } from 'https://unpkg.com/js-waku@0.27.0/bundle/lib/create_waku.js' + createPrivacyNode + } from 'https://unpkg.com/js-waku@0.28.0/bundle/lib/create_waku.js' import { waitForRemotePeer - } from 'https://unpkg.com/js-waku@0.27.0/bundle/lib/wait_for_remote_peer.js' + } from 'https://unpkg.com/js-waku@0.28.0/bundle/lib/wait_for_remote_peer.js' const statusDiv = document.getElementById('status'); const messagesDiv = document.getElementById('messages'); @@ -60,7 +60,7 @@ // We are currently working on migrating this method to DNS Discovery. // // https://js-waku.wakuconnect.dev/classes/waku.Waku.html#create - const waku = await createWaku({defaultBootstrap: true}); + const waku = await createPrivacyNode({defaultBootstrap: true}); await waku.start(); // Had a hook to process all incoming messages on a specified content topic. diff --git a/relay-reactjs-chat/package.json b/relay-reactjs-chat/package.json index 238c3e2..ad799de 100644 --- a/relay-reactjs-chat/package.json +++ b/relay-reactjs-chat/package.json @@ -7,7 +7,7 @@ "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.3.0", "@testing-library/user-event": "^13.5.0", - "js-waku": "0.27.0", + "js-waku": "0.28.0", "protobufjs": "^7.0.0", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/relay-reactjs-chat/pnpm-lock.yaml b/relay-reactjs-chat/pnpm-lock.yaml index 7909234..d159df5 100644 --- a/relay-reactjs-chat/pnpm-lock.yaml +++ b/relay-reactjs-chat/pnpm-lock.yaml @@ -6,7 +6,7 @@ specifiers: '@testing-library/react': ^13.3.0 '@testing-library/user-event': ^13.5.0 eslint: ^8.22.0 - js-waku: 0.27.0 + js-waku: 0.28.0 protobufjs: ^7.0.0 react: ^18.2.0 react-dom: ^18.2.0 @@ -17,7 +17,7 @@ dependencies: '@testing-library/jest-dom': 5.16.5 '@testing-library/react': 13.3.0_biqbaboplfbrettd7655fr4n2y '@testing-library/user-event': 13.5.0_wl4iynrlixafokvgqnhzlvigei - js-waku: 0.27.0_undici@5.10.0 + js-waku: 0.28.0_undici@5.10.0 protobufjs: 7.0.0 react: 18.2.0 react-dom: 18.2.0_react@18.2.0 @@ -7001,8 +7001,8 @@ packages: /js-tokens/4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} - /js-waku/0.27.0_undici@5.10.0: - resolution: {integrity: sha512-uIh1h2Gu+aEyrGb4qmyk2Sc91in3fMfOil0kdtrps9HnA7ESbC5c6d148LeJaxqH5rfOkrfXXIhw1zwA3hlauw==} + /js-waku/0.28.0_undici@5.10.0: + resolution: {integrity: sha512-MEIFugvio2IaQMQT+g+bn24BvlJ5S4PdSKD0AGVZlR7q1BhECwlpRoytyz0A/hC1+EJWhrZB8cpIAmxwtYWTBw==} engines: {node: '>=16'} dependencies: '@chainsafe/libp2p-gossipsub': 4.1.1_undici@5.10.0 diff --git a/relay-reactjs-chat/src/App.js b/relay-reactjs-chat/src/App.js index 4a91f0e..f798af3 100644 --- a/relay-reactjs-chat/src/App.js +++ b/relay-reactjs-chat/src/App.js @@ -1,7 +1,7 @@ import { WakuMessage } from "js-waku"; import * as React from "react"; import protobuf from "protobufjs"; -import { createWaku } from "js-waku/lib/create_waku"; +import { createPrivacyNode } from "js-waku/lib/create_waku"; import { waitForRemotePeer } from "js-waku/lib/wait_for_remote_peer"; const ContentTopic = `/relay-reactjs-chat/1/chat/proto`; @@ -23,7 +23,7 @@ function App() { setWakuStatus("Starting"); (async () => { - const waku = await createWaku({ defaultBootstrap: true }); + const waku = await createPrivacyNode({ defaultBootstrap: true }); setWaku(waku); await waku.start(); diff --git a/store-js/index.html b/store-js/index.html index 169bded..28467ee 100644 --- a/store-js/index.html +++ b/store-js/index.html @@ -2,39 +2,38 @@ - - - JS-Waku store script tag example + + + JS-Waku store script tag example -

Timestamp of latest message seen in store

+

Timestamp of the latest message seen in store

diff --git a/store-reactjs-chat/package.json b/store-reactjs-chat/package.json index 4396479..21ed09d 100644 --- a/store-reactjs-chat/package.json +++ b/store-reactjs-chat/package.json @@ -7,7 +7,7 @@ "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^13.2.0", "@testing-library/user-event": "^14.1.1", - "js-waku": "0.27.0", + "js-waku": "0.28.0", "protobufjs": "^7.1.0", "react": "^18.1.0", "react-dom": "^18.1.0", diff --git a/store-reactjs-chat/pnpm-lock.yaml b/store-reactjs-chat/pnpm-lock.yaml index ba07e88..86e8837 100644 --- a/store-reactjs-chat/pnpm-lock.yaml +++ b/store-reactjs-chat/pnpm-lock.yaml @@ -5,7 +5,7 @@ specifiers: '@testing-library/jest-dom': ^5.16.4 '@testing-library/react': ^13.2.0 '@testing-library/user-event': ^14.1.1 - js-waku: 0.27.0 + js-waku: 0.28.0 protobufjs: ^7.1.0 react: ^18.1.0 react-dom: ^18.1.0 @@ -17,7 +17,7 @@ dependencies: '@testing-library/jest-dom': 5.16.5 '@testing-library/react': 13.3.0_biqbaboplfbrettd7655fr4n2y '@testing-library/user-event': 14.4.2_znfriv3ismgf3ybh2woqwlpfea - js-waku: 0.27.0 + js-waku: 0.28.0 protobufjs: 7.1.0 react: 18.2.0 react-dom: 18.2.0_react@18.2.0 @@ -7375,8 +7375,8 @@ packages: /js-tokens/4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} - /js-waku/0.27.0: - resolution: {integrity: sha512-uIh1h2Gu+aEyrGb4qmyk2Sc91in3fMfOil0kdtrps9HnA7ESbC5c6d148LeJaxqH5rfOkrfXXIhw1zwA3hlauw==} + /js-waku/0.28.0: + resolution: {integrity: sha512-MEIFugvio2IaQMQT+g+bn24BvlJ5S4PdSKD0AGVZlR7q1BhECwlpRoytyz0A/hC1+EJWhrZB8cpIAmxwtYWTBw==} engines: {node: '>=16'} dependencies: '@chainsafe/libp2p-gossipsub': 4.1.1 diff --git a/store-reactjs-chat/src/App.js b/store-reactjs-chat/src/App.js index b96c1bd..7004e87 100644 --- a/store-reactjs-chat/src/App.js +++ b/store-reactjs-chat/src/App.js @@ -55,32 +55,40 @@ function App() { React.useEffect(() => { if (wakuStatus !== "Connected") return; - const processMessages = (retrievedMessages) => { - const messages = retrievedMessages.map(decodeMessage).filter(Boolean); + (async () => { + const startTime = new Date(); + // 7 days/week, 24 hours/day, 60min/hour, 60secs/min, 100ms/sec + startTime.setTime(startTime.getTime() - 7 * 24 * 60 * 60 * 1000); - setMessages((currentMessages) => { - return currentMessages.concat(messages.reverse()); - }); - }; + // TODO: Remove this timeout once https://github.com/status-im/js-waku/issues/913 is done + await new Promise((resolve) => setTimeout(resolve, 200)); - const startTime = new Date(); - // 7 days/week, 24 hours/day, 60min/hour, 60secs/min, 100ms/sec - startTime.setTime(startTime.getTime() - 7 * 24 * 60 * 60 * 1000); - - // TODO: Remove this timeout once https://github.com/status-im/js-waku/issues/913 is done - setTimeout( - () => - waku.store - .queryHistory([ContentTopic], { - callback: processMessages, + try { + for await (const messagesPromises of waku.store.queryGenerator( + [ContentTopic], + { timeFilter: { startTime, endTime: new Date() }, - }) - .catch((e) => { - console.log("Failed to retrieve messages", e); - setWakuStatus("Error Encountered"); - }), - 200 - ); + pageDirection: "forward", + } + )) { + const messages = await Promise.all( + messagesPromises + .map(async (p) => { + const msg = await p; + return decodeMessage(msg); + }) + .filter(Boolean) + ); + + setMessages((currentMessages) => { + return currentMessages.concat(messages.reverse()); + }); + } + } catch (e) { + console.log("Failed to retrieve messages", e); + setWakuStatus("Error Encountered"); + } + })(); }, [waku, wakuStatus]); return ( diff --git a/web-chat/package.json b/web-chat/package.json index 2cabda2..e7bd707 100644 --- a/web-chat/package.json +++ b/web-chat/package.json @@ -6,7 +6,7 @@ "dependencies": { "@livechat/ui-kit": "^0.5.0-20", "@multiformats/multiaddr": "^10.4.0", - "js-waku": "0.27.0", + "js-waku": "0.28.0", "process": "^0.11.10", "protons-runtime": "^3.1.0", "react": "^17.0.2", diff --git a/web-chat/pnpm-lock.yaml b/web-chat/pnpm-lock.yaml index f3df525..6c8daed 100644 --- a/web-chat/pnpm-lock.yaml +++ b/web-chat/pnpm-lock.yaml @@ -9,7 +9,7 @@ specifiers: '@types/react-dom': ^17.0.11 cspell: ^6.0.0 gh-pages: ^4.0.0 - js-waku: 0.27.0 + js-waku: 0.28.0 npm-run-all: ^4.1.5 prettier: ^2.6.2 process: ^0.11.10 @@ -26,7 +26,7 @@ specifiers: dependencies: '@livechat/ui-kit': 0.5.0-20_ibvs32p3vr2bbtbo3dwziny444 '@multiformats/multiaddr': 10.4.0 - js-waku: 0.27.0 + js-waku: 0.28.0 process: 0.11.10 protons-runtime: 3.1.0_uint8arraylist@2.3.2 react: 17.0.2 @@ -8382,8 +8382,8 @@ packages: /js-tokens/4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} - /js-waku/0.27.0: - resolution: {integrity: sha512-uIh1h2Gu+aEyrGb4qmyk2Sc91in3fMfOil0kdtrps9HnA7ESbC5c6d148LeJaxqH5rfOkrfXXIhw1zwA3hlauw==} + /js-waku/0.28.0: + resolution: {integrity: sha512-MEIFugvio2IaQMQT+g+bn24BvlJ5S4PdSKD0AGVZlR7q1BhECwlpRoytyz0A/hC1+EJWhrZB8cpIAmxwtYWTBw==} engines: {node: '>=16'} dependencies: '@chainsafe/libp2p-gossipsub': 4.1.1 diff --git a/web-chat/src/App.tsx b/web-chat/src/App.tsx index 1bbb34a..cc545e3 100644 --- a/web-chat/src/App.tsx +++ b/web-chat/src/App.tsx @@ -51,19 +51,7 @@ export const ChatContentTopic = "/toy-chat/2/huilong/proto"; async function retrieveStoreMessages( waku: WakuLight, setArchivedMessages: (value: Message[]) => void -): Promise { - const callback = (wakuMessages: WakuMessage[]): void => { - const messages: Message[] = []; - wakuMessages - .map((wakuMsg) => Message.fromWakuMessage(wakuMsg)) - .forEach((message) => { - if (message) { - messages.push(message); - } - }); - setArchivedMessages(messages); - }; - +): Promise { const startTime = new Date(); // Only retrieve a week of history startTime.setTime(Date.now() - 1000 * 60 * 60 * 24 * 7); @@ -71,20 +59,32 @@ async function retrieveStoreMessages( const endTime = new Date(); try { - const res = await waku.store.queryHistory([ChatContentTopic], { - pageSize: 5, - pageDirection: PageDirection.FORWARD, - timeFilter: { - startTime, - endTime, - }, - callback, - }); + for await (const messagesPromises of waku.store.queryGenerator( + [ChatContentTopic], + { + pageSize: 5, + pageDirection: PageDirection.FORWARD, + timeFilter: { + startTime, + endTime, + }, + } + )) { + const messages: Message[] = []; + const wakuMessages = await Promise.all(messagesPromises); - return res.length; + wakuMessages + .filter(isWakuMessageDefined) + .map((wakuMsg) => Message.fromWakuMessage(wakuMsg)) + .forEach((message) => { + if (message) { + messages.push(message); + } + }); + setArchivedMessages(messages); + } } catch (e) { console.log("Failed to retrieve messages", e); - return 0; } } @@ -228,3 +228,9 @@ function selectFleetEnv() { function reduceMessages(state: Message[], newMessages: Message[]) { return state.concat(newMessages); } + +const isWakuMessageDefined = ( + msg: WakuMessage | undefined +): msg is WakuMessage => { + return !!msg; +};