From ca66e8b13266b6885d6bb63da4b7c9114ee4254a Mon Sep 17 00:00:00 2001 From: Felicio Mununga Date: Thu, 9 Jun 2022 20:32:36 +0200 Subject: [PATCH] use clock --- packages/status-js/src/client.ts | 5 ----- packages/status-js/src/client/community/community.ts | 9 +++++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/status-js/src/client.ts b/packages/status-js/src/client.ts index 178778a0..e39abb6d 100644 --- a/packages/status-js/src/client.ts +++ b/packages/status-js/src/client.ts @@ -1,11 +1,6 @@ -// todo: handle updates together with fetching history (chat messages) -// todo: handle diff waku messages on diff topics // todo?: already received (by messageId or event) -// todo: use clock for sorting // todo: use Map // todo: write class for channels -// todo: fetch all history until Map; remove end param -// todo: handle // todo: tests diff --git a/packages/status-js/src/client/community/community.ts b/packages/status-js/src/client/community/community.ts index e845a006..4524903f 100644 --- a/packages/status-js/src/client/community/community.ts +++ b/packages/status-js/src/client/community/community.ts @@ -202,6 +202,10 @@ export class Community { communityMetadata: CommunityMetadataType ) => { if (this.communityMetadata) { + if (this.communityMetadata.clock > communityMetadata.clock) { + return + } + // Channels const removedChats = difference( Object.keys(this.communityMetadata.chats), @@ -245,10 +249,7 @@ export class Community { break } - if ( - new Date(Number(_message.timestamp)) <= - new Date(Number(chatMessage.timestamp)) - ) { + if (_message.clock <= chatMessage.clock) { break }