fix: get replies function (#213)

This commit is contained in:
雨宮蓮
2024-06-19 21:02:33 +07:00
committed by GitHub
parent 6c26f8967b
commit f8280ec8ee
4 changed files with 74 additions and 55 deletions

View File

@@ -17,6 +17,7 @@ export class LumeEvent {
public sig: string;
public meta: Meta;
public relay?: string;
public replies?: LumeEvent[];
#raw: NostrEvent;
constructor(event: NostrEvent) {
@@ -94,20 +95,22 @@ export class LumeEvent {
return { id, relayHint };
}
public async getReplies(id: string) {
const query = await commands.getReplies(id);
public async getAllReplies() {
const query = await commands.getReplies(this.id);
if (query.status === "ok") {
const events = query.data.map((item) => {
const raw = JSON.parse(item.raw) as EventWithReplies;
const nostrEvent: NostrEvent = JSON.parse(item.raw);
if (item.parsed) {
raw.meta = item.parsed;
nostrEvent.meta = item.parsed;
} else {
raw.meta = null;
nostrEvent.meta = null;
}
return raw;
const lumeEvent = new LumeEvent(nostrEvent);
return lumeEvent;
});
if (events.length > 0) {
@@ -115,7 +118,7 @@ export class LumeEvent {
for (const event of events) {
const tags = event.tags.filter(
(el) => el[0] === "e" && el[1] !== id && el[3] !== "mention",
(el) => el[0] === "e" && el[1] !== this.id && el[3] !== "mention",
);
if (tags.length > 0) {
@@ -141,6 +144,9 @@ export class LumeEvent {
}
return events;
} else {
console.error(query.error);
return [];
}
}

View File

@@ -10,7 +10,7 @@ import { LumeEvent } from "./event";
export class NostrQuery {
static #toLumeEvents(richEvents: RichEvent[]) {
const events = richEvents.map((item) => {
const nostrEvent = JSON.parse(item.raw) as NostrEvent;
const nostrEvent: NostrEvent = JSON.parse(item.raw);
if (item.parsed) {
nostrEvent.meta = item.parsed;