From 63fb934220525bf6748aa90b44ef6ce64ebe7ebc Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 31 Dec 2023 22:04:11 -0600 Subject: [PATCH] setTag -> addTag --- src/controllers/api/accounts.ts | 4 ++-- src/tags.test.ts | 12 ++++++------ src/tags.ts | 4 ++-- src/utils/web.ts | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/controllers/api/accounts.ts b/src/controllers/api/accounts.ts index 0e0ee16..5609fbe 100644 --- a/src/controllers/api/accounts.ts +++ b/src/controllers/api/accounts.ts @@ -7,7 +7,7 @@ import { type DittoFilter } from '@/filter.ts'; import { getAuthor, getFollowedPubkeys } from '@/queries.ts'; import { booleanParamSchema, fileSchema } from '@/schema.ts'; import { jsonMetaContentSchema } from '@/schemas/nostr.ts'; -import { setTag } from '@/tags.ts'; +import { addTag } from '@/tags.ts'; import { uploadFile } from '@/upload.ts'; import { lookupAccount, nostrNow } from '@/utils.ts'; import { paginated, paginationSchema, parseBody, updateListEvent } from '@/utils/web.ts'; @@ -219,7 +219,7 @@ const followController: AppController = async (c) => { await updateListEvent( { kinds: [3], authors: [sourcePubkey] }, - (tags) => setTag(tags, ['p', targetPubkey]), + (tags) => addTag(tags, ['p', targetPubkey]), c, ); diff --git a/src/tags.test.ts b/src/tags.test.ts index 9c7e938..c4d3214 100644 --- a/src/tags.test.ts +++ b/src/tags.test.ts @@ -1,6 +1,6 @@ import { assertEquals } from '@/deps-test.ts'; -import { deleteTag, getTagSet, setTag } from './tags.ts'; +import { addTag, deleteTag, getTagSet } from './tags.ts'; Deno.test('getTagSet', () => { assertEquals(getTagSet([], 'p'), new Set()); @@ -9,11 +9,11 @@ Deno.test('getTagSet', () => { assertEquals(getTagSet([['p', '123'], ['p', '456'], ['q', '789']], 'p'), new Set(['123', '456'])); }); -Deno.test('setTag', () => { - assertEquals(setTag([], ['p', '123']), [['p', '123']]); - assertEquals(setTag([['p', '123']], ['p', '123']), [['p', '123']]); - assertEquals(setTag([['p', '123'], ['p', '456']], ['p', '123']), [['p', '123'], ['p', '456']]); - assertEquals(setTag([['p', '123'], ['p', '456']], ['p', '789']), [['p', '123'], ['p', '456'], ['p', '789']]); +Deno.test('addTag', () => { + assertEquals(addTag([], ['p', '123']), [['p', '123']]); + assertEquals(addTag([['p', '123']], ['p', '123']), [['p', '123']]); + assertEquals(addTag([['p', '123'], ['p', '456']], ['p', '123']), [['p', '123'], ['p', '456']]); + assertEquals(addTag([['p', '123'], ['p', '456']], ['p', '789']), [['p', '123'], ['p', '456'], ['p', '789']]); }); Deno.test('deleteTag', () => { diff --git a/src/tags.ts b/src/tags.ts index 4909b3f..6027808 100644 --- a/src/tags.ts +++ b/src/tags.ts @@ -22,7 +22,7 @@ function deleteTag(tags: readonly string[][], tag: string[]): string[][] { } /** Add a tag to the list, replacing the name/value pair if it already exists. */ -function setTag(tags: readonly string[][], tag: string[]): string[][] { +function addTag(tags: readonly string[][], tag: string[]): string[][] { const tagIndex = tags.findIndex(([name, value]) => name === tag[0] && value === tag[1]); if (tagIndex === -1) { return [...tags, tag]; @@ -31,4 +31,4 @@ function setTag(tags: readonly string[][], tag: string[]): string[][] { } } -export { deleteTag, getTagSet, hasTag, setTag }; +export { addTag, deleteTag, getTagSet, hasTag }; diff --git a/src/utils/web.ts b/src/utils/web.ts index e5437d2..3687a65 100644 --- a/src/utils/web.ts +++ b/src/utils/web.ts @@ -53,7 +53,7 @@ async function updateEvent>( } /** Fetch existing event, update its tags, then publish the new event. */ -function updateListEvent>( +function updateListEvent( filter: UpdateEventFilter, fn: (tags: string[][]) => string[][], c: AppContext,