setTag -> addTag
This commit is contained in:
parent
8023cfa7b2
commit
63fb934220
|
@ -7,7 +7,7 @@ import { type DittoFilter } from '@/filter.ts';
|
||||||
import { getAuthor, getFollowedPubkeys } from '@/queries.ts';
|
import { getAuthor, getFollowedPubkeys } from '@/queries.ts';
|
||||||
import { booleanParamSchema, fileSchema } from '@/schema.ts';
|
import { booleanParamSchema, fileSchema } from '@/schema.ts';
|
||||||
import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
|
import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
|
||||||
import { setTag } from '@/tags.ts';
|
import { addTag } from '@/tags.ts';
|
||||||
import { uploadFile } from '@/upload.ts';
|
import { uploadFile } from '@/upload.ts';
|
||||||
import { lookupAccount, nostrNow } from '@/utils.ts';
|
import { lookupAccount, nostrNow } from '@/utils.ts';
|
||||||
import { paginated, paginationSchema, parseBody, updateListEvent } from '@/utils/web.ts';
|
import { paginated, paginationSchema, parseBody, updateListEvent } from '@/utils/web.ts';
|
||||||
|
@ -219,7 +219,7 @@ const followController: AppController = async (c) => {
|
||||||
|
|
||||||
await updateListEvent(
|
await updateListEvent(
|
||||||
{ kinds: [3], authors: [sourcePubkey] },
|
{ kinds: [3], authors: [sourcePubkey] },
|
||||||
(tags) => setTag(tags, ['p', targetPubkey]),
|
(tags) => addTag(tags, ['p', targetPubkey]),
|
||||||
c,
|
c,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { assertEquals } from '@/deps-test.ts';
|
import { assertEquals } from '@/deps-test.ts';
|
||||||
|
|
||||||
import { deleteTag, getTagSet, setTag } from './tags.ts';
|
import { addTag, deleteTag, getTagSet } from './tags.ts';
|
||||||
|
|
||||||
Deno.test('getTagSet', () => {
|
Deno.test('getTagSet', () => {
|
||||||
assertEquals(getTagSet([], 'p'), new Set());
|
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']));
|
assertEquals(getTagSet([['p', '123'], ['p', '456'], ['q', '789']], 'p'), new Set(['123', '456']));
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test('setTag', () => {
|
Deno.test('addTag', () => {
|
||||||
assertEquals(setTag([], ['p', '123']), [['p', '123']]);
|
assertEquals(addTag([], ['p', '123']), [['p', '123']]);
|
||||||
assertEquals(setTag([['p', '123']], ['p', '123']), [['p', '123']]);
|
assertEquals(addTag([['p', '123']], ['p', '123']), [['p', '123']]);
|
||||||
assertEquals(setTag([['p', '123'], ['p', '456']], ['p', '123']), [['p', '123'], ['p', '456']]);
|
assertEquals(addTag([['p', '123'], ['p', '456']], ['p', '123']), [['p', '123'], ['p', '456']]);
|
||||||
assertEquals(setTag([['p', '123'], ['p', '456']], ['p', '789']), [['p', '123'], ['p', '456'], ['p', '789']]);
|
assertEquals(addTag([['p', '123'], ['p', '456']], ['p', '789']), [['p', '123'], ['p', '456'], ['p', '789']]);
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test('deleteTag', () => {
|
Deno.test('deleteTag', () => {
|
||||||
|
|
|
@ -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. */
|
/** 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]);
|
const tagIndex = tags.findIndex(([name, value]) => name === tag[0] && value === tag[1]);
|
||||||
if (tagIndex === -1) {
|
if (tagIndex === -1) {
|
||||||
return [...tags, tag];
|
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 };
|
||||||
|
|
|
@ -53,7 +53,7 @@ async function updateEvent<K extends number, E extends EventStub<K>>(
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Fetch existing event, update its tags, then publish the new event. */
|
/** Fetch existing event, update its tags, then publish the new event. */
|
||||||
function updateListEvent<K extends number, E extends EventStub<K>>(
|
function updateListEvent<K extends number>(
|
||||||
filter: UpdateEventFilter<K>,
|
filter: UpdateEventFilter<K>,
|
||||||
fn: (tags: string[][]) => string[][],
|
fn: (tags: string[][]) => string[][],
|
||||||
c: AppContext,
|
c: AppContext,
|
||||||
|
|
Loading…
Reference in New Issue