From 0a3be0da587425f0eafc38040ce93f3ce76df144 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 3 May 2024 21:22:53 -0500 Subject: [PATCH] Notifications: fix Favourites and EmojiReacts not being displayed --- src/storages/hydrate.ts | 7 +++++++ src/views/mastodon/notifications.ts | 14 ++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/storages/hydrate.ts b/src/storages/hydrate.ts index 716f251..61d8285 100644 --- a/src/storages/hydrate.ts +++ b/src/storages/hydrate.ts @@ -76,6 +76,13 @@ function assembleEvents( } } + if (event.kind === 7) { + const id = event.tags.find(([name]) => name === 'e')?.[1]; + if (id) { + event.reacted = b.find((e) => matchFilter({ kinds: [1], ids: [id] }, e)); + } + } + if (event.kind === 1) { const id = event.tags.find(([name]) => name === 'q')?.[1]; if (id) { diff --git a/src/views/mastodon/notifications.ts b/src/views/mastodon/notifications.ts index 266b77b..5b618d7 100644 --- a/src/views/mastodon/notifications.ts +++ b/src/views/mastodon/notifications.ts @@ -2,6 +2,7 @@ import { DittoEvent } from '@/interfaces/DittoEvent.ts'; import { nostrDate } from '@/utils.ts'; import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts'; import { renderStatus } from '@/views/mastodon/statuses.ts'; +import { NostrEvent } from '@nostrify/nostrify'; interface RenderNotificationOpts { viewerPubkey: string; @@ -32,7 +33,7 @@ async function renderMention(event: DittoEvent, opts: RenderNotificationOpts) { if (!status) return; return { - id: event.id, + id: notificationId(event), type: 'mention', created_at: nostrDate(event.created_at).toISOString(), account: status.account, @@ -47,7 +48,7 @@ async function renderReblog(event: DittoEvent, opts: RenderNotificationOpts) { const account = event.author ? await renderAccount(event.author) : accountFromPubkey(event.pubkey); return { - id: event.id, + id: notificationId(event), type: 'reblog', created_at: nostrDate(event.created_at).toISOString(), account, @@ -62,7 +63,7 @@ async function renderFavourite(event: DittoEvent, opts: RenderNotificationOpts) const account = event.author ? await renderAccount(event.author) : accountFromPubkey(event.pubkey); return { - id: event.id, + id: notificationId(event), type: 'favourite', created_at: nostrDate(event.created_at).toISOString(), account, @@ -77,7 +78,7 @@ async function renderReaction(event: DittoEvent, opts: RenderNotificationOpts) { const account = event.author ? await renderAccount(event.author) : accountFromPubkey(event.pubkey); return { - id: event.id, + id: notificationId(event), type: 'pleroma:emoji_reaction', emoji: event.content, created_at: nostrDate(event.created_at).toISOString(), @@ -86,4 +87,9 @@ async function renderReaction(event: DittoEvent, opts: RenderNotificationOpts) { }; } +/** This helps notifications be sorted in the correct order. */ +function notificationId({ id, created_at }: NostrEvent): string { + return `${created_at}-${id}`; +} + export { renderNotification };