snort/src/Feed/FollowsFeed.ts

25 lines
863 B
TypeScript
Raw Normal View History

2023-01-10 12:05:36 +00:00
import { useMemo } from "react";
2023-01-20 11:11:50 +00:00
import { HexKey } from "Nostr";
import EventKind from "Nostr/EventKind";
import { Subscriptions} from "Nostr/Subscriptions";
import useSubscription, { NoteStore } from "Feed/Subscription";
2023-01-10 12:05:36 +00:00
2023-01-15 19:40:47 +00:00
export default function useFollowsFeed(pubkey: HexKey) {
2023-01-10 12:05:36 +00:00
const sub = useMemo(() => {
let x = new Subscriptions();
2023-02-01 13:22:11 +00:00
x.Id = `follows:${pubkey.slice(0, 12)}`;
2023-01-15 19:40:47 +00:00
x.Kinds = new Set([EventKind.ContactList]);
x.Authors = new Set([pubkey]);
2023-01-10 12:05:36 +00:00
return x;
}, [pubkey]);
return useSubscription(sub);
2023-01-18 03:26:42 +00:00
}
export function getFollowers(feed: NoteStore, pubkey: HexKey) {
let contactLists = feed?.notes.filter(a => a.kind === EventKind.ContactList && a.pubkey === pubkey);
let pTags = contactLists?.map(a => a.tags.filter(b => b[0] === "p").map(c => c[1]));
return [...new Set(pTags?.flat())];
}