Log more around usage of waku store

This commit is contained in:
Franck Royer 2021-05-07 10:37:53 +10:00
parent 39a0d38c9e
commit 775a288a5c
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 22 additions and 16 deletions

View File

@ -64,22 +64,27 @@ export default function App() {
{ peerId, protocols }: { peerId: PeerId; protocols: string[] } { peerId, protocols }: { peerId: PeerId; protocols: string[] }
) => { ) => {
if (protocols.includes(StoreCodec)) { if (protocols.includes(StoreCodec)) {
console.log( console.log(`${peerId.toB58String()}: retrieving archived messages}`);
`Retrieving archived messages from ${peerId.toB58String()}` try {
); const response = await waku.store.queryHistory(peerId, [
const response = await waku.store.queryHistory(peerId, [ ChatContentTopic,
ChatContentTopic, ]);
]); console.log(`${peerId.toB58String()}: messages retrieved:`, response);
if (response) {
if (response) { const messages = response
const messages = response .map((wakuMsg) => wakuMsg.payload)
.map((wakuMsg) => wakuMsg.payload) .filter((payload) => !!payload)
.filter((payload) => !!payload) .map((payload) => WakuChatMessage.decode(payload as Uint8Array))
.map((payload) => WakuChatMessage.decode(payload as Uint8Array)) .map((wakuChatMessage) =>
.map((wakuChatMessage) => ChatMessage.fromWakuChatMessage(wakuChatMessage)
ChatMessage.fromWakuChatMessage(wakuChatMessage) );
); setArchivedMessages(messages);
setArchivedMessages(messages); }
} catch (e) {
console.log(
`${peerId.toB58String()}: error encountered when retrieving archived messages`,
e
);
} }
} }
}; };

View File

@ -61,6 +61,7 @@ export class WakuStore {
if (!response.messages || !response.messages.length) { if (!response.messages || !response.messages.length) {
// No messages left (or stored) // No messages left (or stored)
console.log('No messages present in HistoryRPC response');
return messages; return messages;
} }