From 6d1375ba5908399406b826e66aa9d279342816a6 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 31 Dec 2023 22:56:21 -0600 Subject: [PATCH] Optimize the relationships controller, support block relationships --- src/views/mastodon/relationships.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/views/mastodon/relationships.ts b/src/views/mastodon/relationships.ts index 57a17df..97fa0f1 100644 --- a/src/views/mastodon/relationships.ts +++ b/src/views/mastodon/relationships.ts @@ -1,20 +1,22 @@ -import { getFollows } from '@/queries.ts'; +import { eventsDB } from '@/db/events.ts'; import { hasTag } from '@/tags.ts'; async function renderRelationship(sourcePubkey: string, targetPubkey: string) { - const [source, target] = await Promise.all([ - getFollows(sourcePubkey), - getFollows(targetPubkey), + const [event3, target3, event10000, target10000] = await eventsDB.getEvents([ + { kinds: [3], authors: [sourcePubkey], limit: 1 }, + { kinds: [3], authors: [targetPubkey], limit: 1 }, + { kinds: [10000], authors: [sourcePubkey], limit: 1 }, + { kinds: [10000], authors: [targetPubkey], limit: 1 }, ]); return { id: targetPubkey, - following: source ? hasTag(source.tags, ['p', targetPubkey]) : false, + following: event3 ? hasTag(event3.tags, ['p', targetPubkey]) : false, showing_reblogs: true, notifying: false, - followed_by: target ? hasTag(target.tags, ['p', sourcePubkey]) : false, - blocking: false, - blocked_by: false, + followed_by: target3 ? hasTag(target3?.tags, ['p', sourcePubkey]) : false, + blocking: event10000 ? hasTag(target10000.tags, ['p', targetPubkey]) : false, + blocked_by: target10000 ? hasTag(target10000.tags, ['p', sourcePubkey]) : false, muting: false, muting_notifications: false, requested: false,