count in profile page
This commit is contained in:
@ -13,5 +13,14 @@ export default function useFollowersFeed(pubkey: HexKey) {
|
||||
return x;
|
||||
}, [pubkey]);
|
||||
|
||||
return useSubscription(sub);
|
||||
const followersFeed = useSubscription(sub, { leaveOpen: false, cache: true });
|
||||
|
||||
const followers = useMemo(() => {
|
||||
const contactLists = followersFeed?.store.notes.filter(
|
||||
a => a.kind === EventKind.ContactList && a.tags.some(b => b[0] === "p" && b[1] === pubkey)
|
||||
);
|
||||
return [...new Set(contactLists?.map(a => a.pubkey))];
|
||||
}, [followersFeed, pubkey]);
|
||||
|
||||
return followers;
|
||||
}
|
||||
|
@ -1,23 +1,32 @@
|
||||
import { useMemo } from "react";
|
||||
import { HexKey } from "@snort/nostr";
|
||||
import { EventKind, Subscriptions } from "@snort/nostr";
|
||||
import useSubscription, { NoteStore } from "Feed/Subscription";
|
||||
import { useSelector } from "react-redux";
|
||||
import { HexKey, TaggedRawEvent, EventKind, Subscriptions } from "@snort/nostr";
|
||||
|
||||
import useSubscription from "Feed/Subscription";
|
||||
import { RootState } from "State/Store";
|
||||
|
||||
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;
|
||||
const x = new Subscriptions();
|
||||
x.Id = `follows:${pubkey.slice(0, 12)}`;
|
||||
x.Kinds = new Set([EventKind.ContactList]);
|
||||
x.Authors = new Set([pubkey]);
|
||||
|
||||
return x;
|
||||
}, [pubkey]);
|
||||
}, [isMe, pubkey]);
|
||||
|
||||
return useSubscription(sub);
|
||||
const contactFeed = useSubscription(sub, { leaveOpen: false, cache: true });
|
||||
const following = useMemo(() => {
|
||||
return getFollowing(contactFeed.store.notes ?? [], pubkey);
|
||||
}, [contactFeed.store.notes]);
|
||||
return isMe ? follows : following;
|
||||
}
|
||||
|
||||
export function getFollowers(feed: NoteStore, pubkey: HexKey) {
|
||||
const contactLists = feed?.notes.filter(a => a.kind === EventKind.ContactList && a.pubkey === pubkey);
|
||||
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())];
|
||||
}
|
||||
|
@ -1,12 +1,18 @@
|
||||
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 { RootState } from "State/Store";
|
||||
|
||||
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;
|
||||
const sub = new Subscriptions();
|
||||
sub.Id = `muted:${pubkey.slice(0, 12)}`;
|
||||
sub.Kinds = new Set([EventKind.PubkeyLists]);
|
||||
@ -16,7 +22,13 @@ export default function useMutedFeed(pubkey: HexKey) {
|
||||
return sub;
|
||||
}, [pubkey]);
|
||||
|
||||
return useSubscription(sub);
|
||||
const mutedFeed = useSubscription(sub, { leaveOpen: false, cache: true });
|
||||
|
||||
const mutedList = useMemo(() => {
|
||||
return getMuted(mutedFeed.store, pubkey);
|
||||
}, [mutedFeed.store]);
|
||||
|
||||
return isMe ? muted : mutedList;
|
||||
}
|
||||
|
||||
export function getMutedKeys(rawNotes: TaggedRawEvent[]): {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useMemo } from "react";
|
||||
import { HexKey } from "@snort/nostr";
|
||||
import { EventKind, Subscriptions } from "@snort/nostr";
|
||||
import { HexKey, EventKind, Subscriptions } from "@snort/nostr";
|
||||
import { parseZap } from "Element/Zap";
|
||||
import useSubscription from "./Subscription";
|
||||
|
||||
export default function useZapsFeed(pubkey: HexKey) {
|
||||
@ -12,5 +12,15 @@ export default function useZapsFeed(pubkey: HexKey) {
|
||||
return x;
|
||||
}, [pubkey]);
|
||||
|
||||
return useSubscription(sub, { leaveOpen: true, cache: true });
|
||||
const zapsFeed = useSubscription(sub, { leaveOpen: false, cache: true });
|
||||
|
||||
const zaps = useMemo(() => {
|
||||
const profileZaps = zapsFeed.store.notes
|
||||
.map(parseZap)
|
||||
.filter(z => z.valid && z.p === pubkey && z.zapper !== pubkey && !z.e);
|
||||
profileZaps.sort((a, b) => b.amount - a.amount);
|
||||
return profileZaps;
|
||||
}, [zapsFeed]);
|
||||
|
||||
return zaps;
|
||||
}
|
||||
|
Reference in New Issue
Block a user