mirror of
https://github.com/hoornet/vega.git
synced 2026-05-14 00:58:36 -07:00
Add NIP-05 badges, hashtag pages, keyword muting, suggestion dismissal, notification poller
- Article cover: aspect-video replaces max-h-72 for consistent 16:9 - NIP-05 verification badge on note cards with 1-hour TTL cache - Dedicated hashtag feed pages (clicking #tag opens live feed, not search) - Keyword muting: word-boundary matching, applied across all feed views - Follow suggestion dismissal: persistent "don't suggest again" per person - Background notification poller (60s): mentions, zaps, new followers - All notification types independently toggleable in settings - Centralized notification firing (removed inline store notifications)
This commit is contained in:
@@ -15,6 +15,7 @@ import { ZapHistoryView } from "./components/zap/ZapHistoryView";
|
|||||||
import { DMView } from "./components/dm/DMView";
|
import { DMView } from "./components/dm/DMView";
|
||||||
import { NotificationsView } from "./components/notifications/NotificationsView";
|
import { NotificationsView } from "./components/notifications/NotificationsView";
|
||||||
import { BookmarkView } from "./components/bookmark/BookmarkView";
|
import { BookmarkView } from "./components/bookmark/BookmarkView";
|
||||||
|
import { HashtagFeed } from "./components/feed/HashtagFeed";
|
||||||
import { HelpModal } from "./components/shared/HelpModal";
|
import { HelpModal } from "./components/shared/HelpModal";
|
||||||
import { useUIStore } from "./stores/ui";
|
import { useUIStore } from "./stores/ui";
|
||||||
import { useUpdater } from "./hooks/useUpdater";
|
import { useUpdater } from "./hooks/useUpdater";
|
||||||
@@ -79,6 +80,7 @@ function App() {
|
|||||||
{currentView === "dm" && <DMView />}
|
{currentView === "dm" && <DMView />}
|
||||||
{currentView === "notifications" && <NotificationsView />}
|
{currentView === "notifications" && <NotificationsView />}
|
||||||
{currentView === "bookmarks" && <BookmarkView />}
|
{currentView === "bookmarks" && <BookmarkView />}
|
||||||
|
{currentView === "hashtag" && <HashtagFeed />}
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
{showHelp && <HelpModal onClose={toggleHelp} />}
|
{showHelp && <HelpModal onClose={toggleHelp} />}
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ export function ArticleView() {
|
|||||||
<img
|
<img
|
||||||
src={image}
|
src={image}
|
||||||
alt=""
|
alt=""
|
||||||
className="w-full max-h-72 object-cover rounded-sm"
|
className="w-full aspect-video object-cover rounded-sm"
|
||||||
onError={(e) => { (e.target as HTMLImageElement).style.display = "none"; }}
|
onError={(e) => { (e.target as HTMLImageElement).style.display = "none"; }}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { NDKEvent } from "@nostr-dev-kit/ndk";
|
|||||||
export function Feed() {
|
export function Feed() {
|
||||||
const { notes, loading, connected, error, connect, loadCachedFeed, loadFeed, trendingNotes, trendingLoading, loadTrendingFeed, focusedNoteIndex } = useFeedStore();
|
const { notes, loading, connected, error, connect, loadCachedFeed, loadFeed, trendingNotes, trendingLoading, loadTrendingFeed, focusedNoteIndex } = useFeedStore();
|
||||||
const { loggedIn, follows } = useUserStore();
|
const { loggedIn, follows } = useUserStore();
|
||||||
const { mutedPubkeys } = useMuteStore();
|
const { mutedPubkeys, contentMatchesMutedKeyword } = useMuteStore();
|
||||||
const { feedTab: tab, setFeedTab: setTab, feedLanguageFilter, setFeedLanguageFilter } = useUIStore();
|
const { feedTab: tab, setFeedTab: setTab, feedLanguageFilter, setFeedLanguageFilter } = useUIStore();
|
||||||
const [followNotes, setFollowNotes] = useState<NDKEvent[]>([]);
|
const [followNotes, setFollowNotes] = useState<NDKEvent[]>([]);
|
||||||
const [followLoading, setFollowLoading] = useState(false);
|
const [followLoading, setFollowLoading] = useState(false);
|
||||||
@@ -51,6 +51,7 @@ export function Feed() {
|
|||||||
|
|
||||||
const filteredNotes = activeNotes.filter((event) => {
|
const filteredNotes = activeNotes.filter((event) => {
|
||||||
if (mutedPubkeys.includes(event.pubkey)) return false;
|
if (mutedPubkeys.includes(event.pubkey)) return false;
|
||||||
|
if (contentMatchesMutedKeyword(event.content)) 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
|
||||||
|
|||||||
50
src/components/feed/HashtagFeed.tsx
Normal file
50
src/components/feed/HashtagFeed.tsx
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { NDKEvent } from "@nostr-dev-kit/ndk";
|
||||||
|
import { useUIStore } from "../../stores/ui";
|
||||||
|
import { fetchHashtagFeed } from "../../lib/nostr";
|
||||||
|
import { NoteCard } from "./NoteCard";
|
||||||
|
|
||||||
|
export function HashtagFeed() {
|
||||||
|
const { pendingHashtag, goBack } = useUIStore();
|
||||||
|
const tag = pendingHashtag ?? "";
|
||||||
|
|
||||||
|
const [notes, setNotes] = useState<NDKEvent[]>([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!tag) return;
|
||||||
|
setLoading(true);
|
||||||
|
setNotes([]);
|
||||||
|
fetchHashtagFeed(tag)
|
||||||
|
.then(setNotes)
|
||||||
|
.finally(() => setLoading(false));
|
||||||
|
}, [tag]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="h-full flex flex-col">
|
||||||
|
<header className="border-b border-border px-4 py-2.5 flex items-center gap-3 shrink-0">
|
||||||
|
<button onClick={goBack} className="text-text-dim hover:text-text text-[11px] transition-colors">
|
||||||
|
← back
|
||||||
|
</button>
|
||||||
|
<h2 className="text-text text-[14px] font-medium">#{tag}</h2>
|
||||||
|
{!loading && (
|
||||||
|
<span className="text-text-dim text-[11px]">{notes.length} note{notes.length !== 1 ? "s" : ""}</span>
|
||||||
|
)}
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div className="flex-1 overflow-y-auto">
|
||||||
|
{loading && (
|
||||||
|
<div className="px-4 py-8 text-text-dim text-[12px] text-center">Loading notes for #{tag}…</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!loading && notes.length === 0 && (
|
||||||
|
<div className="px-4 py-8 text-text-dim text-[12px] text-center">No notes found for #{tag}</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{notes.map((event) => (
|
||||||
|
<NoteCard key={event.id} event={event} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useState, useRef, useEffect } from "react";
|
import { useState, useRef, useEffect } from "react";
|
||||||
import { NDKEvent } from "@nostr-dev-kit/ndk";
|
import { NDKEvent } from "@nostr-dev-kit/ndk";
|
||||||
import { useProfile } from "../../hooks/useProfile";
|
import { useProfile } from "../../hooks/useProfile";
|
||||||
|
import { useNip05Verified } from "../../hooks/useNip05Verified";
|
||||||
import { useReactionCount } from "../../hooks/useReactionCount";
|
import { useReactionCount } from "../../hooks/useReactionCount";
|
||||||
import { useReplyCount } from "../../hooks/useReplyCount";
|
import { useReplyCount } from "../../hooks/useReplyCount";
|
||||||
import { useZapCount } from "../../hooks/useZapCount";
|
import { useZapCount } from "../../hooks/useZapCount";
|
||||||
@@ -39,6 +40,7 @@ export function NoteCard({ event, focused }: NoteCardProps) {
|
|||||||
const name = profile?.displayName || profile?.name || shortenPubkey(event.pubkey);
|
const name = profile?.displayName || profile?.name || shortenPubkey(event.pubkey);
|
||||||
const avatar = profile?.picture;
|
const avatar = profile?.picture;
|
||||||
const nip05 = profile?.nip05;
|
const nip05 = profile?.nip05;
|
||||||
|
const verified = useNip05Verified(event.pubkey, nip05);
|
||||||
const time = event.created_at ? timeAgo(event.created_at) : "";
|
const time = event.created_at ? timeAgo(event.created_at) : "";
|
||||||
|
|
||||||
const { loggedIn, pubkey: ownPubkey, follows, follow, unfollow } = useUserStore();
|
const { loggedIn, pubkey: ownPubkey, follows, follow, unfollow } = useUserStore();
|
||||||
@@ -175,7 +177,9 @@ export function NoteCard({ event, focused }: NoteCardProps) {
|
|||||||
onClick={() => openProfile(event.pubkey)}
|
onClick={() => openProfile(event.pubkey)}
|
||||||
>{name}</span>
|
>{name}</span>
|
||||||
{nip05 && (
|
{nip05 && (
|
||||||
<span className="text-text-dim text-[10px] truncate max-w-40">{nip05}</span>
|
<span className={`text-[10px] truncate max-w-40 ${verified === "valid" ? "text-success" : "text-text-dim"}`}>
|
||||||
|
{verified === "valid" ? "✓ " : ""}{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 */}
|
{/* Context menu — hidden until card hover, not shown for own notes */}
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ interface NoteContentProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function NoteContent({ content, inline, mediaOnly }: NoteContentProps) {
|
export function NoteContent({ content, inline, mediaOnly }: NoteContentProps) {
|
||||||
const { openSearch } = useUIStore();
|
const { openHashtag } = useUIStore();
|
||||||
const segments = parseContent(content);
|
const segments = parseContent(content);
|
||||||
const images: string[] = segments.filter((s) => s.type === "image").map((s) => s.value);
|
const images: string[] = segments.filter((s) => s.type === "image").map((s) => s.value);
|
||||||
const videos: string[] = segments.filter((s) => s.type === "video").map((s) => s.value);
|
const videos: string[] = segments.filter((s) => s.type === "video").map((s) => s.value);
|
||||||
@@ -246,7 +246,7 @@ export function NoteContent({ content, inline, mediaOnly }: NoteContentProps) {
|
|||||||
<span
|
<span
|
||||||
key={i}
|
key={i}
|
||||||
className="text-accent/80 cursor-pointer hover:text-accent"
|
className="text-accent/80 cursor-pointer hover:text-accent"
|
||||||
onClick={(e) => { e.stopPropagation(); openSearch(`#${seg.value}`); }}
|
onClick={(e) => { e.stopPropagation(); openHashtag(seg.value); }}
|
||||||
>
|
>
|
||||||
{seg.display}
|
{seg.display}
|
||||||
</span>
|
</span>
|
||||||
@@ -441,7 +441,7 @@ export function NoteContent({ content, inline, mediaOnly }: NoteContentProps) {
|
|||||||
<span
|
<span
|
||||||
key={i}
|
key={i}
|
||||||
className="text-accent/80 cursor-pointer hover:text-accent"
|
className="text-accent/80 cursor-pointer hover:text-accent"
|
||||||
onClick={(e) => { e.stopPropagation(); openSearch(`#${seg.value}`); }}
|
onClick={(e) => { e.stopPropagation(); openHashtag(seg.value); }}
|
||||||
>
|
>
|
||||||
{seg.display}
|
{seg.display}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import { useUserStore } from "../../stores/user";
|
import { useUserStore } from "../../stores/user";
|
||||||
|
import { useMuteStore } from "../../stores/mute";
|
||||||
import { useNotificationsStore } from "../../stores/notifications";
|
import { useNotificationsStore } from "../../stores/notifications";
|
||||||
import { NoteCard } from "../feed/NoteCard";
|
import { NoteCard } from "../feed/NoteCard";
|
||||||
import { SkeletonNoteList } from "../shared/Skeleton";
|
import { SkeletonNoteList } from "../shared/Skeleton";
|
||||||
@@ -14,6 +15,10 @@ export function NotificationsView() {
|
|||||||
fetchNotifications,
|
fetchNotifications,
|
||||||
markAllRead,
|
markAllRead,
|
||||||
} = useNotificationsStore();
|
} = useNotificationsStore();
|
||||||
|
const { mutedPubkeys, contentMatchesMutedKeyword } = useMuteStore();
|
||||||
|
const filteredNotifications = notifications.filter(
|
||||||
|
(e) => !mutedPubkeys.includes(e.pubkey) && !contentMatchesMutedKeyword(e.content)
|
||||||
|
);
|
||||||
|
|
||||||
// Capture lastSeenAt at mount time so unread highlights persist during this view session
|
// Capture lastSeenAt at mount time so unread highlights persist during this view session
|
||||||
const prevLastSeenAtRef = useRef(lastSeenAt);
|
const prevLastSeenAtRef = useRef(lastSeenAt);
|
||||||
@@ -52,14 +57,14 @@ export function NotificationsView() {
|
|||||||
<SkeletonNoteList count={4} />
|
<SkeletonNoteList count={4} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!loading && notifications.length === 0 && (
|
{!loading && filteredNotifications.length === 0 && (
|
||||||
<div className="px-4 py-12 text-center space-y-2">
|
<div className="px-4 py-12 text-center space-y-2">
|
||||||
<p className="text-text-dim text-[13px]">No mentions yet.</p>
|
<p className="text-text-dim text-[13px]">No mentions yet.</p>
|
||||||
<p className="text-text-dim text-[11px] opacity-60">When someone mentions you, it will appear here.</p>
|
<p className="text-text-dim text-[11px] opacity-60">When someone mentions you, it will appear here.</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{notifications.map((event) => {
|
{filteredNotifications.map((event) => {
|
||||||
const isUnread = (event.created_at ?? 0) > prevLastSeenAtRef.current;
|
const isUnread = (event.created_at ?? 0) > prevLastSeenAtRef.current;
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import { getStoredRelayUrls, fetchFollowSuggestions, fetchProfile, advancedSearc
|
|||||||
import { parseSearchQuery, describeSearch } from "../../lib/search";
|
import { parseSearchQuery, describeSearch } from "../../lib/search";
|
||||||
import { getNip50Relays } from "../../lib/nostr/relayInfo";
|
import { getNip50Relays } from "../../lib/nostr/relayInfo";
|
||||||
import { useUserStore } from "../../stores/user";
|
import { useUserStore } from "../../stores/user";
|
||||||
|
import { useMuteStore } from "../../stores/mute";
|
||||||
|
import { useDismissedSuggestionsStore } from "../../stores/dismissedSuggestions";
|
||||||
import { useUIStore } from "../../stores/ui";
|
import { useUIStore } from "../../stores/ui";
|
||||||
import { shortenPubkey } from "../../lib/utils";
|
import { shortenPubkey } from "../../lib/utils";
|
||||||
import { NoteCard } from "../feed/NoteCard";
|
import { NoteCard } from "../feed/NoteCard";
|
||||||
@@ -159,6 +161,12 @@ export function SearchView() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const { loggedIn, follows } = useUserStore();
|
const { loggedIn, follows } = useUserStore();
|
||||||
|
const { mutedPubkeys } = useMuteStore();
|
||||||
|
const { dismissedPubkeys, dismiss } = useDismissedSuggestionsStore();
|
||||||
|
|
||||||
|
const visibleSuggestions = suggestions.filter(
|
||||||
|
(s) => !dismissedPubkeys.includes(s.pubkey) && !mutedPubkeys.includes(s.pubkey) && !follows.includes(s.pubkey)
|
||||||
|
);
|
||||||
|
|
||||||
// Load follow suggestions on mount (only for logged-in users with follows)
|
// Load follow suggestions on mount (only for logged-in users with follows)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -384,8 +392,8 @@ export function SearchView() {
|
|||||||
{suggestionsLoading && (
|
{suggestionsLoading && (
|
||||||
<div className="px-4 py-6 text-text-dim text-[11px] text-center">Finding suggestions...</div>
|
<div className="px-4 py-6 text-text-dim text-[11px] text-center">Finding suggestions...</div>
|
||||||
)}
|
)}
|
||||||
{suggestions.map((s) => s.profile && (
|
{visibleSuggestions.map((s) => s.profile && (
|
||||||
<div key={s.pubkey} className="flex items-center gap-3 px-4 py-2.5 border-b border-border hover:bg-bg-hover transition-colors">
|
<div key={s.pubkey} className="flex items-center gap-3 px-4 py-2.5 border-b border-border hover:bg-bg-hover transition-colors group/suggestion">
|
||||||
<div className="shrink-0 cursor-pointer" onClick={() => useUIStore.getState().openProfile(s.pubkey)}>
|
<div className="shrink-0 cursor-pointer" onClick={() => useUIStore.getState().openProfile(s.pubkey)}>
|
||||||
{s.profile.picture ? (
|
{s.profile.picture ? (
|
||||||
<img src={s.profile.picture} alt="" className="w-9 h-9 rounded-sm object-cover bg-bg-raised"
|
<img src={s.profile.picture} alt="" className="w-9 h-9 rounded-sm object-cover bg-bg-raised"
|
||||||
@@ -409,9 +417,16 @@ export function SearchView() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<SuggestionFollowButton pubkey={s.pubkey} />
|
<SuggestionFollowButton pubkey={s.pubkey} />
|
||||||
|
<button
|
||||||
|
onClick={() => dismiss(s.pubkey)}
|
||||||
|
className="text-text-dim hover:text-danger text-[14px] opacity-0 group-hover/suggestion:opacity-100 transition-opacity shrink-0 px-1"
|
||||||
|
title="Don't suggest again"
|
||||||
|
>
|
||||||
|
×
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
{suggestionsLoaded && suggestions.length === 0 && (
|
{suggestionsLoaded && visibleSuggestions.length === 0 && (
|
||||||
<div className="px-4 py-6 text-text-dim text-[11px] text-center">
|
<div className="px-4 py-6 text-text-dim text-[11px] text-center">
|
||||||
Follow more people to see suggestions here.
|
Follow more people to see suggestions here.
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -45,6 +45,74 @@ function MuteSection() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function MutedKeywordsSection() {
|
||||||
|
const { mutedKeywords, addKeyword, removeKeyword } = useMuteStore();
|
||||||
|
const [input, setInput] = useState("");
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const handleAdd = () => {
|
||||||
|
const trimmed = input.trim().toLowerCase();
|
||||||
|
if (trimmed.length < 2) {
|
||||||
|
setError("Minimum 2 characters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (mutedKeywords.includes(trimmed)) {
|
||||||
|
setError("Already muted");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
addKeyword(trimmed);
|
||||||
|
setInput("");
|
||||||
|
setError(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleKeyDown = (e: React.KeyboardEvent) => {
|
||||||
|
if (e.key === "Enter") handleAdd();
|
||||||
|
if (e.key === "Escape") setInput("");
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section>
|
||||||
|
<h2 className="text-text text-[11px] font-medium uppercase tracking-widest mb-2 text-text-dim">
|
||||||
|
Muted keywords {mutedKeywords.length > 0 && `(${mutedKeywords.length})`}
|
||||||
|
</h2>
|
||||||
|
<p className="text-text-dim text-[11px] mb-3">
|
||||||
|
Notes containing these words or phrases will be hidden from your feeds.
|
||||||
|
</p>
|
||||||
|
{mutedKeywords.length > 0 && (
|
||||||
|
<div className="space-y-1 mb-3">
|
||||||
|
{mutedKeywords.map((kw) => (
|
||||||
|
<div key={kw} className="flex items-center gap-3 px-3 py-2 border border-border text-[12px] group">
|
||||||
|
<span className="text-text truncate flex-1">{kw}</span>
|
||||||
|
<button
|
||||||
|
onClick={() => removeKeyword(kw)}
|
||||||
|
className="text-text-dim hover:text-danger text-[10px] opacity-0 group-hover:opacity-100 transition-opacity shrink-0"
|
||||||
|
>
|
||||||
|
remove
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<input
|
||||||
|
value={input}
|
||||||
|
onChange={(e) => { setInput(e.target.value); setError(null); }}
|
||||||
|
onKeyDown={handleKeyDown}
|
||||||
|
placeholder="word or phrase to mute"
|
||||||
|
className="flex-1 bg-bg border border-border px-3 py-1.5 text-text text-[12px] focus:outline-none focus:border-accent/50 placeholder:text-text-dim"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
onClick={handleAdd}
|
||||||
|
className="px-3 py-1.5 text-[11px] border border-border text-text-muted hover:text-accent hover:border-accent/40 transition-colors shrink-0"
|
||||||
|
>
|
||||||
|
add
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{error && <p className="text-danger text-[11px] mt-1">{error}</p>}
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function RelayRow({ url, onRemove }: { url: string; onRemove: () => void }) {
|
function RelayRow({ url, onRemove }: { url: string; onRemove: () => void }) {
|
||||||
const ndk = getNDK();
|
const ndk = getNDK();
|
||||||
const relay = ndk.pool?.relays.get(url);
|
const relay = ndk.pool?.relays.get(url);
|
||||||
@@ -267,7 +335,7 @@ function ExportSection() {
|
|||||||
function NotificationSection() {
|
function NotificationSection() {
|
||||||
const [settings, setSettings] = useState(getNotificationSettings);
|
const [settings, setSettings] = useState(getNotificationSettings);
|
||||||
|
|
||||||
const toggle = (key: "mentions" | "dms" | "zaps") => {
|
const toggle = (key: "mentions" | "dms" | "zaps" | "followers") => {
|
||||||
const next = { ...settings, [key]: !settings[key] };
|
const next = { ...settings, [key]: !settings[key] };
|
||||||
setSettings(next);
|
setSettings(next);
|
||||||
saveNotificationSettings(next);
|
saveNotificationSettings(next);
|
||||||
@@ -275,10 +343,11 @@ function NotificationSection() {
|
|||||||
if (next[key]) ensurePermission().catch(() => {});
|
if (next[key]) ensurePermission().catch(() => {});
|
||||||
};
|
};
|
||||||
|
|
||||||
const items: Array<{ key: "mentions" | "dms" | "zaps"; label: string }> = [
|
const items: Array<{ key: "mentions" | "dms" | "zaps" | "followers"; label: string }> = [
|
||||||
{ key: "mentions", label: "Mentions" },
|
{ key: "mentions", label: "Mentions" },
|
||||||
{ key: "dms", label: "Direct messages" },
|
{ key: "dms", label: "Direct messages" },
|
||||||
{ key: "zaps", label: "Zaps received" },
|
{ key: "zaps", label: "Zaps received" },
|
||||||
|
{ key: "followers", label: "New followers" },
|
||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -326,6 +395,7 @@ export function SettingsView() {
|
|||||||
<ExportSection />
|
<ExportSection />
|
||||||
<IdentitySection />
|
<IdentitySection />
|
||||||
<MuteSection />
|
<MuteSection />
|
||||||
|
<MutedKeywordsSection />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useEffect, useRef, 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 } from "../../hooks/useProfile";
|
import { useProfile } from "../../hooks/useProfile";
|
||||||
import { useReactionCount } from "../../hooks/useReactionCount";
|
import { useReactionCount } from "../../hooks/useReactionCount";
|
||||||
import { useZapCount } from "../../hooks/useZapCount";
|
import { useZapCount } from "../../hooks/useZapCount";
|
||||||
@@ -145,6 +146,7 @@ function RootNote({ event }: { event: NDKEvent }) {
|
|||||||
export function ThreadView() {
|
export function ThreadView() {
|
||||||
const { selectedNote, goBack } = useUIStore();
|
const { selectedNote, goBack } = useUIStore();
|
||||||
const { loggedIn } = useUserStore();
|
const { loggedIn } = useUserStore();
|
||||||
|
const { mutedPubkeys, contentMatchesMutedKeyword } = useMuteStore();
|
||||||
if (!selectedNote) { goBack(); return null; }
|
if (!selectedNote) { goBack(); return null; }
|
||||||
const event = selectedNote;
|
const event = selectedNote;
|
||||||
|
|
||||||
@@ -239,7 +241,9 @@ export function ThreadView() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{replies.map((reply) => (
|
{replies
|
||||||
|
.filter((r) => !mutedPubkeys.includes(r.pubkey) && !contentMatchesMutedKeyword(r.content))
|
||||||
|
.map((reply) => (
|
||||||
<NoteCard key={reply.id} event={reply} />
|
<NoteCard key={reply.id} event={reply} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
51
src/hooks/useNip05Verified.ts
Normal file
51
src/hooks/useNip05Verified.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { useState, useEffect } from "react";
|
||||||
|
|
||||||
|
type VerifyStatus = "valid" | "invalid";
|
||||||
|
|
||||||
|
const cache = new Map<string, { status: VerifyStatus; checkedAt: number }>();
|
||||||
|
const TTL = 3600000; // 1 hour
|
||||||
|
|
||||||
|
async function verifyNip05(pubkey: string, nip05: string): Promise<VerifyStatus> {
|
||||||
|
const parts = nip05.split("@");
|
||||||
|
if (parts.length !== 2) return "invalid";
|
||||||
|
const [name, domain] = parts;
|
||||||
|
try {
|
||||||
|
const res = await fetch(`https://${domain}/.well-known/nostr.json?name=${encodeURIComponent(name)}`);
|
||||||
|
if (!res.ok) return "invalid";
|
||||||
|
const json = await res.json();
|
||||||
|
const resolved = json?.names?.[name];
|
||||||
|
return resolved === pubkey ? "valid" : "invalid";
|
||||||
|
} catch {
|
||||||
|
return "invalid";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useNip05Verified(pubkey: string, nip05: string | undefined): "valid" | "invalid" | "checking" | null {
|
||||||
|
const [status, setStatus] = useState<"valid" | "invalid" | "checking" | null>(() => {
|
||||||
|
if (!nip05) return null;
|
||||||
|
const cached = cache.get(pubkey);
|
||||||
|
if (cached && Date.now() - cached.checkedAt < TTL) return cached.status;
|
||||||
|
return "checking";
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!nip05) { setStatus(null); return; }
|
||||||
|
|
||||||
|
const cached = cache.get(pubkey);
|
||||||
|
if (cached && Date.now() - cached.checkedAt < TTL) {
|
||||||
|
setStatus(cached.status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let cancelled = false;
|
||||||
|
setStatus("checking");
|
||||||
|
verifyNip05(pubkey, nip05).then((result) => {
|
||||||
|
if (cancelled) return;
|
||||||
|
cache.set(pubkey, { status: result, checkedAt: Date.now() });
|
||||||
|
setStatus(result);
|
||||||
|
});
|
||||||
|
return () => { cancelled = true; };
|
||||||
|
}, [pubkey, nip05]);
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
@@ -867,6 +867,37 @@ export async function fetchTrendingHashtags(limit = 15): Promise<{ tag: string;
|
|||||||
.slice(0, limit);
|
.slice(0, limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── New Followers ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export async function fetchNewFollowers(pubkey: string, since: number, limit = 20): Promise<NDKEvent[]> {
|
||||||
|
const instance = getNDK();
|
||||||
|
const filter: NDKFilter = {
|
||||||
|
kinds: [3 as NDKKind],
|
||||||
|
"#p": [pubkey],
|
||||||
|
since,
|
||||||
|
limit,
|
||||||
|
};
|
||||||
|
const events = await instance.fetchEvents(filter, {
|
||||||
|
cacheUsage: NDKSubscriptionCacheUsage.ONLY_RELAY,
|
||||||
|
});
|
||||||
|
return Array.from(events).sort((a, b) => (b.created_at ?? 0) - (a.created_at ?? 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Hashtag Feed ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export async function fetchHashtagFeed(tag: string, limit = 100): Promise<NDKEvent[]> {
|
||||||
|
const instance = getNDK();
|
||||||
|
const filter: NDKFilter = {
|
||||||
|
kinds: [NDKKind.Text],
|
||||||
|
"#t": [tag.toLowerCase()],
|
||||||
|
limit,
|
||||||
|
};
|
||||||
|
const events = await instance.fetchEvents(filter, {
|
||||||
|
cacheUsage: NDKSubscriptionCacheUsage.ONLY_RELAY,
|
||||||
|
});
|
||||||
|
return Array.from(events).sort((a, b) => (b.created_at ?? 0) - (a.created_at ?? 0));
|
||||||
|
}
|
||||||
|
|
||||||
// ── Advanced Search ───────────────────────────────────────────────────────────
|
// ── Advanced Search ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export interface AdvancedSearchResults {
|
export interface AdvancedSearchResults {
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
export { getNDK, connectToRelays, fetchGlobalFeed, fetchFollowFeed, fetchReplies, publishNote, publishArticle, publishProfile, publishReaction, publishRepost, publishQuote, publishReply, publishContactList, fetchBatchEngagement, fetchReactionCount, fetchReplyCount, fetchZapCount, fetchNoteById, fetchUserNotes, fetchProfile, fetchArticle, fetchAuthorArticles, fetchArticleFeed, searchArticles, fetchZapsReceived, fetchZapsSent, fetchDMConversations, fetchDMThread, sendDM, decryptDM, fetchBookmarkList, publishBookmarkList, fetchBookmarkListFull, publishBookmarkListFull, fetchByAddr, fetchMuteList, publishMuteList, getStoredRelayUrls, addRelay, removeRelay, searchNotes, searchUsers, fetchUserRelayList, publishRelayList, fetchUserNotesNIP65, fetchFollowSuggestions, fetchMentions, resolveNip05, advancedSearch, fetchRelayRecommendations, fetchTrendingHashtags } from "./client";
|
export { getNDK, connectToRelays, fetchGlobalFeed, fetchFollowFeed, fetchReplies, publishNote, publishArticle, publishProfile, publishReaction, publishRepost, publishQuote, publishReply, publishContactList, fetchBatchEngagement, fetchReactionCount, fetchReplyCount, fetchZapCount, fetchNoteById, fetchUserNotes, fetchProfile, fetchArticle, fetchAuthorArticles, fetchArticleFeed, searchArticles, fetchZapsReceived, fetchZapsSent, fetchDMConversations, fetchDMThread, sendDM, decryptDM, fetchBookmarkList, publishBookmarkList, fetchBookmarkListFull, publishBookmarkListFull, fetchByAddr, fetchMuteList, publishMuteList, getStoredRelayUrls, addRelay, removeRelay, searchNotes, searchUsers, fetchUserRelayList, publishRelayList, fetchUserNotesNIP65, fetchFollowSuggestions, fetchMentions, resolveNip05, advancedSearch, fetchRelayRecommendations, fetchTrendingHashtags, fetchHashtagFeed, fetchNewFollowers } from "./client";
|
||||||
export type { UserRelayList, AdvancedSearchResults } from "./client";
|
export type { UserRelayList, AdvancedSearchResults } from "./client";
|
||||||
|
|||||||
121
src/lib/notificationPoller.ts
Normal file
121
src/lib/notificationPoller.ts
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
import { fetchMentions, fetchZapsReceived, fetchNewFollowers, fetchProfile } from "./nostr";
|
||||||
|
import { notifyMention, notifyZap, notifyFollower } from "./notifications";
|
||||||
|
import { useNotificationsStore } from "../stores/notifications";
|
||||||
|
|
||||||
|
const POLL_INTERVAL = 60_000; // 60 seconds
|
||||||
|
const POLL_TS_KEY = "wrystr_notif_poll_ts";
|
||||||
|
const MAX_SEEN = 200;
|
||||||
|
|
||||||
|
let intervalId: ReturnType<typeof setInterval> | null = null;
|
||||||
|
const recentlySeen = new Set<string>();
|
||||||
|
|
||||||
|
function loadPollTimestamps(): Record<string, number> {
|
||||||
|
try {
|
||||||
|
return JSON.parse(localStorage.getItem(POLL_TS_KEY) ?? "{}");
|
||||||
|
} catch {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function savePollTimestamps(ts: Record<string, number>) {
|
||||||
|
localStorage.setItem(POLL_TS_KEY, JSON.stringify(ts));
|
||||||
|
}
|
||||||
|
|
||||||
|
function trimSeenSet() {
|
||||||
|
if (recentlySeen.size > MAX_SEEN) {
|
||||||
|
const arr = Array.from(recentlySeen);
|
||||||
|
arr.splice(0, arr.length - MAX_SEEN);
|
||||||
|
recentlySeen.clear();
|
||||||
|
arr.forEach((id) => recentlySeen.add(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getProfileName(pubkey: string): Promise<string> {
|
||||||
|
try {
|
||||||
|
const p = await fetchProfile(pubkey);
|
||||||
|
if (p) {
|
||||||
|
const meta = p as Record<string, string>;
|
||||||
|
return meta.display_name || meta.name || pubkey.slice(0, 8) + "…";
|
||||||
|
}
|
||||||
|
} catch { /* ignore */ }
|
||||||
|
return pubkey.slice(0, 8) + "…";
|
||||||
|
}
|
||||||
|
|
||||||
|
async function pollOnce(pubkey: string) {
|
||||||
|
const ts = loadPollTimestamps();
|
||||||
|
const now = Math.floor(Date.now() / 1000);
|
||||||
|
|
||||||
|
// Mentions
|
||||||
|
try {
|
||||||
|
const mentionsSince = ts.mentions || (now - 300);
|
||||||
|
const mentions = await fetchMentions(pubkey, mentionsSince, 10);
|
||||||
|
for (const e of mentions) {
|
||||||
|
if (recentlySeen.has(e.id!)) continue;
|
||||||
|
if (e.pubkey === pubkey) continue; // don't notify self-mentions
|
||||||
|
recentlySeen.add(e.id!);
|
||||||
|
const name = await getProfileName(e.pubkey);
|
||||||
|
notifyMention(name, e.content?.slice(0, 120) || "mentioned you").catch(() => {});
|
||||||
|
}
|
||||||
|
if (mentions.length > 0) ts.mentions = now;
|
||||||
|
// Also update the notifications store unread count
|
||||||
|
useNotificationsStore.getState().fetchNotifications(pubkey).catch(() => {});
|
||||||
|
} catch { /* non-critical */ }
|
||||||
|
|
||||||
|
// Zaps
|
||||||
|
try {
|
||||||
|
const zapsSince = ts.zaps || (now - 300);
|
||||||
|
const zaps = await fetchZapsReceived(pubkey, 10);
|
||||||
|
for (const e of zaps) {
|
||||||
|
if (recentlySeen.has(e.id!)) continue;
|
||||||
|
if ((e.created_at ?? 0) <= zapsSince) continue;
|
||||||
|
recentlySeen.add(e.id!);
|
||||||
|
// Extract sender and amount from zap receipt
|
||||||
|
const desc = e.tags.find((t) => t[0] === "description")?.[1];
|
||||||
|
let senderName = "Someone";
|
||||||
|
let amount = 0;
|
||||||
|
if (desc) {
|
||||||
|
try {
|
||||||
|
const zapReq = JSON.parse(desc) as { pubkey?: string; tags?: string[][] };
|
||||||
|
if (zapReq.pubkey) senderName = await getProfileName(zapReq.pubkey);
|
||||||
|
const amountTag = zapReq.tags?.find((t) => t[0] === "amount");
|
||||||
|
if (amountTag?.[1]) amount = Math.round(parseInt(amountTag[1]) / 1000);
|
||||||
|
} catch { /* malformed */ }
|
||||||
|
}
|
||||||
|
if (amount > 0) {
|
||||||
|
notifyZap(senderName, amount).catch(() => {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ts.zaps = now;
|
||||||
|
} catch { /* non-critical */ }
|
||||||
|
|
||||||
|
// New followers
|
||||||
|
try {
|
||||||
|
const followersSince = ts.followers || (now - 300);
|
||||||
|
const followers = await fetchNewFollowers(pubkey, followersSince, 5);
|
||||||
|
for (const e of followers) {
|
||||||
|
if (recentlySeen.has(e.id!)) continue;
|
||||||
|
if (e.pubkey === pubkey) continue;
|
||||||
|
recentlySeen.add(e.id!);
|
||||||
|
const name = await getProfileName(e.pubkey);
|
||||||
|
notifyFollower(name).catch(() => {});
|
||||||
|
}
|
||||||
|
if (followers.length > 0) ts.followers = now;
|
||||||
|
} catch { /* non-critical */ }
|
||||||
|
|
||||||
|
trimSeenSet();
|
||||||
|
savePollTimestamps(ts);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function startNotificationPoller(pubkey: string) {
|
||||||
|
stopNotificationPoller();
|
||||||
|
// Run first poll after a short delay (let relays connect)
|
||||||
|
setTimeout(() => pollOnce(pubkey).catch(() => {}), 5000);
|
||||||
|
intervalId = setInterval(() => pollOnce(pubkey).catch(() => {}), POLL_INTERVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function stopNotificationPoller() {
|
||||||
|
if (intervalId !== null) {
|
||||||
|
clearInterval(intervalId);
|
||||||
|
intervalId = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,9 +10,10 @@ interface NotificationSettings {
|
|||||||
mentions: boolean;
|
mentions: boolean;
|
||||||
dms: boolean;
|
dms: boolean;
|
||||||
zaps: boolean;
|
zaps: boolean;
|
||||||
|
followers: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaults: NotificationSettings = { mentions: true, dms: true, zaps: true };
|
const defaults: NotificationSettings = { mentions: true, dms: true, zaps: true, followers: true };
|
||||||
|
|
||||||
export function getNotificationSettings(): NotificationSettings {
|
export function getNotificationSettings(): NotificationSettings {
|
||||||
try {
|
try {
|
||||||
@@ -65,3 +66,13 @@ export async function notifyZap(senderName: string, amount: number): Promise<voi
|
|||||||
body: `${amount.toLocaleString()} sats`,
|
body: `${amount.toLocaleString()} sats`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function notifyFollower(followerName: string): Promise<void> {
|
||||||
|
const settings = getNotificationSettings();
|
||||||
|
if (!settings.followers) return;
|
||||||
|
if (!(await ensurePermission())) return;
|
||||||
|
sendNotification({
|
||||||
|
title: `${followerName} followed you`,
|
||||||
|
body: "You have a new follower",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
50
src/stores/dismissedSuggestions.ts
Normal file
50
src/stores/dismissedSuggestions.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import { create } from "zustand";
|
||||||
|
|
||||||
|
const STORAGE_KEY = "wrystr_dismissed_suggestions";
|
||||||
|
|
||||||
|
function loadDismissed(): string[] {
|
||||||
|
try {
|
||||||
|
return JSON.parse(localStorage.getItem(STORAGE_KEY) ?? "[]");
|
||||||
|
} catch {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveDismissed(pubkeys: string[]) {
|
||||||
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(pubkeys));
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DismissedSuggestionsState {
|
||||||
|
dismissedPubkeys: string[];
|
||||||
|
dismiss: (pubkey: string) => void;
|
||||||
|
undismiss: (pubkey: string) => void;
|
||||||
|
isDismissed: (pubkey: string) => boolean;
|
||||||
|
clearAll: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useDismissedSuggestionsStore = create<DismissedSuggestionsState>((set, get) => ({
|
||||||
|
dismissedPubkeys: loadDismissed(),
|
||||||
|
|
||||||
|
dismiss: (pubkey: string) => {
|
||||||
|
const { dismissedPubkeys } = get();
|
||||||
|
if (dismissedPubkeys.includes(pubkey)) return;
|
||||||
|
const updated = [...dismissedPubkeys, pubkey];
|
||||||
|
set({ dismissedPubkeys: updated });
|
||||||
|
saveDismissed(updated);
|
||||||
|
},
|
||||||
|
|
||||||
|
undismiss: (pubkey: string) => {
|
||||||
|
const updated = get().dismissedPubkeys.filter((p) => p !== pubkey);
|
||||||
|
set({ dismissedPubkeys: updated });
|
||||||
|
saveDismissed(updated);
|
||||||
|
},
|
||||||
|
|
||||||
|
isDismissed: (pubkey: string) => {
|
||||||
|
return get().dismissedPubkeys.includes(pubkey);
|
||||||
|
},
|
||||||
|
|
||||||
|
clearAll: () => {
|
||||||
|
set({ dismissedPubkeys: [] });
|
||||||
|
saveDismissed([]);
|
||||||
|
},
|
||||||
|
}));
|
||||||
@@ -2,6 +2,7 @@ import { create } from "zustand";
|
|||||||
import { fetchMuteList, publishMuteList } from "../lib/nostr";
|
import { fetchMuteList, publishMuteList } from "../lib/nostr";
|
||||||
|
|
||||||
const STORAGE_KEY = "wrystr_mutes";
|
const STORAGE_KEY = "wrystr_mutes";
|
||||||
|
const KEYWORDS_KEY = "wrystr_muted_keywords";
|
||||||
|
|
||||||
function loadLocal(): string[] {
|
function loadLocal(): string[] {
|
||||||
try {
|
try {
|
||||||
@@ -15,21 +16,51 @@ function saveLocal(pubkeys: string[]) {
|
|||||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(pubkeys));
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(pubkeys));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadKeywords(): string[] {
|
||||||
|
try {
|
||||||
|
return JSON.parse(localStorage.getItem(KEYWORDS_KEY) ?? "[]");
|
||||||
|
} catch {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveKeywords(keywords: string[]) {
|
||||||
|
localStorage.setItem(KEYWORDS_KEY, JSON.stringify(keywords));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build word-boundary regexes for single words, substring match for phrases
|
||||||
|
function buildKeywordMatchers(keywords: string[]): Array<(content: string) => boolean> {
|
||||||
|
return keywords.map((kw) => {
|
||||||
|
const lower = kw.toLowerCase();
|
||||||
|
if (/\s/.test(lower)) {
|
||||||
|
// Phrase — substring match
|
||||||
|
return (content: string) => content.toLowerCase().includes(lower);
|
||||||
|
}
|
||||||
|
// Single word — word boundary match
|
||||||
|
const re = new RegExp(`\\b${lower.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`, "i");
|
||||||
|
return (content: string) => re.test(content);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
interface MuteState {
|
interface MuteState {
|
||||||
mutedPubkeys: string[];
|
mutedPubkeys: string[];
|
||||||
|
mutedKeywords: string[];
|
||||||
fetchMuteList: (pubkey: string) => Promise<void>;
|
fetchMuteList: (pubkey: string) => Promise<void>;
|
||||||
mute: (pubkey: string) => Promise<void>;
|
mute: (pubkey: string) => Promise<void>;
|
||||||
unmute: (pubkey: string) => Promise<void>;
|
unmute: (pubkey: string) => Promise<void>;
|
||||||
|
addKeyword: (keyword: string) => void;
|
||||||
|
removeKeyword: (keyword: string) => void;
|
||||||
|
contentMatchesMutedKeyword: (content: string) => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useMuteStore = create<MuteState>((set, get) => ({
|
export const useMuteStore = create<MuteState>((set, get) => ({
|
||||||
mutedPubkeys: loadLocal(),
|
mutedPubkeys: loadLocal(),
|
||||||
|
mutedKeywords: loadKeywords(),
|
||||||
|
|
||||||
fetchMuteList: async (pubkey: string) => {
|
fetchMuteList: async (pubkey: string) => {
|
||||||
try {
|
try {
|
||||||
const pubkeys = await fetchMuteList(pubkey);
|
const pubkeys = await fetchMuteList(pubkey);
|
||||||
if (pubkeys.length === 0) return;
|
if (pubkeys.length === 0) return;
|
||||||
// Merge relay list with any local-only mutes (e.g. from npub sessions)
|
|
||||||
const local = get().mutedPubkeys;
|
const local = get().mutedPubkeys;
|
||||||
const merged = Array.from(new Set([...pubkeys, ...local]));
|
const merged = Array.from(new Set([...pubkeys, ...local]));
|
||||||
set({ mutedPubkeys: merged });
|
set({ mutedPubkeys: merged });
|
||||||
@@ -45,7 +76,7 @@ export const useMuteStore = create<MuteState>((set, get) => ({
|
|||||||
const updated = [...mutedPubkeys, pubkey];
|
const updated = [...mutedPubkeys, pubkey];
|
||||||
set({ mutedPubkeys: updated });
|
set({ mutedPubkeys: updated });
|
||||||
saveLocal(updated);
|
saveLocal(updated);
|
||||||
publishMuteList(updated).catch(() => {}); // best-effort relay publish
|
publishMuteList(updated).catch(() => {});
|
||||||
},
|
},
|
||||||
|
|
||||||
unmute: async (pubkey: string) => {
|
unmute: async (pubkey: string) => {
|
||||||
@@ -54,4 +85,27 @@ export const useMuteStore = create<MuteState>((set, get) => ({
|
|||||||
saveLocal(updated);
|
saveLocal(updated);
|
||||||
publishMuteList(updated).catch(() => {});
|
publishMuteList(updated).catch(() => {});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
addKeyword: (keyword: string) => {
|
||||||
|
const trimmed = keyword.trim().toLowerCase();
|
||||||
|
if (trimmed.length < 2) return;
|
||||||
|
const { mutedKeywords } = get();
|
||||||
|
if (mutedKeywords.includes(trimmed)) return;
|
||||||
|
const updated = [...mutedKeywords, trimmed];
|
||||||
|
set({ mutedKeywords: updated });
|
||||||
|
saveKeywords(updated);
|
||||||
|
},
|
||||||
|
|
||||||
|
removeKeyword: (keyword: string) => {
|
||||||
|
const updated = get().mutedKeywords.filter((k) => k !== keyword);
|
||||||
|
set({ mutedKeywords: updated });
|
||||||
|
saveKeywords(updated);
|
||||||
|
},
|
||||||
|
|
||||||
|
contentMatchesMutedKeyword: (content: string) => {
|
||||||
|
const { mutedKeywords } = get();
|
||||||
|
if (mutedKeywords.length === 0) return false;
|
||||||
|
const matchers = buildKeywordMatchers(mutedKeywords);
|
||||||
|
return matchers.some((match) => match(content));
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import { NDKEvent } from "@nostr-dev-kit/ndk";
|
import { NDKEvent } from "@nostr-dev-kit/ndk";
|
||||||
import { fetchMentions } from "../lib/nostr";
|
import { fetchMentions } from "../lib/nostr";
|
||||||
import { notifyMention, notifyDM } from "../lib/notifications";
|
|
||||||
|
|
||||||
const NOTIF_SEEN_KEY = "wrystr_notif_last_seen";
|
const NOTIF_SEEN_KEY = "wrystr_notif_last_seen";
|
||||||
const DM_SEEN_KEY = "wrystr_dm_last_seen";
|
const DM_SEEN_KEY = "wrystr_dm_last_seen";
|
||||||
@@ -55,14 +54,6 @@ export const useNotificationsStore = create<NotificationsState>((set, get) => ({
|
|||||||
const events = await fetchMentions(pubkey, lastSeenAt);
|
const events = await fetchMentions(pubkey, lastSeenAt);
|
||||||
const newEvents = events.filter((e) => (e.created_at ?? 0) > lastSeenAt);
|
const newEvents = events.filter((e) => (e.created_at ?? 0) > lastSeenAt);
|
||||||
const unreadCount = newEvents.length;
|
const unreadCount = newEvents.length;
|
||||||
// Fire OS notification for new mentions (only truly new ones since last fetch)
|
|
||||||
const prevCount = get().unreadCount;
|
|
||||||
if (unreadCount > prevCount && newEvents.length > 0) {
|
|
||||||
const latest = newEvents[0];
|
|
||||||
const authorName = latest.pubkey.slice(0, 8) + "…";
|
|
||||||
const preview = latest.content?.slice(0, 120) || "mentioned you";
|
|
||||||
notifyMention(authorName, preview).catch(() => {});
|
|
||||||
}
|
|
||||||
set({ notifications: events, unreadCount, lastSeenAt });
|
set({ notifications: events, unreadCount, lastSeenAt });
|
||||||
} catch {
|
} catch {
|
||||||
// Non-critical
|
// Non-critical
|
||||||
@@ -86,17 +77,11 @@ export const useNotificationsStore = create<NotificationsState>((set, get) => ({
|
|||||||
},
|
},
|
||||||
|
|
||||||
computeDMUnread: (conversations: Array<{ partnerPubkey: string; lastAt: number }>) => {
|
computeDMUnread: (conversations: Array<{ partnerPubkey: string; lastAt: number }>) => {
|
||||||
const { dmLastSeen, dmUnreadCount: prevCount } = get();
|
const { dmLastSeen } = get();
|
||||||
const unreadConvos = conversations.filter(
|
const unreadConvos = conversations.filter(
|
||||||
(c) => c.lastAt > (dmLastSeen[c.partnerPubkey] ?? 0)
|
(c) => c.lastAt > (dmLastSeen[c.partnerPubkey] ?? 0)
|
||||||
);
|
);
|
||||||
const dmUnreadCount = unreadConvos.length;
|
const dmUnreadCount = unreadConvos.length;
|
||||||
// Fire OS notification if new unread DMs appeared
|
|
||||||
if (dmUnreadCount > prevCount && unreadConvos.length > 0) {
|
|
||||||
const latest = unreadConvos[0];
|
|
||||||
const name = latest.partnerPubkey.slice(0, 8) + "…";
|
|
||||||
notifyDM(name, "New message").catch(() => {});
|
|
||||||
}
|
|
||||||
set({ dmUnreadCount });
|
set({ dmUnreadCount });
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { create } from "zustand";
|
|||||||
|
|
||||||
import { NDKEvent } from "@nostr-dev-kit/ndk";
|
import { NDKEvent } from "@nostr-dev-kit/ndk";
|
||||||
|
|
||||||
type View = "feed" | "search" | "relays" | "settings" | "profile" | "thread" | "article-editor" | "article" | "articles" | "about" | "zaps" | "dm" | "notifications" | "bookmarks";
|
type View = "feed" | "search" | "relays" | "settings" | "profile" | "thread" | "article-editor" | "article" | "articles" | "about" | "zaps" | "dm" | "notifications" | "bookmarks" | "hashtag";
|
||||||
type FeedTab = "global" | "following" | "trending";
|
type FeedTab = "global" | "following" | "trending";
|
||||||
|
|
||||||
interface UIState {
|
interface UIState {
|
||||||
@@ -16,6 +16,7 @@ interface UIState {
|
|||||||
pendingDMPubkey: string | null;
|
pendingDMPubkey: string | null;
|
||||||
pendingArticleNaddr: string | null;
|
pendingArticleNaddr: string | null;
|
||||||
pendingArticleEvent: NDKEvent | null;
|
pendingArticleEvent: NDKEvent | null;
|
||||||
|
pendingHashtag: string | null;
|
||||||
showHelp: boolean;
|
showHelp: boolean;
|
||||||
feedLanguageFilter: string | null;
|
feedLanguageFilter: string | null;
|
||||||
setView: (view: View) => void;
|
setView: (view: View) => void;
|
||||||
@@ -23,6 +24,7 @@ interface UIState {
|
|||||||
openProfile: (pubkey: string) => void;
|
openProfile: (pubkey: string) => void;
|
||||||
openThread: (note: NDKEvent, from: View) => void;
|
openThread: (note: NDKEvent, from: View) => void;
|
||||||
openSearch: (query: string) => void;
|
openSearch: (query: string) => void;
|
||||||
|
openHashtag: (tag: string) => void;
|
||||||
openDM: (pubkey: string) => void;
|
openDM: (pubkey: string) => void;
|
||||||
openArticle: (naddr: string, event?: NDKEvent) => void;
|
openArticle: (naddr: string, event?: NDKEvent) => void;
|
||||||
goBack: () => void;
|
goBack: () => void;
|
||||||
@@ -44,6 +46,7 @@ export const useUIStore = create<UIState>((set, _get) => ({
|
|||||||
pendingDMPubkey: null,
|
pendingDMPubkey: null,
|
||||||
pendingArticleNaddr: null,
|
pendingArticleNaddr: null,
|
||||||
pendingArticleEvent: null,
|
pendingArticleEvent: null,
|
||||||
|
pendingHashtag: null,
|
||||||
showHelp: false,
|
showHelp: false,
|
||||||
feedLanguageFilter: null,
|
feedLanguageFilter: null,
|
||||||
setView: (currentView) => set({ currentView }),
|
setView: (currentView) => set({ currentView }),
|
||||||
@@ -51,6 +54,7 @@ export const useUIStore = create<UIState>((set, _get) => ({
|
|||||||
openProfile: (pubkey) => set((s) => ({ currentView: "profile", selectedPubkey: pubkey, previousView: s.currentView as View })),
|
openProfile: (pubkey) => set((s) => ({ currentView: "profile", selectedPubkey: pubkey, previousView: s.currentView as View })),
|
||||||
openThread: (note, from) => set({ currentView: "thread", selectedNote: note, previousView: from }),
|
openThread: (note, from) => set({ currentView: "thread", selectedNote: note, previousView: from }),
|
||||||
openSearch: (query) => set({ currentView: "search", pendingSearch: query }),
|
openSearch: (query) => set({ currentView: "search", pendingSearch: query }),
|
||||||
|
openHashtag: (tag) => set((s) => ({ currentView: "hashtag", pendingHashtag: tag, previousView: s.currentView as View })),
|
||||||
openDM: (pubkey) => set({ currentView: "dm", pendingDMPubkey: pubkey }),
|
openDM: (pubkey) => set({ currentView: "dm", pendingDMPubkey: pubkey }),
|
||||||
openArticle: (naddr, event) => set((s) => ({ currentView: "article", pendingArticleNaddr: naddr, pendingArticleEvent: event ?? null, previousView: s.currentView as View })),
|
openArticle: (naddr, event) => set((s) => ({ currentView: "article", pendingArticleNaddr: naddr, pendingArticleEvent: event ?? null, previousView: s.currentView as View })),
|
||||||
goBack: () => set((s) => ({
|
goBack: () => set((s) => ({
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { useLightningStore } from "./lightning";
|
|||||||
import { useUIStore } from "./ui";
|
import { useUIStore } from "./ui";
|
||||||
import { useNotificationsStore } from "./notifications";
|
import { useNotificationsStore } from "./notifications";
|
||||||
import { useFeedStore } from "./feed";
|
import { useFeedStore } from "./feed";
|
||||||
|
import { startNotificationPoller, stopNotificationPoller } from "../lib/notificationPoller";
|
||||||
|
|
||||||
export interface SavedAccount {
|
export interface SavedAccount {
|
||||||
pubkey: string;
|
pubkey: string;
|
||||||
@@ -122,6 +123,7 @@ export const useUserStore = create<UserState>((set, get) => ({
|
|||||||
get().fetchFollows();
|
get().fetchFollows();
|
||||||
useMuteStore.getState().fetchMuteList(pubkey);
|
useMuteStore.getState().fetchMuteList(pubkey);
|
||||||
useNotificationsStore.getState().fetchNotifications(pubkey);
|
useNotificationsStore.getState().fetchNotifications(pubkey);
|
||||||
|
startNotificationPoller(pubkey);
|
||||||
|
|
||||||
// Navigate to feed and refresh so the new account's content loads
|
// Navigate to feed and refresh so the new account's content loads
|
||||||
useUIStore.getState().setView("feed");
|
useUIStore.getState().setView("feed");
|
||||||
@@ -165,6 +167,7 @@ export const useUserStore = create<UserState>((set, get) => ({
|
|||||||
get().fetchFollows();
|
get().fetchFollows();
|
||||||
useMuteStore.getState().fetchMuteList(pubkey);
|
useMuteStore.getState().fetchMuteList(pubkey);
|
||||||
useNotificationsStore.getState().fetchNotifications(pubkey);
|
useNotificationsStore.getState().fetchNotifications(pubkey);
|
||||||
|
startNotificationPoller(pubkey);
|
||||||
|
|
||||||
useUIStore.getState().setView("feed");
|
useUIStore.getState().setView("feed");
|
||||||
useFeedStore.getState().loadFeed();
|
useFeedStore.getState().loadFeed();
|
||||||
@@ -174,6 +177,7 @@ export const useUserStore = create<UserState>((set, get) => ({
|
|||||||
},
|
},
|
||||||
|
|
||||||
logout: () => {
|
logout: () => {
|
||||||
|
stopNotificationPoller();
|
||||||
const ndk = getNDK();
|
const ndk = getNDK();
|
||||||
ndk.signer = undefined;
|
ndk.signer = undefined;
|
||||||
// Don't delete the keychain entry — keep the account available for instant switch-back.
|
// Don't delete the keychain entry — keep the account available for instant switch-back.
|
||||||
@@ -228,6 +232,7 @@ export const useUserStore = create<UserState>((set, get) => ({
|
|||||||
get().fetchFollows();
|
get().fetchFollows();
|
||||||
useMuteStore.getState().fetchMuteList(savedPubkey);
|
useMuteStore.getState().fetchMuteList(savedPubkey);
|
||||||
useNotificationsStore.getState().fetchNotifications(savedPubkey);
|
useNotificationsStore.getState().fetchNotifications(savedPubkey);
|
||||||
|
startNotificationPoller(savedPubkey);
|
||||||
}
|
}
|
||||||
// No keychain entry → stay logged out, user re-enters nsec once.
|
// No keychain entry → stay logged out, user re-enters nsec once.
|
||||||
}
|
}
|
||||||
@@ -252,6 +257,7 @@ export const useUserStore = create<UserState>((set, get) => ({
|
|||||||
get().fetchOwnProfile();
|
get().fetchOwnProfile();
|
||||||
get().fetchFollows();
|
get().fetchFollows();
|
||||||
useMuteStore.getState().fetchMuteList(pubkey);
|
useMuteStore.getState().fetchMuteList(pubkey);
|
||||||
|
startNotificationPoller(pubkey);
|
||||||
useUIStore.getState().setView("feed");
|
useUIStore.getState().setView("feed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user