feat: attempt to delete repost if original post is deleted

This commit is contained in:
P. Reis 2024-04-06 22:32:39 -03:00
parent bd5899029e
commit ba08958b30
4 changed files with 19 additions and 10 deletions

View File

@ -181,7 +181,7 @@ const reblogStatusController: AppController = async (c) => {
kind: 1,
});
if (event == undefined) {
if (!event) {
return c.json({ error: 'Event not found.' }, 404);
}
@ -189,11 +189,10 @@ const reblogStatusController: AppController = async (c) => {
const reblogEvent = await createEvent({
kind: 6,
content: JSON.stringify(event),
tags,
}, c);
const status = await renderReblog(reblogEvent, reblogEvent.pubkey);
const status = await renderReblog(reblogEvent);
return c.json(status);
};

View File

@ -57,8 +57,8 @@ async function renderStatuses(c: AppContext, filters: NostrFilter[]) {
}
const statuses = await Promise.all(events.map((event) => {
if (event.kind == 6) {
return renderReblog(event, c.get('pubkey'));
if (event.kind === 6) {
return renderReblog(event)
}
return renderStatus(event, c.get('pubkey'));
}));

View File

@ -22,4 +22,5 @@ export interface DittoEvent extends NostrEvent {
event_stats?: EventStats;
d_author?: DittoEvent;
user?: DittoEvent;
repost?: NostrEvent;
}

View File

@ -4,7 +4,7 @@ import { Conf } from '@/config.ts';
import { nip19 } from '@/deps.ts';
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
import { getMediaLinks, parseNoteContent } from '@/note.ts';
import { getAuthor } from '@/queries.ts';
import { getAuthor, getEvent } from '@/queries.ts';
import { jsonMediaDataSchema } from '@/schemas/nostr.ts';
import { eventsDB } from '@/storages.ts';
import { findReplyTag } from '@/tags.ts';
@ -98,15 +98,24 @@ async function renderStatus(event: DittoEvent, viewerPubkey?: string) {
};
}
async function renderReblog(event: DittoEvent, viewerPubkey?: string) {
if (event.author == undefined) return;
async function renderReblog(event: DittoEvent) {
if (!event.author) return;
const reblog = await renderStatus(JSON.parse(event.content), viewerPubkey);
for (let i = 0; i < event.tags.length; i++) {
if (event.tags[i][0] === 'e') {
event.repost = await getEvent(event.tags[i][1], {kind:1})
break
}
}
if (!event.repost) return;
const reblog = await renderStatus(event.repost);
return {
id: event.id,
account: await renderAccount(event.author),
reblogged: true,
reblog,
reblog
};
}