diff --git a/src/components/NotificationList/index.tsx b/src/components/NotificationList/index.tsx index 9aa53352..bd03e30a 100644 --- a/src/components/NotificationList/index.tsx +++ b/src/components/NotificationList/index.tsx @@ -13,6 +13,8 @@ import { useTranslation } from 'react-i18next' import PullToRefresh from 'react-simple-pull-to-refresh' import { FormattedTimestamp } from '../FormattedTimestamp' import UserAvatar from '../UserAvatar' +import { embedded, embeddedNostrNpubRenderer, embeddedNostrProfileRenderer } from '../Embedded' +import { extractEmbeddedNotesFromContent, extractImagesFromContent } from '@/lib/event' const LIMIT = 100 @@ -268,7 +270,17 @@ function CommentNotification({ notification }: { notification: Event }) { } function ContentPreview({ event }: { event?: Event }) { + const { t } = useTranslation() + const content = useMemo(() => { + if (!event) return null + const { contentWithoutEmbeddedNotes } = extractEmbeddedNotesFromContent(event.content) + const { contentWithoutImages, images } = extractImagesFromContent(contentWithoutEmbeddedNotes) + return embedded(contentWithoutImages + (images?.length ? `[${t('image')}]` : ''), [ + embeddedNostrProfileRenderer, + embeddedNostrNpubRenderer + ]) + }, [event]) if (!event) return null - return
{event.content}
+ return
{content}
} diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 3f5418a4..8fb39a2a 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -104,6 +104,7 @@ export default { 'A special note for picture-first clients like Olas': 'A special note for picture-first clients like Olas', 'Picture note requires images': 'Picture note requires images', - Relays: 'Relays' + Relays: 'Relays', + image: 'image' } } diff --git a/src/i18n/zh.ts b/src/i18n/zh.ts index 36d9228d..ab774b69 100644 --- a/src/i18n/zh.ts +++ b/src/i18n/zh.ts @@ -103,6 +103,7 @@ export default { 'A special note for picture-first clients like Olas': '一种可以在图片优先客户端 (如 Olas) 中显示的特殊笔记', 'Picture note requires images': '图片笔记需要有图片', - Relays: '服务器' + Relays: '服务器', + image: '图片' } } diff --git a/src/lib/event.ts b/src/lib/event.ts index c1504d7d..c1fce642 100644 --- a/src/lib/event.ts +++ b/src/lib/event.ts @@ -215,3 +215,17 @@ export function extractImagesFromContent(content: string) { contentWithoutImages = contentWithoutImages.replace(/\n{3,}/g, '\n\n').trim() return { images, contentWithoutImages } } + +export function extractEmbeddedNotesFromContent(content: string) { + let c = content + const embeddedNotes: string[] = [] + const embeddedNoteRegex = /nostr:(note1[a-z0-9]{58}|nevent1[a-z0-9]+|naddr1[a-z0-9]+)/g + ;(c.match(embeddedNoteRegex) || []).forEach((note) => { + c = c.replace(note, '').trim() + embeddedNotes.push(note) + }) + + c = c.replace(/\n{3,}/g, '\n\n').trim() + + return { embeddedNotes, contentWithoutEmbeddedNotes: c } +}