From a3fc334f976c2e7e305c0795b02bf17d8d080d46 Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Fri, 16 Sep 2022 12:21:19 +1000 Subject: [PATCH] chore(store-reactjs-chat): bump js-waku to 0.28.0 --- store-reactjs-chat/package.json | 2 +- store-reactjs-chat/pnpm-lock.yaml | 8 ++--- store-reactjs-chat/src/App.js | 54 ++++++++++++++++++------------- 3 files changed, 36 insertions(+), 28 deletions(-) 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 (