diff --git a/src/controllers/api/accounts.ts b/src/controllers/api/accounts.ts index 412fa530..d10509e5 100644 --- a/src/controllers/api/accounts.ts +++ b/src/controllers/api/accounts.ts @@ -7,9 +7,9 @@ import { type DittoFilter } from '@/filter.ts'; import { getAuthor, getFollowedPubkeys, getFollows } from '@/queries.ts'; import { booleanParamSchema, fileSchema } from '@/schema.ts'; import { jsonMetaContentSchema } from '@/schemas/nostr.ts'; -import { setTag } from '@/tags.ts'; +import { hasTag, setTag } from '@/tags.ts'; import { uploadFile } from '@/upload.ts'; -import { isFollowing, lookupAccount, nostrNow } from '@/utils.ts'; +import { lookupAccount, nostrNow } from '@/utils.ts'; import { paginated, paginationSchema, parseBody, updateListEvent } from '@/utils/web.ts'; import { createEvent } from '@/utils/web.ts'; import { renderEventAccounts } from '@/views.ts'; @@ -218,14 +218,10 @@ const followController: AppController = async (c) => { const targetPubkey = c.req.param('pubkey'); const source = await getFollows(sourcePubkey); + const tag = ['p', targetPubkey]; - if (!source || !isFollowing(source, targetPubkey)) { - await updateListEvent( - source ?? { kind: 3 }, - ['p', targetPubkey], - setTag, - c, - ); + if (!source || !hasTag(source.tags, tag)) { + await updateListEvent(source ?? { kind: 3 }, tag, setTag, c); } const relationship = await renderRelationship(sourcePubkey, targetPubkey); diff --git a/src/utils.ts b/src/utils.ts index 27c61364..1294e007 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,6 +1,5 @@ import { type Event, type EventTemplate, getEventHash, nip19, z } from '@/deps.ts'; import { getAuthor } from '@/queries.ts'; -import { hasTag } from '@/tags.ts'; import { lookupNip05Cached } from '@/utils/nip05.ts'; import { nostrIdSchema } from '@/schemas/nostr.ts'; @@ -96,11 +95,6 @@ const relaySchema = z.string().max(255).startsWith('wss://').url(); /** Check whether the value is a valid relay URL. */ const isRelay = (relay: string): relay is `wss://${string}` => relaySchema.safeParse(relay).success; -/** Check whether source is following target. */ -function isFollowing(source: Event<3>, targetPubkey: string): boolean { - return hasTag(source.tags, ['p', targetPubkey]); -} - /** Deduplicate events by ID. */ function dedupeEvents(events: Event[]): Event[] { return [...new Map(events.map((event) => [event.id, event])).values()]; @@ -155,7 +149,6 @@ export { eventDateComparator, eventMatchesTemplate, findTag, - isFollowing, isNostrId, isRelay, isURL, diff --git a/src/views/mastodon/relationships.ts b/src/views/mastodon/relationships.ts index 91d33ea7..57a17df8 100644 --- a/src/views/mastodon/relationships.ts +++ b/src/views/mastodon/relationships.ts @@ -1,5 +1,5 @@ import { getFollows } from '@/queries.ts'; -import { isFollowing } from '@/utils.ts'; +import { hasTag } from '@/tags.ts'; async function renderRelationship(sourcePubkey: string, targetPubkey: string) { const [source, target] = await Promise.all([ @@ -9,10 +9,10 @@ async function renderRelationship(sourcePubkey: string, targetPubkey: string) { return { id: targetPubkey, - following: source ? isFollowing(source, targetPubkey) : false, + following: source ? hasTag(source.tags, ['p', targetPubkey]) : false, showing_reblogs: true, notifying: false, - followed_by: target ? isFollowing(target, sourcePubkey) : false, + followed_by: target ? hasTag(target.tags, ['p', sourcePubkey]) : false, blocking: false, blocked_by: false, muting: false,