feat: nip5 in profile path

This commit is contained in:
2023-02-27 13:17:13 +00:00
parent 688c5cf4f8
commit 45c4c3bce1
10 changed files with 56 additions and 40 deletions

View File

@ -4,7 +4,7 @@ import { RootState } from "State/Store";
import { HexKey, Lists } from "@snort/nostr";
import useNotelistSubscription from "Feed/useNotelistSubscription";
export default function useBookmarkFeed(pubkey: HexKey) {
export default function useBookmarkFeed(pubkey?: HexKey) {
const { bookmarked } = useSelector((s: RootState) => s.login);
return useNotelistSubscription(pubkey, Lists.Bookmarked, bookmarked);
}

View File

@ -3,8 +3,9 @@ import { HexKey } from "@snort/nostr";
import { EventKind, Subscriptions } from "@snort/nostr";
import useSubscription from "Feed/Subscription";
export default function useFollowersFeed(pubkey: HexKey) {
export default function useFollowersFeed(pubkey?: HexKey) {
const sub = useMemo(() => {
if (!pubkey) return null;
const x = new Subscriptions();
x.Id = `followers:${pubkey.slice(0, 12)}`;
x.Kinds = new Set([EventKind.ContactList]);

View File

@ -5,12 +5,12 @@ import { HexKey, TaggedRawEvent, EventKind, Subscriptions } from "@snort/nostr";
import useSubscription from "Feed/Subscription";
import { RootState } from "State/Store";
export default function useFollowsFeed(pubkey: HexKey) {
export default function useFollowsFeed(pubkey?: HexKey) {
const { publicKey, follows } = useSelector((s: RootState) => s.login);
const isMe = publicKey === pubkey;
const sub = useMemo(() => {
if (isMe) return null;
if (isMe || !pubkey) return null;
const x = new Subscriptions();
x.Id = `follows:${pubkey.slice(0, 12)}`;
x.Kinds = new Set([EventKind.ContactList]);
@ -23,11 +23,12 @@ export default function useFollowsFeed(pubkey: HexKey) {
if (isMe) {
return follows;
}
return getFollowing(contactFeed.store.notes ?? [], pubkey);
}, [contactFeed.store, follows]);
}, [contactFeed.store, follows, pubkey]);
}
export function getFollowing(notes: TaggedRawEvent[], pubkey: HexKey) {
export function getFollowing(notes: TaggedRawEvent[], pubkey?: HexKey) {
const contactLists = notes.filter(a => a.kind === EventKind.ContactList && a.pubkey === pubkey);
const pTags = contactLists?.map(a => a.tags.filter(b => b[0] === "p").map(c => c[1]));
return [...new Set(pTags?.flat())];

View File

@ -7,12 +7,12 @@ import { EventKind, Subscriptions } from "@snort/nostr";
import useSubscription, { NoteStore } from "Feed/Subscription";
import { RootState } from "State/Store";
export default function useMutedFeed(pubkey: HexKey) {
export default function useMutedFeed(pubkey?: HexKey) {
const { publicKey, muted } = useSelector((s: RootState) => s.login);
const isMe = publicKey === pubkey;
const sub = useMemo(() => {
if (isMe) return null;
if (isMe || !pubkey) return null;
const sub = new Subscriptions();
sub.Id = `muted:${pubkey.slice(0, 12)}`;
sub.Kinds = new Set([EventKind.PubkeyLists]);
@ -25,8 +25,11 @@ export default function useMutedFeed(pubkey: HexKey) {
const mutedFeed = useSubscription(sub, { leaveOpen: false, cache: true });
const mutedList = useMemo(() => {
return getMuted(mutedFeed.store, pubkey);
}, [mutedFeed.store]);
if (pubkey) {
return getMuted(mutedFeed.store, pubkey);
}
return [];
}, [mutedFeed.store, pubkey]);
return isMe ? muted : mutedList;
}

View File

@ -4,7 +4,7 @@ import { RootState } from "State/Store";
import { HexKey, Lists } from "@snort/nostr";
import useNotelistSubscription from "Feed/useNotelistSubscription";
export default function usePinnedFeed(pubkey: HexKey) {
export default function usePinnedFeed(pubkey?: HexKey) {
const { pinned } = useSelector((s: RootState) => s.login);
return useNotelistSubscription(pubkey, Lists.Pinned, pinned);
}

View File

@ -3,8 +3,9 @@ import { HexKey, FullRelaySettings } from "@snort/nostr";
import { EventKind, Subscriptions } from "@snort/nostr";
import useSubscription from "./Subscription";
export default function useRelaysFeed(pubkey: HexKey) {
export default function useRelaysFeed(pubkey?: HexKey) {
const sub = useMemo(() => {
if (!pubkey) return null;
const x = new Subscriptions();
x.Id = `relays:${pubkey.slice(0, 12)}`;
x.Kinds = new Set([EventKind.ContactList]);

View File

@ -3,8 +3,9 @@ import { HexKey, EventKind, Subscriptions } from "@snort/nostr";
import { parseZap } from "Element/Zap";
import useSubscription from "./Subscription";
export default function useZapsFeed(pubkey: HexKey) {
export default function useZapsFeed(pubkey?: HexKey) {
const sub = useMemo(() => {
if (!pubkey) return null;
const x = new Subscriptions();
x.Id = `zaps:${pubkey.slice(0, 12)}`;
x.Kinds = new Set([EventKind.ZapReceipt]);

View File

@ -6,12 +6,12 @@ import { HexKey, Lists, EventKind, Subscriptions } from "@snort/nostr";
import useSubscription from "Feed/Subscription";
import { RootState } from "State/Store";
export default function useNotelistSubscription(pubkey: HexKey, l: Lists, defaultIds: HexKey[]) {
export default function useNotelistSubscription(pubkey: HexKey | undefined, l: Lists, defaultIds: HexKey[]) {
const { preferences, publicKey } = useSelector((s: RootState) => s.login);
const isMe = publicKey === pubkey;
const sub = useMemo(() => {
if (isMe) return null;
if (isMe || !pubkey) return null;
const sub = new Subscriptions();
sub.Id = `note-list-${l}:${pubkey.slice(0, 12)}`;
sub.Kinds = new Set([EventKind.NoteLists]);
@ -33,12 +33,13 @@ export default function useNotelistSubscription(pubkey: HexKey, l: Lists, defaul
}, [store.notes, isMe, defaultIds]);
const esub = useMemo(() => {
if (!pubkey) return null;
const s = new Subscriptions();
s.Id = `${l}-notes:${pubkey.slice(0, 12)}`;
s.Kinds = new Set([EventKind.TextNote]);
s.Ids = new Set(etags);
return s;
}, [etags]);
}, [etags, pubkey]);
const subRelated = useMemo(() => {
let sub: Subscriptions | undefined;