From 775a288a5c85de3aede091fa8bf7c9ffe4949afe Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Fri, 7 May 2021 10:37:53 +1000 Subject: [PATCH] Log more around usage of waku store --- examples/web-chat/src/App.tsx | 37 ++++++++++++++++++++--------------- src/lib/waku_store/index.ts | 1 + 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/examples/web-chat/src/App.tsx b/examples/web-chat/src/App.tsx index db8b82993d..82aa587e1b 100644 --- a/examples/web-chat/src/App.tsx +++ b/examples/web-chat/src/App.tsx @@ -64,22 +64,27 @@ export default function App() { { peerId, protocols }: { peerId: PeerId; protocols: string[] } ) => { if (protocols.includes(StoreCodec)) { - console.log( - `Retrieving archived messages from ${peerId.toB58String()}` - ); - const response = await waku.store.queryHistory(peerId, [ - ChatContentTopic, - ]); - - if (response) { - const messages = response - .map((wakuMsg) => wakuMsg.payload) - .filter((payload) => !!payload) - .map((payload) => WakuChatMessage.decode(payload as Uint8Array)) - .map((wakuChatMessage) => - ChatMessage.fromWakuChatMessage(wakuChatMessage) - ); - setArchivedMessages(messages); + console.log(`${peerId.toB58String()}: retrieving archived messages}`); + try { + const response = await waku.store.queryHistory(peerId, [ + ChatContentTopic, + ]); + console.log(`${peerId.toB58String()}: messages retrieved:`, response); + if (response) { + const messages = response + .map((wakuMsg) => wakuMsg.payload) + .filter((payload) => !!payload) + .map((payload) => WakuChatMessage.decode(payload as Uint8Array)) + .map((wakuChatMessage) => + ChatMessage.fromWakuChatMessage(wakuChatMessage) + ); + setArchivedMessages(messages); + } + } catch (e) { + console.log( + `${peerId.toB58String()}: error encountered when retrieving archived messages`, + e + ); } } }; diff --git a/src/lib/waku_store/index.ts b/src/lib/waku_store/index.ts index e78b0bb995..1a328cb63c 100644 --- a/src/lib/waku_store/index.ts +++ b/src/lib/waku_store/index.ts @@ -61,6 +61,7 @@ export class WakuStore { if (!response.messages || !response.messages.length) { // No messages left (or stored) + console.log('No messages present in HistoryRPC response'); return messages; }