2023-01-10 10:30:33 +00:00
|
|
|
import { useMemo } from "react";
|
2023-02-11 20:05:46 +00:00
|
|
|
import { HexKey } from "@snort/nostr";
|
|
|
|
import { EventKind, Subscriptions } from "@snort/nostr";
|
2023-01-20 11:11:50 +00:00
|
|
|
import useSubscription from "Feed/Subscription";
|
2023-01-10 10:30:33 +00:00
|
|
|
|
2023-02-27 13:17:13 +00:00
|
|
|
export default function useFollowersFeed(pubkey?: HexKey) {
|
2023-02-07 20:04:50 +00:00
|
|
|
const sub = useMemo(() => {
|
2023-02-27 13:17:13 +00:00
|
|
|
if (!pubkey) return null;
|
2023-02-07 19:47:57 +00:00
|
|
|
const x = new Subscriptions();
|
2023-02-07 20:04:50 +00:00
|
|
|
x.Id = `followers:${pubkey.slice(0, 12)}`;
|
|
|
|
x.Kinds = new Set([EventKind.ContactList]);
|
|
|
|
x.PTags = new Set([pubkey]);
|
2023-01-10 10:30:33 +00:00
|
|
|
|
2023-02-07 20:04:50 +00:00
|
|
|
return x;
|
|
|
|
}, [pubkey]);
|
2023-01-10 10:30:33 +00:00
|
|
|
|
2023-02-10 11:12:11 +00:00
|
|
|
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;
|
2023-02-07 20:04:50 +00:00
|
|
|
}
|