Add mute/ignore user + anti-spam (roadmap #5, NIP-51)

- fetchMuteList / publishMuteList in nostr client (kind 10000)
- mute store: mutedPubkeys persisted to localStorage + synced to relay;
  mute/unmute publish kind 10000 best-effort; fetchMuteList merges relay
  list with local mutes on login
- fetchMuteList called after every login (nsec + pubkey)
- Feed: muted pubkeys filtered from both Global and Following tabs
- NoteCard: ⋯ context menu (appears on hover, hidden for own notes)
  with mute / unmute action; backdrop click closes menu
- ProfileView: mute / unmute button in the action row (next to follow)
- SettingsView: MuteSection lists muted accounts with name + avatar;
  hover to reveal unmute button; hidden when mute list is empty

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jure
2026-03-10 18:23:30 +01:00
parent 926a7cbdae
commit 42fe32f584
8 changed files with 168 additions and 4 deletions

57
src/stores/mute.ts Normal file
View File

@@ -0,0 +1,57 @@
import { create } from "zustand";
import { fetchMuteList, publishMuteList } from "../lib/nostr";
const STORAGE_KEY = "wrystr_mutes";
function loadLocal(): string[] {
try {
return JSON.parse(localStorage.getItem(STORAGE_KEY) ?? "[]");
} catch {
return [];
}
}
function saveLocal(pubkeys: string[]) {
localStorage.setItem(STORAGE_KEY, JSON.stringify(pubkeys));
}
interface MuteState {
mutedPubkeys: string[];
fetchMuteList: (pubkey: string) => Promise<void>;
mute: (pubkey: string) => Promise<void>;
unmute: (pubkey: string) => Promise<void>;
}
export const useMuteStore = create<MuteState>((set, get) => ({
mutedPubkeys: loadLocal(),
fetchMuteList: async (pubkey: string) => {
try {
const pubkeys = await fetchMuteList(pubkey);
if (pubkeys.length === 0) return;
// Merge relay list with any local-only mutes (e.g. from npub sessions)
const local = get().mutedPubkeys;
const merged = Array.from(new Set([...pubkeys, ...local]));
set({ mutedPubkeys: merged });
saveLocal(merged);
} catch {
// Non-critical — local mutes still work
}
},
mute: async (pubkey: string) => {
const { mutedPubkeys } = get();
if (mutedPubkeys.includes(pubkey)) return;
const updated = [...mutedPubkeys, pubkey];
set({ mutedPubkeys: updated });
saveLocal(updated);
publishMuteList(updated).catch(() => {}); // best-effort relay publish
},
unmute: async (pubkey: string) => {
const updated = get().mutedPubkeys.filter((p) => p !== pubkey);
set({ mutedPubkeys: updated });
saveLocal(updated);
publishMuteList(updated).catch(() => {});
},
}));

View File

@@ -3,6 +3,7 @@ import { NDKPrivateKeySigner } from "@nostr-dev-kit/ndk";
import { getNDK, publishContactList } from "../lib/nostr";
import { nip19 } from "@nostr-dev-kit/ndk";
import { invoke } from "@tauri-apps/api/core";
import { useMuteStore } from "./mute";
export interface SavedAccount {
pubkey: string;
@@ -97,9 +98,10 @@ export const useUserStore = create<UserState>((set, get) => ({
// Store nsec in OS keychain (best-effort — gracefully ignored if unavailable)
invoke<void>("store_nsec", { pubkey, nsec: nsecInput }).catch(() => {});
// Fetch profile and follows
// Fetch profile, follows, and mute list
get().fetchOwnProfile();
get().fetchFollows();
useMuteStore.getState().fetchMuteList(pubkey);
} catch (err) {
set({ loginError: `Login failed: ${err}` });
}
@@ -134,6 +136,7 @@ export const useUserStore = create<UserState>((set, get) => ({
get().fetchOwnProfile();
get().fetchFollows();
useMuteStore.getState().fetchMuteList(pubkey);
} catch (err) {
set({ loginError: `Login failed: ${err}` });
}