diff --git a/src/classes/notifications.ts b/src/classes/notifications.ts index dea025984..61bc97c63 100644 --- a/src/classes/notifications.ts +++ b/src/classes/notifications.ts @@ -11,6 +11,8 @@ import clientRelaysService from "../services/client-relays"; import { getPubkeysMentionedInContent } from "../helpers/nostr/post"; import { TORRENT_COMMENT_KIND } from "../helpers/nostr/torrents"; import { STREAM_CHAT_MESSAGE_KIND } from "../helpers/nostr/stream"; +import replaceableEventsService from "../services/replaceable-events"; +import { MUTE_LIST_KIND, getPubkeysFromList } from "../helpers/nostr/lists"; export const typeSymbol = Symbol("notificationType"); @@ -92,11 +94,15 @@ export default class AccountNotifications { throttleUpdateTimeline = _throttle(this.updateTimeline.bind(this), 200); updateTimeline() { + const muteList = replaceableEventsService.getEvent(MUTE_LIST_KIND, this.pubkey).value; + const mutedPubkeys = muteList ? getPubkeysFromList(muteList).map((p) => p.pubkey) : []; + const sorted = this.store.getSortedEvents(); const timeline: CategorizedEvent[] = []; for (const event of sorted) { if (!Object.hasOwn(event, typeSymbol)) continue; + if (mutedPubkeys.includes(event.pubkey)) continue; const e = event as CategorizedEvent; switch (e[typeSymbol]) { diff --git a/src/helpers/nostr/lists.ts b/src/helpers/nostr/lists.ts index 1f47822c6..ba833ec64 100644 --- a/src/helpers/nostr/lists.ts +++ b/src/helpers/nostr/lists.ts @@ -5,15 +5,15 @@ import { DraftNostrEvent, NostrEvent, PTag, isATag, isDTag, isETag, isPTag, isRT import { parseCoordinate, replaceOrAddSimpleTag } from "./event"; import { getRelayVariations, safeRelayUrls } from "../relay"; -export const MUTE_LIST_KIND = 10000; -export const PIN_LIST_KIND = 10001; -export const BOOKMARK_LIST_KIND = 10003; -export const COMMUNITIES_LIST_KIND = 10004; -export const CHANNELS_LIST_KIND = 10005; +export const MUTE_LIST_KIND = kinds.Mutelist; +export const PIN_LIST_KIND = kinds.Pinlist; +export const BOOKMARK_LIST_KIND = kinds.BookmarkList; +export const COMMUNITIES_LIST_KIND = kinds.CommunitiesList; +export const CHANNELS_LIST_KIND = kinds.PublicChatsList; -export const PEOPLE_LIST_KIND = 30000; +export const PEOPLE_LIST_KIND = kinds.Followsets; export const NOTE_LIST_KIND = 30001; -export const BOOKMARK_LIST_SET_KIND = 30003; +export const BOOKMARK_LIST_SET_KIND = kinds.Bookmarksets; export function getListName(event: NostrEvent) { if (event.kind === kinds.Contacts) return "Following"; diff --git a/src/views/notifications/index.tsx b/src/views/notifications/index.tsx index a921438e5..9997d3612 100644 --- a/src/views/notifications/index.tsx +++ b/src/views/notifications/index.tsx @@ -143,18 +143,35 @@ function NotificationsPage() { ); const nextDay = () => { - setDay((date) => - dayjs(date ?? today, DATE_FORMAT) + setDay((date) => { + const endOfDay = dayjs(date ?? today, DATE_FORMAT) + .endOf("day") + .unix(); + + // find the next event + for (let i = timeline.timeline.value.length - 1; i > 0; i--) { + const e = timeline.timeline.value[i]; + if (e.created_at > endOfDay) return dayjs.unix(e.created_at).format(DATE_FORMAT); + } + + return dayjs(date ?? today, DATE_FORMAT) .add(1, "day") - .format(DATE_FORMAT), - ); + .format(DATE_FORMAT); + }); }; const previousDay = () => { - setDay((date) => - dayjs(date ?? today, DATE_FORMAT) + setDay((date) => { + const startOfDay = dayjs(date ?? today, DATE_FORMAT).unix(); + + // find the next event + for (const e of timeline.timeline.value) { + if (e.created_at < startOfDay) return dayjs.unix(e.created_at).format(DATE_FORMAT); + } + + return dayjs(date ?? today, DATE_FORMAT) .subtract(1, "day") - .format(DATE_FORMAT), - ); + .format(DATE_FORMAT); + }); }; // save toggles to localStorage when changed