Hide muted users from threads

This commit is contained in:
Alex Gleason 2024-06-05 11:00:16 -05:00
parent 358a6f02a1
commit c5c4f47bc2
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
3 changed files with 18 additions and 10 deletions

View File

@ -203,6 +203,7 @@ const deleteStatusController: AppController = async (c) => {
const contextController: AppController = async (c) => { const contextController: AppController = async (c) => {
const id = c.req.param('id'); const id = c.req.param('id');
const store = c.get('store');
const event = await getEvent(id, { kind: 1, relations: ['author', 'event_stats', 'author_stats'] }); const event = await getEvent(id, { kind: 1, relations: ['author', 'event_stats', 'author_stats'] });
const viewerPubkey = await c.get('signer')?.getPublicKey(); const viewerPubkey = await c.get('signer')?.getPublicKey();
@ -215,8 +216,8 @@ const contextController: AppController = async (c) => {
if (event) { if (event) {
const [ancestors, descendants] = await Promise.all([ const [ancestors, descendants] = await Promise.all([
getAncestors(event).then(renderStatuses), getAncestors(store, event).then(renderStatuses),
getDescendants(event.id).then(renderStatuses), getDescendants(store, event.id).then(renderStatuses),
]); ]);
return c.json({ ancestors, descendants }); return c.json({ ancestors, descendants });

View File

@ -1,4 +1,4 @@
import { NostrEvent, NostrFilter } from '@nostrify/nostrify'; import { NostrEvent, NostrFilter, NStore } from '@nostrify/nostrify';
import Debug from '@soapbox/stickynotes/debug'; import Debug from '@soapbox/stickynotes/debug';
import { Conf } from '@/config.ts'; import { Conf } from '@/config.ts';
@ -68,7 +68,7 @@ async function getFeedPubkeys(pubkey: string): Promise<string[]> {
return [...authors, pubkey]; return [...authors, pubkey];
} }
async function getAncestors(event: NostrEvent, result: NostrEvent[] = []): Promise<NostrEvent[]> { async function getAncestors(store: NStore, event: NostrEvent, result: NostrEvent[] = []): Promise<NostrEvent[]> {
if (result.length < 100) { if (result.length < 100) {
const replyTag = findReplyTag(event.tags); const replyTag = findReplyTag(event.tags);
const inReplyTo = replyTag ? replyTag[1] : undefined; const inReplyTo = replyTag ? replyTag[1] : undefined;
@ -78,7 +78,7 @@ async function getAncestors(event: NostrEvent, result: NostrEvent[] = []): Promi
if (parentEvent) { if (parentEvent) {
result.push(parentEvent); result.push(parentEvent);
return getAncestors(parentEvent, result); return getAncestors(store, parentEvent, result);
} }
} }
} }
@ -86,11 +86,13 @@ async function getAncestors(event: NostrEvent, result: NostrEvent[] = []): Promi
return result.reverse(); return result.reverse();
} }
async function getDescendants(eventId: string, signal = AbortSignal.timeout(2000)): Promise<NostrEvent[]> { async function getDescendants(
const store = await Storages.db(); store: NStore,
eventId: string,
signal = AbortSignal.timeout(2000),
): Promise<NostrEvent[]> {
const events = await store const events = await store
.query([{ kinds: [1], '#e': [eventId] }], { limit: 200, signal }) .query([{ kinds: [1], '#e': [eventId], limit: 200 }], { signal })
.then((events) => events.filter(({ tags }) => findReplyTag(tags)?.[1] === eventId)); .then((events) => events.filter(({ tags }) => findReplyTag(tags)?.[1] === eventId));
return hydrateEvents({ events, store, signal }); return hydrateEvents({ events, store, signal });

View File

@ -4,6 +4,8 @@ import { DittoEvent } from '@/interfaces/DittoEvent.ts';
import { getTagSet } from '@/utils/tags.ts'; import { getTagSet } from '@/utils/tags.ts';
export class UserStore implements NStore { export class UserStore implements NStore {
private promise: Promise<DittoEvent[]> | undefined;
constructor(private pubkey: string, private store: NStore) {} constructor(private pubkey: string, private store: NStore) {}
async event(event: NostrEvent, opts?: { signal?: AbortSignal }): Promise<void> { async event(event: NostrEvent, opts?: { signal?: AbortSignal }): Promise<void> {
@ -24,7 +26,10 @@ export class UserStore implements NStore {
} }
private async getMuteList(): Promise<DittoEvent | undefined> { private async getMuteList(): Promise<DittoEvent | undefined> {
const [muteList] = await this.store.query([{ authors: [this.pubkey], kinds: [10000], limit: 1 }]); if (!this.promise) {
this.promise = this.store.query([{ authors: [this.pubkey], kinds: [10000], limit: 1 }]);
}
const [muteList] = await this.promise;
return muteList; return muteList;
} }