Notifications: fix Favourites and EmojiReacts not being displayed

This commit is contained in:
Alex Gleason 2024-05-03 21:22:53 -05:00
parent e25372313b
commit 0a3be0da58
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 17 additions and 4 deletions

View File

@ -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) { if (event.kind === 1) {
const id = event.tags.find(([name]) => name === 'q')?.[1]; const id = event.tags.find(([name]) => name === 'q')?.[1];
if (id) { if (id) {

View File

@ -2,6 +2,7 @@ import { DittoEvent } from '@/interfaces/DittoEvent.ts';
import { nostrDate } from '@/utils.ts'; import { nostrDate } from '@/utils.ts';
import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts'; import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts';
import { renderStatus } from '@/views/mastodon/statuses.ts'; import { renderStatus } from '@/views/mastodon/statuses.ts';
import { NostrEvent } from '@nostrify/nostrify';
interface RenderNotificationOpts { interface RenderNotificationOpts {
viewerPubkey: string; viewerPubkey: string;
@ -32,7 +33,7 @@ async function renderMention(event: DittoEvent, opts: RenderNotificationOpts) {
if (!status) return; if (!status) return;
return { return {
id: event.id, id: notificationId(event),
type: 'mention', type: 'mention',
created_at: nostrDate(event.created_at).toISOString(), created_at: nostrDate(event.created_at).toISOString(),
account: status.account, 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); const account = event.author ? await renderAccount(event.author) : accountFromPubkey(event.pubkey);
return { return {
id: event.id, id: notificationId(event),
type: 'reblog', type: 'reblog',
created_at: nostrDate(event.created_at).toISOString(), created_at: nostrDate(event.created_at).toISOString(),
account, account,
@ -62,7 +63,7 @@ async function renderFavourite(event: DittoEvent, opts: RenderNotificationOpts)
const account = event.author ? await renderAccount(event.author) : accountFromPubkey(event.pubkey); const account = event.author ? await renderAccount(event.author) : accountFromPubkey(event.pubkey);
return { return {
id: event.id, id: notificationId(event),
type: 'favourite', type: 'favourite',
created_at: nostrDate(event.created_at).toISOString(), created_at: nostrDate(event.created_at).toISOString(),
account, account,
@ -77,7 +78,7 @@ async function renderReaction(event: DittoEvent, opts: RenderNotificationOpts) {
const account = event.author ? await renderAccount(event.author) : accountFromPubkey(event.pubkey); const account = event.author ? await renderAccount(event.author) : accountFromPubkey(event.pubkey);
return { return {
id: event.id, id: notificationId(event),
type: 'pleroma:emoji_reaction', type: 'pleroma:emoji_reaction',
emoji: event.content, emoji: event.content,
created_at: nostrDate(event.created_at).toISOString(), 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 }; export { renderNotification };