mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-09-25 19:23:45 +02:00
filter notifications by mute list
This commit is contained in:
@@ -11,6 +11,8 @@ import clientRelaysService from "../services/client-relays";
|
|||||||
import { getPubkeysMentionedInContent } from "../helpers/nostr/post";
|
import { getPubkeysMentionedInContent } from "../helpers/nostr/post";
|
||||||
import { TORRENT_COMMENT_KIND } from "../helpers/nostr/torrents";
|
import { TORRENT_COMMENT_KIND } from "../helpers/nostr/torrents";
|
||||||
import { STREAM_CHAT_MESSAGE_KIND } from "../helpers/nostr/stream";
|
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");
|
export const typeSymbol = Symbol("notificationType");
|
||||||
|
|
||||||
@@ -92,11 +94,15 @@ export default class AccountNotifications {
|
|||||||
|
|
||||||
throttleUpdateTimeline = _throttle(this.updateTimeline.bind(this), 200);
|
throttleUpdateTimeline = _throttle(this.updateTimeline.bind(this), 200);
|
||||||
updateTimeline() {
|
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 sorted = this.store.getSortedEvents();
|
||||||
|
|
||||||
const timeline: CategorizedEvent[] = [];
|
const timeline: CategorizedEvent[] = [];
|
||||||
for (const event of sorted) {
|
for (const event of sorted) {
|
||||||
if (!Object.hasOwn(event, typeSymbol)) continue;
|
if (!Object.hasOwn(event, typeSymbol)) continue;
|
||||||
|
if (mutedPubkeys.includes(event.pubkey)) continue;
|
||||||
const e = event as CategorizedEvent;
|
const e = event as CategorizedEvent;
|
||||||
|
|
||||||
switch (e[typeSymbol]) {
|
switch (e[typeSymbol]) {
|
||||||
|
@@ -5,15 +5,15 @@ import { DraftNostrEvent, NostrEvent, PTag, isATag, isDTag, isETag, isPTag, isRT
|
|||||||
import { parseCoordinate, replaceOrAddSimpleTag } from "./event";
|
import { parseCoordinate, replaceOrAddSimpleTag } from "./event";
|
||||||
import { getRelayVariations, safeRelayUrls } from "../relay";
|
import { getRelayVariations, safeRelayUrls } from "../relay";
|
||||||
|
|
||||||
export const MUTE_LIST_KIND = 10000;
|
export const MUTE_LIST_KIND = kinds.Mutelist;
|
||||||
export const PIN_LIST_KIND = 10001;
|
export const PIN_LIST_KIND = kinds.Pinlist;
|
||||||
export const BOOKMARK_LIST_KIND = 10003;
|
export const BOOKMARK_LIST_KIND = kinds.BookmarkList;
|
||||||
export const COMMUNITIES_LIST_KIND = 10004;
|
export const COMMUNITIES_LIST_KIND = kinds.CommunitiesList;
|
||||||
export const CHANNELS_LIST_KIND = 10005;
|
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 NOTE_LIST_KIND = 30001;
|
||||||
export const BOOKMARK_LIST_SET_KIND = 30003;
|
export const BOOKMARK_LIST_SET_KIND = kinds.Bookmarksets;
|
||||||
|
|
||||||
export function getListName(event: NostrEvent) {
|
export function getListName(event: NostrEvent) {
|
||||||
if (event.kind === kinds.Contacts) return "Following";
|
if (event.kind === kinds.Contacts) return "Following";
|
||||||
|
@@ -143,18 +143,35 @@ function NotificationsPage() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const nextDay = () => {
|
const nextDay = () => {
|
||||||
setDay((date) =>
|
setDay((date) => {
|
||||||
dayjs(date ?? today, DATE_FORMAT)
|
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")
|
.add(1, "day")
|
||||||
.format(DATE_FORMAT),
|
.format(DATE_FORMAT);
|
||||||
);
|
});
|
||||||
};
|
};
|
||||||
const previousDay = () => {
|
const previousDay = () => {
|
||||||
setDay((date) =>
|
setDay((date) => {
|
||||||
dayjs(date ?? today, DATE_FORMAT)
|
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")
|
.subtract(1, "day")
|
||||||
.format(DATE_FORMAT),
|
.format(DATE_FORMAT);
|
||||||
);
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// save toggles to localStorage when changed
|
// save toggles to localStorage when changed
|
||||||
|
Reference in New Issue
Block a user