Remove isFollowing util

This commit is contained in:
Alex Gleason 2023-12-31 20:30:41 -06:00
parent dc27ee05d4
commit f665c5f825
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
3 changed files with 8 additions and 19 deletions

View File

@ -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);

View File

@ -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<K extends number>(events: Event<K>[]): Event<K>[] {
return [...new Map(events.map((event) => [event.id, event])).values()];
@ -155,7 +149,6 @@ export {
eventDateComparator,
eventMatchesTemplate,
findTag,
isFollowing,
isNostrId,
isRelay,
isURL,

View File

@ -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,