aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/nip51.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-02-11 17:51:24 -0800
committerAdam Soltys <[email protected]>2026-02-11 17:51:24 -0800
commit13466248004327e9a026cb89f94926f9b060d1c1 (patch)
tree47b4972c33809ccdf866b043c92cd3e0ecf5dcd0 /src/lib/nip51.ts
parent3aa9ce1b5985397d7f568887ec6f881df13c1034 (diff)
downloadcoinos-ui-13466248004327e9a026cb89f94926f9b060d1c1.tar.gz
coinos-ui-13466248004327e9a026cb89f94926f9b060d1c1.zip
linting
Diffstat (limited to 'src/lib/nip51.ts')
-rw-r--r--src/lib/nip51.ts113
1 files changed, 62 insertions, 51 deletions
diff --git a/src/lib/nip51.ts b/src/lib/nip51.ts
index 0210bf8b..7560dd3d 100644
--- a/src/lib/nip51.ts
+++ b/src/lib/nip51.ts
@@ -1,70 +1,81 @@
-import { SimplePool } from 'nostr-tools/pool';
-import { signEvent, encrypt, decrypt } from '$lib/nip07';
+import { SimplePool } from "nostr-tools/pool";
+import { signEvent, encrypt, decrypt } from "$lib/nip07";
const pool = new SimplePool();
-import { PUBLIC_DM_RELAYS } from '$env/static/public';
-const DM_RELAYS_LIST = PUBLIC_DM_RELAYS.split(',');
+import { PUBLIC_DM_RELAYS } from "$env/static/public";
+const DM_RELAYS_LIST = PUBLIC_DM_RELAYS.split(",");
// Mute the provided pubkey, as the provided user.
export const mute = async (user: any, pubkey: string, hide: boolean) => {
- let { shown, hidden } = await getMuteLists(user);
- if (hide) {
- hidden.push(["p", pubkey]);
- } else {
- shown.push(["p", pubkey]);
- }
- await publishMuteList(user, shown, hidden);
-}
+ let { shown, hidden } = await getMuteLists(user);
+ if (hide) {
+ hidden.push(["p", pubkey]);
+ } else {
+ shown.push(["p", pubkey]);
+ }
+ await publishMuteList(user, shown, hidden);
+};
const tagMatches = (tag: string[], pubkey: string): boolean =>
- tag.length >= 2 && tag[0] === "p" && tag[1] === pubkey;
+ tag.length >= 2 && tag[0] === "p" && tag[1] === pubkey;
// Unmute the provided pubkey, as the provided user.
export const unmute = async (user: any, pubkey: string) => {
- let { shown, hidden } = await getMuteLists(user);
- shown = shown.filter((tag: string[]) => !tagMatches(tag, pubkey));
- hidden = hidden.filter((tag: string[]) => !tagMatches(tag, pubkey));
- await publishMuteList(user, shown, hidden);
-}
+ let { shown, hidden } = await getMuteLists(user);
+ shown = shown.filter((tag: string[]) => !tagMatches(tag, pubkey));
+ hidden = hidden.filter((tag: string[]) => !tagMatches(tag, pubkey));
+ await publishMuteList(user, shown, hidden);
+};
// Returns a set of the provided user's muted accounts.
export const mutedAccounts = async (user: any): Promise<Set<string>> => {
- const { shown, hidden } = await getMuteLists(user);
- let muted = new Set<string>();
- for (const tag of shown) {
- if (tag.length >= 2 && tag[0] === "p") {
- muted.add(tag[1]);
- }
+ const { shown, hidden } = await getMuteLists(user);
+ let muted = new Set<string>();
+ for (const tag of shown) {
+ if (tag.length >= 2 && tag[0] === "p") {
+ muted.add(tag[1]);
}
- for (const tag of hidden) {
- if (tag.length >= 2 && tag[0] === "p") {
- muted.add(tag[1]);
- }
+ }
+ for (const tag of hidden) {
+ if (tag.length >= 2 && tag[0] === "p") {
+ muted.add(tag[1]);
}
- return muted;
-}
+ }
+ return muted;
+};
const getMuteLists = async (user: any): Promise<any> => {
- const listEvents = await pool.querySync(
- DM_RELAYS_LIST, { kinds: [10000], "authors": [user.pubkey], limit: 1 }
- );
- if (listEvents.length == 0) {
- return { shown: [], hidden: [] };
- }
+ const listEvents = await pool.querySync(DM_RELAYS_LIST, {
+ kinds: [10000],
+ authors: [user.pubkey],
+ limit: 1,
+ });
+ if (listEvents.length == 0) {
+ return { shown: [], hidden: [] };
+ }
- return {
- shown: listEvents[0].tags,
- hidden: listEvents[0].content == "" ? [] :
- await decrypt(listEvents[0].content, user, user.pubkey)
- };
-}
+ return {
+ shown: listEvents[0].tags,
+ hidden:
+ listEvents[0].content == ""
+ ? []
+ : await decrypt(listEvents[0].content, user, user.pubkey),
+ };
+};
-const publishMuteList = async (user: any, shown: string[], hidden: string[]) => {
- const event = await signEvent({
- kind: 10000,
- created_at: Math.floor(Date.now() / 1000),
- tags: shown,
- content: await encrypt(hidden, user, user.pubkey)
- }, user);
- return Promise.any(pool.publish(DM_RELAYS_LIST, event));
-}
+const publishMuteList = async (
+ user: any,
+ shown: string[],
+ hidden: string[],
+) => {
+ const event = await signEvent(
+ {
+ kind: 10000,
+ created_at: Math.floor(Date.now() / 1000),
+ tags: shown,
+ content: await encrypt(hidden, user, user.pubkey),
+ },
+ user,
+ );
+ return Promise.any(pool.publish(DM_RELAYS_LIST, event));
+};