Set `bookmarked` property of statuses, optimize status querying, fix relationships wrong assumption
This commit is contained in:
parent
5af0e0992f
commit
b98487196f
|
@ -2,13 +2,18 @@ import { eventsDB } from '@/db/events.ts';
|
||||||
import { hasTag } from '@/tags.ts';
|
import { hasTag } from '@/tags.ts';
|
||||||
|
|
||||||
async function renderRelationship(sourcePubkey: string, targetPubkey: string) {
|
async function renderRelationship(sourcePubkey: string, targetPubkey: string) {
|
||||||
const [event3, target3, event10000, target10000] = await eventsDB.getEvents([
|
const events = await eventsDB.getEvents([
|
||||||
{ kinds: [3], authors: [sourcePubkey], limit: 1 },
|
{ kinds: [3], authors: [sourcePubkey], limit: 1 },
|
||||||
{ kinds: [3], authors: [targetPubkey], limit: 1 },
|
{ kinds: [3], authors: [targetPubkey], limit: 1 },
|
||||||
{ kinds: [10000], authors: [sourcePubkey], limit: 1 },
|
{ kinds: [10000], authors: [sourcePubkey], limit: 1 },
|
||||||
{ kinds: [10000], authors: [targetPubkey], limit: 1 },
|
{ kinds: [10000], authors: [targetPubkey], limit: 1 },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const event3 = events.find((event) => event.kind === 3 && event.pubkey === sourcePubkey);
|
||||||
|
const target3 = events.find((event) => event.kind === 3 && event.pubkey === targetPubkey);
|
||||||
|
const event10000 = events.find((event) => event.kind === 10000 && event.pubkey === sourcePubkey);
|
||||||
|
const target10000 = events.find((event) => event.kind === 10000 && event.pubkey === targetPubkey);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: targetPubkey,
|
id: targetPubkey,
|
||||||
following: event3 ? hasTag(event3.tags, ['p', targetPubkey]) : false,
|
following: event3 ? hasTag(event3.tags, ['p', targetPubkey]) : false,
|
||||||
|
|
|
@ -30,14 +30,23 @@ async function renderStatus(event: DittoEvent<1>, viewerPubkey?: string) {
|
||||||
|
|
||||||
const { html, links, firstUrl } = parseNoteContent(event.content);
|
const { html, links, firstUrl } = parseNoteContent(event.content);
|
||||||
|
|
||||||
const [mentions, card, [repostEvent], [reactionEvent]] = await Promise
|
const [mentions, card, relatedEvents] = await Promise
|
||||||
.all([
|
.all([
|
||||||
Promise.all(mentionedPubkeys.map(toMention)),
|
Promise.all(mentionedPubkeys.map(toMention)),
|
||||||
firstUrl ? unfurlCardCached(firstUrl) : null,
|
firstUrl ? unfurlCardCached(firstUrl) : null,
|
||||||
viewerPubkey ? eventsDB.getEvents([{ kinds: [6], '#e': [event.id], authors: [viewerPubkey] }], { limit: 1 }) : [],
|
viewerPubkey
|
||||||
viewerPubkey ? eventsDB.getEvents([{ kinds: [7], '#e': [event.id], authors: [viewerPubkey] }], { limit: 1 }) : [],
|
? await eventsDB.getEvents([
|
||||||
|
{ kinds: [6], '#e': [event.id], authors: [viewerPubkey], limit: 1 },
|
||||||
|
{ kinds: [7], '#e': [event.id], authors: [viewerPubkey], limit: 1 },
|
||||||
|
{ kinds: [10003], '#e': [event.id], authors: [viewerPubkey], limit: 1 },
|
||||||
|
])
|
||||||
|
: [],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const reactionEvent = relatedEvents.find((event) => event.kind === 6);
|
||||||
|
const repostEvent = relatedEvents.find((event) => event.kind === 7);
|
||||||
|
const bookmarkEvent = relatedEvents.find((event) => event.kind === 10003);
|
||||||
|
|
||||||
const content = buildInlineRecipients(mentions) + html;
|
const content = buildInlineRecipients(mentions) + html;
|
||||||
|
|
||||||
const cw = event.tags.find(isCWTag);
|
const cw = event.tags.find(isCWTag);
|
||||||
|
@ -69,7 +78,7 @@ async function renderStatus(event: DittoEvent<1>, viewerPubkey?: string) {
|
||||||
favourited: reactionEvent?.content === '+',
|
favourited: reactionEvent?.content === '+',
|
||||||
reblogged: Boolean(repostEvent),
|
reblogged: Boolean(repostEvent),
|
||||||
muted: false,
|
muted: false,
|
||||||
bookmarked: false,
|
bookmarked: Boolean(bookmarkEvent),
|
||||||
reblog: null,
|
reblog: null,
|
||||||
application: null,
|
application: null,
|
||||||
media_attachments: media.map(renderAttachment),
|
media_attachments: media.map(renderAttachment),
|
||||||
|
|
Loading…
Reference in New Issue