Merge branch 'refactor-queries-ts' into 'main'

refactor: getFollowedPubkeys() and getFeedPubkeys() functions return Set<string>

See merge request soapbox-pub/ditto!496
This commit is contained in:
Alex Gleason 2024-09-17 17:40:39 +00:00
commit c67d27e580
4 changed files with 9 additions and 9 deletions

View file

@ -381,7 +381,7 @@ const followersController: AppController = (c) => {
const followingController: AppController = async (c) => { const followingController: AppController = async (c) => {
const pubkey = c.req.param('pubkey'); const pubkey = c.req.param('pubkey');
const pubkeys = await getFollowedPubkeys(pubkey); const pubkeys = await getFollowedPubkeys(pubkey);
return renderAccounts(c, pubkeys); return renderAccounts(c, [...pubkeys]);
}; };
/** https://docs.joinmastodon.org/methods/accounts/#block */ /** https://docs.joinmastodon.org/methods/accounts/#block */
@ -460,7 +460,7 @@ const familiarFollowersController: AppController = async (c) => {
const follows = await getFollowedPubkeys(pubkey); const follows = await getFollowedPubkeys(pubkey);
const results = await Promise.all(ids.map(async (id) => { const results = await Promise.all(ids.map(async (id) => {
const followLists = await store.query([{ kinds: [3], authors: follows, '#p': [id] }]) const followLists = await store.query([{ kinds: [3], authors: [...follows], '#p': [id] }])
.then((events) => hydrateEvents({ events, store })); .then((events) => hydrateEvents({ events, store }));
const accounts = await Promise.all( const accounts = await Promise.all(

View file

@ -215,7 +215,7 @@ async function topicToFilter(
// HACK: this puts the user's entire contacts list into RAM, // HACK: this puts the user's entire contacts list into RAM,
// and then calls `matchFilters` over it. Refreshing the page // and then calls `matchFilters` over it. Refreshing the page
// is required after following a new user. // is required after following a new user.
return pubkey ? { kinds: [1, 6], authors: await getFeedPubkeys(pubkey) } : undefined; return pubkey ? { kinds: [1, 6], authors: [...await getFeedPubkeys(pubkey)] } : undefined;
} }
} }

View file

@ -13,7 +13,7 @@ import { renderReblog, renderStatus } from '@/views/mastodon/statuses.ts';
const homeTimelineController: AppController = async (c) => { const homeTimelineController: AppController = async (c) => {
const params = c.get('pagination'); const params = c.get('pagination');
const pubkey = await c.get('signer')?.getPublicKey()!; const pubkey = await c.get('signer')?.getPublicKey()!;
const authors = await getFeedPubkeys(pubkey); const authors = [...await getFeedPubkeys(pubkey)];
return renderStatuses(c, [{ authors, kinds: [1, 6], ...params }]); return renderStatuses(c, [{ authors, kinds: [1, 6], ...params }]);
}; };

View file

@ -56,16 +56,16 @@ const getFollows = async (pubkey: string, signal?: AbortSignal): Promise<NostrEv
}; };
/** Get pubkeys the user follows. */ /** Get pubkeys the user follows. */
async function getFollowedPubkeys(pubkey: string, signal?: AbortSignal): Promise<string[]> { async function getFollowedPubkeys(pubkey: string, signal?: AbortSignal): Promise<Set<string>> {
const event = await getFollows(pubkey, signal); const event = await getFollows(pubkey, signal);
if (!event) return []; if (!event) return new Set();
return [...getTagSet(event.tags, 'p')]; return getTagSet(event.tags, 'p');
} }
/** Get pubkeys the user follows, including the user's own pubkey. */ /** Get pubkeys the user follows, including the user's own pubkey. */
async function getFeedPubkeys(pubkey: string): Promise<string[]> { async function getFeedPubkeys(pubkey: string): Promise<Set<string>> {
const authors = await getFollowedPubkeys(pubkey); const authors = await getFollowedPubkeys(pubkey);
return [...authors, pubkey]; return authors.add(pubkey);
} }
async function getAncestors(store: NStore, event: NostrEvent, result: NostrEvent[] = []): Promise<NostrEvent[]> { async function getAncestors(store: NStore, event: NostrEvent, result: NostrEvent[] = []): Promise<NostrEvent[]> {