Merge branch 'hydrate-reactions' into 'main'

Notifications: fix Favourites and EmojiReacts not being displayed

See merge request soapbox-pub/ditto!219
This commit is contained in:
Alex Gleason 2024-05-04 12:48:59 +00:00
commit fbf3011e3e
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) {
const id = event.tags.find(([name]) => name === 'q')?.[1];
if (id) {

View File

@ -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 };