From 759cd73af4f7f83cd4c5caba923c718b415904c0 Mon Sep 17 00:00:00 2001 From: codytseng Date: Wed, 12 Mar 2025 22:53:25 +0800 Subject: [PATCH] feat: display reaction emojis in notifications --- src/components/Image/index.tsx | 4 ++- .../NotificationItem/ReactionNotification.tsx | 34 ++++++++++++++----- src/lib/tag.ts | 5 +++ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/components/Image/index.tsx b/src/components/Image/index.tsx index 26124d3..fc71c04 100644 --- a/src/components/Image/index.tsx +++ b/src/components/Image/index.tsx @@ -11,6 +11,7 @@ export default function Image({ className = '', classNames = {}, hideIfError = false, + errorPlaceholder = , ...props }: HTMLAttributes & { classNames?: { @@ -20,6 +21,7 @@ export default function Image({ image: TImageInfo alt?: string hideIfError?: boolean + errorPlaceholder?: React.ReactNode }) { const [isLoading, setIsLoading] = useState(true) const [displayBlurHash, setDisplayBlurHash] = useState(true) @@ -77,7 +79,7 @@ export default function Image({ classNames.errorPlaceholder )} > - + {errorPlaceholder} )} {displayBlurHash && blurDataUrl && !hasError && ( diff --git a/src/components/NotificationList/NotificationItem/ReactionNotification.tsx b/src/components/NotificationList/NotificationItem/ReactionNotification.tsx index c9c4cac..5da8919 100644 --- a/src/components/NotificationList/NotificationItem/ReactionNotification.tsx +++ b/src/components/NotificationList/NotificationItem/ReactionNotification.tsx @@ -1,7 +1,8 @@ +import Image from '@/components/Image' import { PICTURE_EVENT_KIND } from '@/constants' import { useFetchEvent } from '@/hooks' import { toNote } from '@/lib/link' -import { tagNameEquals } from '@/lib/tag' +import { extractEmojiFromEventTags, tagNameEquals } from '@/lib/tag' import { cn } from '@/lib/utils' import { useSecondaryPage } from '@/PageManager' import { useNostr } from '@/providers/NostrProvider' @@ -29,6 +30,29 @@ export function ReactionNotification({ return eTag?.[1] }, [notification, pubkey]) const { event } = useFetchEvent(eventId) + const reaction = useMemo(() => { + if (!notification.content || notification.content === '+') { + return + } + + const emojiName = /^:([^:]+):$/.exec(notification.content)?.[1] + if (emojiName) { + const emojiUrl = extractEmojiFromEventTags(emojiName, notification.tags) + if (emojiUrl) { + return ( + {emojiName}} + /> + ) + } + } + return notification.content + }, [notification]) + if (!event || !eventId || ![kinds.ShortTextNote, PICTURE_EVENT_KIND].includes(event.kind)) { return null } @@ -40,13 +64,7 @@ export function ReactionNotification({ >
-
- {!notification.content || notification.content === '+' ? ( - - ) : ( - notification.content - )} -
+
{reaction}
tag[0] === 'emoji' && tag[1] === emojiName) + return emojiTag?.[2] +} + export function isSameTag(tag1: string[], tag2: string[]) { if (tag1.length !== tag2.length) return false for (let i = 0; i < tag1.length; i++) {