From 1ae71b90e83db09fd5b0d4fa04daea4055963860 Mon Sep 17 00:00:00 2001 From: Kieran Date: Wed, 2 Aug 2023 19:16:59 +0100 Subject: [PATCH] parse notification zaps --- packages/app/src/Pages/Notifications.css | 1 + packages/app/src/Pages/Notifications.tsx | 44 ++++++++++++++++++++---- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/packages/app/src/Pages/Notifications.css b/packages/app/src/Pages/Notifications.css index d4afbe8ca..11910a567 100644 --- a/packages/app/src/Pages/Notifications.css +++ b/packages/app/src/Pages/Notifications.css @@ -23,6 +23,7 @@ .notification-group .names > div:first-of-type { width: 24px; + text-align: center; } .notification-group .content { diff --git a/packages/app/src/Pages/Notifications.tsx b/packages/app/src/Pages/Notifications.tsx index 66e4dc3c2..5e4efbd24 100644 --- a/packages/app/src/Pages/Notifications.tsx +++ b/packages/app/src/Pages/Notifications.tsx @@ -8,6 +8,7 @@ import { NostrPrefix, TaggedRawEvent, createNostrLink, + parseZap, } from "@snort/system"; import { unwrap } from "@snort/shared"; import { useUserProfile } from "@snort/system-react"; @@ -16,7 +17,7 @@ import { FormattedMessage } from "react-intl"; import useLogin from "Hooks/useLogin"; import { markNotificationsRead } from "Login"; -import { Notifications } from "Cache"; +import { Notifications, UserCache } from "Cache"; import { dedupe, findTag, orderDescending } from "SnortUtils"; import Note from "Element/Note"; import Icon from "Icons/Icon"; @@ -25,6 +26,7 @@ import useModeration from "Hooks/useModeration"; import { System } from "index"; import useEventFeed from "Feed/EventFeed"; import Text from "Element/Text"; +import { formatShort } from "Number"; function notificationContext(ev: TaggedRawEvent) { switch (ev.kind) { @@ -112,7 +114,7 @@ function NotificationGroup({ evs }: { evs: Array }) { const actionName = (n: number, name: string) => { switch (kind) { - case EventKind.Reaction: + case EventKind.Reaction: { return ( }) { }} /> ); - case EventKind.Repost: + } + case EventKind.Repost: { return ( }) { }} /> ); + } + case EventKind.ZapReceipt: { + return ( + + ); + } } return `${kind}'d your post`; }; @@ -146,10 +161,22 @@ function NotificationGroup({ evs }: { evs: Array }) { ); } - const pubkeys = dedupe(evs.map(a => a.pubkey)); + const zaps = useMemo(() => { + return evs.filter(a => a.kind === EventKind.ZapReceipt).map(a => parseZap(a, UserCache)); + }, [evs]); + const pubkeys = dedupe( + evs.map(a => { + if (a.kind === EventKind.ZapReceipt) { + const zap = zaps.find(a => a.id === a.id); + return zap?.sender ?? a.pubkey; + } + return a.pubkey; + }) + ); const firstPubkey = pubkeys[0]; const firstPubkeyProfile = useUserProfile(System, inView ? firstPubkey : ""); const context = notificationContext(evs[0]); + const totalZaps = zaps.reduce((acc, v) => acc + v.amount, 0); return (
@@ -162,7 +189,7 @@ function NotificationGroup({ evs }: { evs: Array }) {
-
+
{kind === EventKind.ZapReceipt && formatShort(totalZaps)}
{actionName(pubkeys.length - 1, getDisplayName(firstPubkeyProfile, firstPubkey))}
{context && }
@@ -172,10 +199,15 @@ function NotificationGroup({ evs }: { evs: Array }) { function NotificationContext({ link }: { link: NostrLink }) { const { data: ev } = useEventFeed(link); + const content = ev?.content ?? ""; return (
- + 120 ? `${content.substring(0, 120)}...` : content} + tags={ev?.tags ?? []} + creator={ev?.pubkey ?? ""} + />
); }