fix: De-duplicate message search results (#133)

- De-duplicate messages in parse utils
- Add padding around message summary row checkmark
pull/134/head
J M Rossy 1 month ago committed by GitHub
parent ed7eac97e9
commit 67b28bbbd7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      src/features/messages/MessageTable.tsx
  2. 34
      src/features/messages/queries/parse.ts

@ -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}

@ -26,12 +26,7 @@ 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(
@ -39,12 +34,23 @@ export function parseMessageQueryResult(
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)
return deduplicateMessageList(
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);
.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<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());
}

Loading…
Cancel
Save