From 67b28bbbd7adcc0bb9e58124c8dd3abcba972ca3 Mon Sep 17 00:00:00 2001 From: J M Rossy Date: Mon, 28 Oct 2024 14:07:29 -0400 Subject: [PATCH] fix: De-duplicate message search results (#133) - De-duplicate messages in parse utils - Add padding around message summary row checkmark --- src/features/messages/MessageTable.tsx | 4 +-- src/features/messages/queries/parse.ts | 36 ++++++++++++++++++-------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/features/messages/MessageTable.tsx b/src/features/messages/MessageTable.tsx index 3712471..141202d 100644 --- a/src/features/messages/MessageTable.tsx +++ b/src/features/messages/MessageTable.tsx @@ -91,12 +91,12 @@ export function MessageSummaryRow({ message, mp }: { message: MessageStub; mp: M > {shortenAddress(origin.hash)} - + {getHumanReadableTimeString(origin.timestamp)} {statusIcon && ( - + parseMessageStub(multiProvider, scrapedChains, m)) - .filter((m): m is MessageStub => !!m) - .sort((a, b) => b.origin.timestamp - a.origin.timestamp); + return queryResult(multiProvider, scrapedChains, data, parseMessageStub); } export function parseMessageQueryResult( @@ -39,12 +34,23 @@ export function parseMessageQueryResult( scrapedChains: DomainsEntry[], data: MessagesQueryResult | undefined, ): Message[] { + return queryResult(multiProvider, scrapedChains, data, parseMessage); +} + +function queryResult( + multiProvider: MultiProvider, + scrapedChains: DomainsEntry[], + data: Record | undefined, + parseFn: (multiProvider: MultiProvider, scrapedChains: DomainsEntry[], data: D) => M | null, +) { if (!data || !Object.keys(data).length) return []; - return Object.values(data) - .flat() - .map((m) => parseMessage(multiProvider, scrapedChains, m)) - .filter((m): m is Message => !!m) - .sort((a, b) => b.origin.timestamp - a.origin.timestamp); + return deduplicateMessageList( + Object.values(data) + .flat() + .map((d) => parseFn(multiProvider, scrapedChains, d)) + .filter((m): m is M => !!m) + .sort((a, b) => b.origin.timestamp - a.origin.timestamp), + ); } function parseMessageStub( @@ -171,3 +177,11 @@ function getMessageStatus(m: MessageEntry | MessageStubEntry) { return MessageStatus.Pending; } } + +function deduplicateMessageList(messages: Array): Array { + const map = new Map(); + for (const item of messages) { + map.set(item.id, item); + } + return Array.from(map.values()); +}