mirror of
https://github.com/hoornet/vega.git
synced 2026-05-07 04:39:12 -07:00
Grouped emoji reactions, npub search, notification fix, dev logger
- Emoji reactions now display as grouped pills (❤️5 🤙3 🔥2) instead of a single aggregated count. Multi-reaction per note supported. - Throttled reaction fetch queue (max 4 concurrent) prevents relay overload. - Searching a bare npub/nprofile navigates directly to that profile. - Notification poller waits for relay connection before first fetch, fixing empty results on startup. - Dev-only debug logger (src/lib/debug.ts) — silent in production builds.
This commit is contained in:
@@ -48,9 +48,9 @@ describe("useFeedStore - loadTrendingFeed", () => {
|
||||
];
|
||||
|
||||
const engagement = new Map([
|
||||
["a", { reactions: 10, replies: 0, zapSats: 0 }], // score: 10
|
||||
["b", { reactions: 0, replies: 5, zapSats: 0 }], // score: 15
|
||||
["c", { reactions: 1, replies: 1, zapSats: 100 }], // score: 5
|
||||
["a", { reactions: 10, replies: 0, zapSats: 0, reactionGroups: new Map<string, number>(), myReactions: new Set<string>() }], // score: 10
|
||||
["b", { reactions: 0, replies: 5, zapSats: 0, reactionGroups: new Map<string, number>(), myReactions: new Set<string>() }], // score: 15
|
||||
["c", { reactions: 1, replies: 1, zapSats: 100, reactionGroups: new Map<string, number>(), myReactions: new Set<string>() }], // score: 5
|
||||
]);
|
||||
|
||||
vi.mocked(fetchTrendingCandidates).mockResolvedValue(notes);
|
||||
@@ -73,8 +73,8 @@ describe("useFeedStore - loadTrendingFeed", () => {
|
||||
];
|
||||
|
||||
const engagement = new Map([
|
||||
["a", { reactions: 5, replies: 0, zapSats: 0 }],
|
||||
["b", { reactions: 0, replies: 0, zapSats: 0 }],
|
||||
["a", { reactions: 5, replies: 0, zapSats: 0, reactionGroups: new Map<string, number>(), myReactions: new Set<string>() }],
|
||||
["b", { reactions: 0, replies: 0, zapSats: 0, reactionGroups: new Map<string, number>(), myReactions: new Set<string>() }],
|
||||
]);
|
||||
|
||||
vi.mocked(fetchTrendingCandidates).mockResolvedValue(notes);
|
||||
@@ -91,7 +91,7 @@ describe("useFeedStore - loadTrendingFeed", () => {
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
const notes = Array.from({ length: 60 }, (_, i) => makeMockNote(`n${i}`, now - i));
|
||||
const engagement = new Map(
|
||||
notes.map((n) => [n.id, { reactions: 10, replies: 1, zapSats: 0 }])
|
||||
notes.map((n) => [n.id, { reactions: 10, replies: 1, zapSats: 0, reactionGroups: new Map<string, number>(), myReactions: new Set<string>() }])
|
||||
);
|
||||
|
||||
vi.mocked(fetchTrendingCandidates).mockResolvedValue(notes);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { create } from "zustand";
|
||||
import { NDKEvent } from "@nostr-dev-kit/ndk";
|
||||
import { fetchMentions } from "../lib/nostr";
|
||||
import { debug } from "../lib/debug";
|
||||
|
||||
const NOTIF_READ_KEY = "wrystr_notif_read_ids";
|
||||
const DM_SEEN_KEY = "wrystr_dm_last_seen";
|
||||
@@ -71,18 +72,19 @@ export const useNotificationsStore = create<NotificationsState>((set, get) => ({
|
||||
const since = Math.floor(Date.now() / 1000) - 7 * 86400;
|
||||
// Fetch more than we need since we filter out own events
|
||||
const events = await fetchMentions(pubkey, since, MAX_NOTIFICATIONS * 3);
|
||||
// Filter out own events — your replies shouldn't be notifications
|
||||
const others = events.filter((e) => e.pubkey !== pubkey);
|
||||
const sorted = others.sort((a, b) => (b.created_at ?? 0) - (a.created_at ?? 0)).slice(0, MAX_NOTIFICATIONS);
|
||||
debug.log("notif:fetch", events.length, "raw →", others.length, "others →", sorted.length, "kept");
|
||||
|
||||
// Don't overwrite existing notifications with empty results (relay timeout/disconnect)
|
||||
const { readIds, notifications: existing } = get();
|
||||
if (sorted.length === 0 && existing.length > 0) {
|
||||
// Keep existing notifications — relay probably timed out
|
||||
debug.warn("notif:fetch empty result, keeping", existing.length, "existing");
|
||||
return;
|
||||
}
|
||||
|
||||
const unreadCount = sorted.filter((e) => !readIds.has(e.id!)).length;
|
||||
debug.log("notif:set", sorted.length, "notifications,", unreadCount, "unread");
|
||||
set({ notifications: sorted, unreadCount });
|
||||
} catch {
|
||||
// Non-critical — keep existing notifications on error
|
||||
|
||||
Reference in New Issue
Block a user