Skip to content

Commit

Permalink
fix: De-duplicate message search results (#133)
Browse files Browse the repository at this point in the history
- De-duplicate messages in parse utils
- Add padding around message summary row checkmark
  • Loading branch information
jmrossy authored Oct 28, 2024
1 parent ed7eac9 commit 67b28bb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/features/messages/MessageTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ export function MessageSummaryRow({ message, mp }: { message: MessageStub; mp: M
>
{shortenAddress(origin.hash)}
</LinkCell>
<LinkCell id={msgId} base64={base64} aClasses={styles.valueTruncated} tdClasses="pr-4">
<LinkCell id={msgId} base64={base64} aClasses={styles.valueTruncated} tdClasses="pr-5">
{getHumanReadableTimeString(origin.timestamp)}
</LinkCell>
{statusIcon && (
<LinkCell id={msgId} base64={base64} tdClasses="w-0">
<span className="absolute right-4 top-1/2 -translate-y-1/2 transform">
<span className="absolute right-3 top-1/2 -translate-y-1/2 transform">
<Image
src={statusIcon}
width={18}
Expand Down
36 changes: 25 additions & 11 deletions src/features/messages/queries/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,31 @@ export function parseMessageStubResult(
scrapedChains: DomainsEntry[],
data: MessagesStubQueryResult | undefined,
): MessageStub[] {
if (!data || !Object.keys(data).length) return [];
return Object.values(data)
.flat()
.map((m) => 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(
multiProvider: MultiProvider,
scrapedChains: DomainsEntry[],
data: MessagesQueryResult | undefined,
): Message[] {
return queryResult(multiProvider, scrapedChains, data, parseMessage);
}

function queryResult<D, M extends MessageStub>(
multiProvider: MultiProvider,
scrapedChains: DomainsEntry[],
data: Record<string, D[]> | 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(
Expand Down Expand Up @@ -171,3 +177,11 @@ function getMessageStatus(m: MessageEntry | MessageStubEntry) {
return MessageStatus.Pending;
}
}

function deduplicateMessageList<M extends MessageStub>(messages: Array<M>): Array<M> {
const map = new Map();
for (const item of messages) {
map.set(item.id, item);
}
return Array.from(map.values());
}

0 comments on commit 67b28bb

Please sign in to comment.