Show correct reaction note

This commit is contained in:
Kieran 2023-01-02 22:54:03 +00:00
parent 96ec28d1e0
commit 3c87a12eab
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941

View File

@ -3,6 +3,7 @@ import { useDispatch, useSelector } from "react-redux"
import Note from "../element/Note";
import NoteReaction from "../element/NoteReaction";
import useSubscription from "../feed/Subscription";
import Event from "../nostr/Event";
import EventKind from "../nostr/EventKind";
import { Subscriptions } from "../nostr/Subscriptions";
import { markNotificationsRead } from "../state/Login";
@ -17,7 +18,11 @@ export default function NotificationsPage() {
const etagged = useMemo(() => {
return notifications?.filter(a => a.kind === EventKind.Reaction)
.map(a => a.tags.filter(b => b[0] === "e")[0][1])
.map(a => {
let ev = Event.FromObject(a);
let thread = ev.GetThread();
return thread?.ReplyTo?.Event ?? thread?.Root?.Event;
})
}, [notifications]);
const subEvents = useMemo(() => {
@ -37,16 +42,18 @@ export default function NotificationsPage() {
const sorted = [
...notifications
].sort((a,b) => b.created_at - a.created_at);
].sort((a, b) => b.created_at - a.created_at);
return (
<>
{sorted?.map(a => {
if (a.kind === EventKind.TextNote) {
let reactions = otherNotes?.notes?.filter(c => c.tags.find(b => b[0] === "e" && b[1] === a.id));
return <Note data={a} key={a.id} reactions={reactions}/>
return <Note data={a} key={a.id} reactions={reactions} />
} else if (a.kind === EventKind.Reaction) {
let reactedTo = a.tags.filter(a => a[0] === "e")[0][1];
let ev = Event.FromObject(a);
let thread = ev.GetThread();
let reactedTo = thread?.ReplyTo?.Event ?? thread?.Root?.Event;
let reactedNote = otherNotes?.notes?.find(c => c.id === reactedTo);
return <NoteReaction data={a} key={a.id} root={reactedNote} />
}