filter notifications by mute list

This commit is contained in:
hzrd149
2024-04-02 08:43:34 -05:00
parent da2a72a765
commit 0cf61fe790
3 changed files with 38 additions and 15 deletions

View File

@@ -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]) {

View File

@@ -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";

View File

@@ -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