refactor: RequestBuilder
This commit is contained in:
@ -2,10 +2,11 @@ import { useMemo } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
import { getNewest } from "Util";
|
||||
import { HexKey, TaggedRawEvent, Lists } from "@snort/nostr";
|
||||
import { EventKind, Subscriptions } from "@snort/nostr";
|
||||
import useSubscription, { NoteStore } from "Feed/Subscription";
|
||||
import { HexKey, TaggedRawEvent, Lists, EventKind } from "@snort/nostr";
|
||||
|
||||
import { RootState } from "State/Store";
|
||||
import { ParameterizedReplaceableNoteStore, RequestBuilder } from "System";
|
||||
import useRequestBuilder from "Hooks/useRequestBuilder";
|
||||
|
||||
export default function useMutedFeed(pubkey?: HexKey) {
|
||||
const { publicKey, muted } = useSelector((s: RootState) => s.login);
|
||||
@ -13,23 +14,19 @@ export default function useMutedFeed(pubkey?: HexKey) {
|
||||
|
||||
const sub = useMemo(() => {
|
||||
if (isMe || !pubkey) return null;
|
||||
const sub = new Subscriptions();
|
||||
sub.Id = `muted:${pubkey.slice(0, 12)}`;
|
||||
sub.Kinds = new Set([EventKind.PubkeyLists]);
|
||||
sub.Authors = new Set([pubkey]);
|
||||
sub.DTags = new Set([Lists.Muted]);
|
||||
sub.Limit = 1;
|
||||
return sub;
|
||||
const b = new RequestBuilder(`muted:${pubkey.slice(0, 12)}`);
|
||||
b.withFilter().authors([pubkey]).kinds([EventKind.PubkeyLists]).tag("d", [Lists.Muted]);
|
||||
return b;
|
||||
}, [pubkey]);
|
||||
|
||||
const mutedFeed = useSubscription(sub, { leaveOpen: false, cache: true });
|
||||
const mutedFeed = useRequestBuilder<ParameterizedReplaceableNoteStore>(ParameterizedReplaceableNoteStore, sub);
|
||||
|
||||
const mutedList = useMemo(() => {
|
||||
if (pubkey) {
|
||||
return getMuted(mutedFeed.store, pubkey);
|
||||
if (pubkey && mutedFeed.data) {
|
||||
return getMuted(mutedFeed.data, pubkey);
|
||||
}
|
||||
return [];
|
||||
}, [mutedFeed.store, pubkey]);
|
||||
}, [mutedFeed, pubkey]);
|
||||
|
||||
return isMe ? muted : mutedList;
|
||||
}
|
||||
@ -50,7 +47,7 @@ export function getMutedKeys(rawNotes: TaggedRawEvent[]): {
|
||||
return { createdAt: 0, keys: [] };
|
||||
}
|
||||
|
||||
export function getMuted(feed: NoteStore, pubkey: HexKey): HexKey[] {
|
||||
const lists = feed?.notes.filter(a => a.kind === EventKind.PubkeyLists && a.pubkey === pubkey);
|
||||
export function getMuted(feed: readonly TaggedRawEvent[], pubkey: HexKey): HexKey[] {
|
||||
const lists = feed.filter(a => a.kind === EventKind.PubkeyLists && a.pubkey === pubkey);
|
||||
return getMutedKeys(lists).keys;
|
||||
}
|
||||
|
Reference in New Issue
Block a user