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

View File

@@ -1,6 +1,7 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useFeedStore } from "../../stores/feed"; import { useFeedStore } from "../../stores/feed";
import { useUserStore } from "../../stores/user"; import { useUserStore } from "../../stores/user";
import { useMuteStore } from "../../stores/mute";
import { fetchFollowFeed, getNDK } from "../../lib/nostr"; import { fetchFollowFeed, getNDK } from "../../lib/nostr";
import { NoteCard } from "./NoteCard"; import { NoteCard } from "./NoteCard";
import { ComposeBox } from "./ComposeBox"; import { ComposeBox } from "./ComposeBox";
@@ -11,6 +12,7 @@ type FeedTab = "global" | "following";
export function Feed() { export function Feed() {
const { notes, loading, connected, error, connect, loadCachedFeed, loadFeed } = useFeedStore(); const { notes, loading, connected, error, connect, loadCachedFeed, loadFeed } = useFeedStore();
const { loggedIn, follows } = useUserStore(); const { loggedIn, follows } = useUserStore();
const { mutedPubkeys } = useMuteStore();
const [tab, setTab] = useState<FeedTab>("global"); const [tab, setTab] = useState<FeedTab>("global");
const [followNotes, setFollowNotes] = useState<NDKEvent[]>([]); const [followNotes, setFollowNotes] = useState<NDKEvent[]>([]);
@@ -43,6 +45,7 @@ export function Feed() {
const isLoading = isFollowing ? followLoading : loading; const isLoading = isFollowing ? followLoading : loading;
const filteredNotes = activeNotes.filter((event) => { const filteredNotes = activeNotes.filter((event) => {
if (mutedPubkeys.includes(event.pubkey)) return false;
const c = event.content.trim(); const c = event.content.trim();
if (!c || c.startsWith("{") || c.startsWith("[")) return false; if (!c || c.startsWith("{") || c.startsWith("[")) return false;
// Filter out notes that look like base64 blobs or relay protocol messages // Filter out notes that look like base64 blobs or relay protocol messages

View File

@@ -3,6 +3,7 @@ import { NDKEvent } from "@nostr-dev-kit/ndk";
import { useProfile } from "../../hooks/useProfile"; import { useProfile } from "../../hooks/useProfile";
import { useReactionCount } from "../../hooks/useReactionCount"; import { useReactionCount } from "../../hooks/useReactionCount";
import { useUserStore } from "../../stores/user"; import { useUserStore } from "../../stores/user";
import { useMuteStore } from "../../stores/mute";
import { useUIStore } from "../../stores/ui"; import { useUIStore } from "../../stores/ui";
import { timeAgo, shortenPubkey } from "../../lib/utils"; import { timeAgo, shortenPubkey } from "../../lib/utils";
import { publishReaction, publishReply, getNDK } from "../../lib/nostr"; import { publishReaction, publishReply, getNDK } from "../../lib/nostr";
@@ -20,7 +21,9 @@ export function NoteCard({ event }: NoteCardProps) {
const nip05 = profile?.nip05; const nip05 = profile?.nip05;
const time = event.created_at ? timeAgo(event.created_at) : ""; const time = event.created_at ? timeAgo(event.created_at) : "";
const { loggedIn } = useUserStore(); const { loggedIn, pubkey: ownPubkey } = useUserStore();
const { mutedPubkeys, mute, unmute } = useMuteStore();
const isMuted = mutedPubkeys.includes(event.pubkey);
const { openProfile, openThread, currentView } = useUIStore(); const { openProfile, openThread, currentView } = useUIStore();
const likedKey = "wrystr_liked"; const likedKey = "wrystr_liked";
const getLiked = () => { const getLiked = () => {
@@ -37,6 +40,7 @@ export function NoteCard({ event }: NoteCardProps) {
const [replySent, setReplySent] = useState(false); const [replySent, setReplySent] = useState(false);
const replyRef = useRef<HTMLTextAreaElement>(null); const replyRef = useRef<HTMLTextAreaElement>(null);
const [showZap, setShowZap] = useState(false); const [showZap, setShowZap] = useState(false);
const [menuOpen, setMenuOpen] = useState(false);
const handleLike = async () => { const handleLike = async () => {
if (!loggedIn || liked || liking) return; if (!loggedIn || liked || liking) return;
@@ -80,7 +84,7 @@ export function NoteCard({ event }: NoteCardProps) {
}; };
return ( return (
<article className="border-b border-border px-4 py-3 hover:bg-bg-hover transition-colors duration-100"> <article className="border-b border-border px-4 py-3 hover:bg-bg-hover transition-colors duration-100 group/card">
<div className="flex gap-3"> <div className="flex gap-3">
{/* Avatar */} {/* Avatar */}
<div className="shrink-0 cursor-pointer" onClick={() => openProfile(event.pubkey)}> <div className="shrink-0 cursor-pointer" onClick={() => openProfile(event.pubkey)}>
@@ -112,6 +116,30 @@ export function NoteCard({ event }: NoteCardProps) {
<span className="text-text-dim text-[10px] truncate max-w-40">{nip05}</span> <span className="text-text-dim text-[10px] truncate max-w-40">{nip05}</span>
)} )}
<span className="text-text-dim text-[11px] shrink-0">{time}</span> <span className="text-text-dim text-[11px] shrink-0">{time}</span>
{/* Context menu — hidden until card hover, not shown for own notes */}
{loggedIn && event.pubkey !== ownPubkey && (
<div className="relative ml-auto">
<button
onClick={() => setMenuOpen((v) => !v)}
className="text-text-dim hover:text-text text-[14px] px-1 leading-none opacity-0 group-hover/card:opacity-100 transition-opacity"
>
</button>
{menuOpen && (
<>
<div className="fixed inset-0 z-[9]" onClick={() => setMenuOpen(false)} />
<div className="absolute right-0 top-5 bg-bg-raised border border-border shadow-lg z-10 w-32">
<button
onClick={() => { setMenuOpen(false); isMuted ? unmute(event.pubkey) : mute(event.pubkey); }}
className="w-full text-left px-3 py-2 text-[11px] text-text-muted hover:text-danger hover:bg-bg-hover transition-colors"
>
{isMuted ? `unmute` : `mute`}
</button>
</div>
</>
)}
</div>
)}
</div> </div>
<div <div

View File

@@ -2,6 +2,7 @@ import { useEffect, useState } from "react";
import { NDKEvent } from "@nostr-dev-kit/ndk"; import { NDKEvent } from "@nostr-dev-kit/ndk";
import { useUIStore } from "../../stores/ui"; import { useUIStore } from "../../stores/ui";
import { useUserStore } from "../../stores/user"; import { useUserStore } from "../../stores/user";
import { useMuteStore } from "../../stores/mute";
import { useProfile, invalidateProfileCache } from "../../hooks/useProfile"; import { useProfile, invalidateProfileCache } from "../../hooks/useProfile";
import { fetchUserNotes, publishProfile } from "../../lib/nostr"; import { fetchUserNotes, publishProfile } from "../../lib/nostr";
import { shortenPubkey } from "../../lib/utils"; import { shortenPubkey } from "../../lib/utils";
@@ -116,6 +117,8 @@ export function ProfileView() {
const [showZap, setShowZap] = useState(false); const [showZap, setShowZap] = useState(false);
const isFollowing = follows.includes(pubkey); const isFollowing = follows.includes(pubkey);
const { mutedPubkeys, mute, unmute } = useMuteStore();
const isMuted = mutedPubkeys.includes(pubkey);
const handleFollowToggle = async () => { const handleFollowToggle = async () => {
setFollowPending(true); setFollowPending(true);
@@ -185,6 +188,16 @@ export function ProfileView() {
> >
{followPending ? "…" : isFollowing ? "unfollow" : "follow"} {followPending ? "…" : isFollowing ? "unfollow" : "follow"}
</button> </button>
<button
onClick={() => isMuted ? unmute(pubkey) : mute(pubkey)}
className={`text-[11px] px-3 py-1 border transition-colors ${
isMuted
? "border-danger/40 text-danger hover:bg-danger/5"
: "border-border text-text-dim hover:text-danger hover:border-danger/40"
}`}
>
{isMuted ? "unmute" : "mute"}
</button>
</div> </div>
)} )}
</header> </header>

View File

@@ -1,8 +1,46 @@
import { useState } from "react"; import { useState } from "react";
import { useUserStore } from "../../stores/user"; import { useUserStore } from "../../stores/user";
import { useLightningStore } from "../../stores/lightning"; import { useLightningStore } from "../../stores/lightning";
import { useMuteStore } from "../../stores/mute";
import { isValidNwcUri } from "../../lib/lightning/nwc"; import { isValidNwcUri } from "../../lib/lightning/nwc";
import { getNDK, getStoredRelayUrls, addRelay, removeRelay } from "../../lib/nostr"; import { getNDK, getStoredRelayUrls, addRelay, removeRelay } from "../../lib/nostr";
import { useProfile } from "../../hooks/useProfile";
function MutedRow({ pubkey, onUnmute }: { pubkey: string; onUnmute: () => void }) {
const profile = useProfile(pubkey);
const name = profile?.displayName || profile?.name || pubkey.slice(0, 12) + "…";
return (
<div className="flex items-center gap-3 px-3 py-2 border border-border text-[12px] group">
{profile?.picture && (
<img src={profile.picture} alt="" className="w-5 h-5 rounded-sm object-cover shrink-0" />
)}
<span className="text-text truncate flex-1">{name}</span>
<button
onClick={onUnmute}
className="text-text-dim hover:text-accent text-[10px] opacity-0 group-hover:opacity-100 transition-opacity shrink-0"
>
unmute
</button>
</div>
);
}
function MuteSection() {
const { mutedPubkeys, unmute } = useMuteStore();
if (mutedPubkeys.length === 0) return null;
return (
<section>
<h2 className="text-text text-[11px] font-medium uppercase tracking-widest mb-2 text-text-dim">
Muted accounts ({mutedPubkeys.length})
</h2>
<div className="space-y-1">
{mutedPubkeys.map((pk) => (
<MutedRow key={pk} pubkey={pk} onUnmute={() => unmute(pk)} />
))}
</div>
</section>
);
}
function RelayRow({ url, onRemove }: { url: string; onRemove: () => void }) { function RelayRow({ url, onRemove }: { url: string; onRemove: () => void }) {
const ndk = getNDK(); const ndk = getNDK();
@@ -203,6 +241,7 @@ export function SettingsView() {
<WalletSection /> <WalletSection />
<RelaySection /> <RelaySection />
<IdentitySection /> <IdentitySection />
<MuteSection />
</div> </div>
</div> </div>
); );

View File

@@ -274,6 +274,27 @@ export async function publishContactList(pubkeys: string[]): Promise<void> {
await event.publish(); await event.publish();
} }
export async function fetchMuteList(pubkey: string): Promise<string[]> {
const instance = getNDK();
const filter: NDKFilter = { kinds: [10000 as NDKKind], authors: [pubkey], limit: 1 };
const events = await instance.fetchEvents(filter, {
cacheUsage: NDKSubscriptionCacheUsage.ONLY_RELAY,
});
if (events.size === 0) return [];
const event = Array.from(events).sort((a, b) => (b.created_at ?? 0) - (a.created_at ?? 0))[0];
return event.tags.filter((t) => t[0] === "p" && t[1]).map((t) => t[1]);
}
export async function publishMuteList(pubkeys: string[]): Promise<void> {
const instance = getNDK();
if (!instance.signer) return;
const event = new NDKEvent(instance);
event.kind = 10000 as NDKKind;
event.content = "";
event.tags = pubkeys.map((pk) => ["p", pk]);
await event.publish();
}
export async function fetchProfile(pubkey: string) { export async function fetchProfile(pubkey: string) {
const instance = getNDK(); const instance = getNDK();
const user = instance.getUser({ pubkey }); const user = instance.getUser({ pubkey });

View File

@@ -1 +1 @@
export { getNDK, connectToRelays, fetchGlobalFeed, fetchFollowFeed, fetchReplies, publishNote, publishArticle, publishProfile, publishReaction, publishReply, publishContactList, fetchReactionCount, fetchUserNotes, fetchProfile, getStoredRelayUrls, addRelay, removeRelay, searchNotes, searchUsers } from "./client"; export { getNDK, connectToRelays, fetchGlobalFeed, fetchFollowFeed, fetchReplies, publishNote, publishArticle, publishProfile, publishReaction, publishReply, publishContactList, fetchReactionCount, fetchUserNotes, fetchProfile, fetchMuteList, publishMuteList, getStoredRelayUrls, addRelay, removeRelay, searchNotes, searchUsers } from "./client";

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