Follows/Followers
This commit is contained in:
parent
945302d1b9
commit
d679cc3755
21
src/element/FollowListBase.js
Normal file
21
src/element/FollowListBase.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import useEventPublisher from "../feed/EventPublisher";
|
||||||
|
import ProfilePreview from "./ProfilePreview";
|
||||||
|
|
||||||
|
export default function FollowListBase({ pubkeys }) {
|
||||||
|
const publisher = useEventPublisher();
|
||||||
|
|
||||||
|
async function followAll() {
|
||||||
|
let ev = await publisher.addFollow(pubkeys);
|
||||||
|
publisher.broadcast(ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="flex">
|
||||||
|
<div className="f-grow"></div>
|
||||||
|
<div className="btn" onClick={() => followAll()}>Follow All</div>
|
||||||
|
</div>
|
||||||
|
{pubkeys?.map(a => <ProfilePreview pubkey={a} key={a} options={{ about: false }} />)}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
@ -1,19 +1,15 @@
|
|||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import useFollowersFeed from "../feed/FollowersFeed";
|
import useFollowersFeed from "../feed/FollowersFeed";
|
||||||
import EventKind from "../nostr/EventKind";
|
import EventKind from "../nostr/EventKind";
|
||||||
import ProfilePreview from "./ProfilePreview";
|
import FollowListBase from "./FollowListBase";
|
||||||
|
|
||||||
export default function FollowersList(props) {
|
export default function FollowersList({ pubkey }) {
|
||||||
const feed = useFollowersFeed(props.pubkey);
|
const feed = useFollowersFeed(pubkey);
|
||||||
|
|
||||||
const pubKeys = useMemo(() => {
|
const pubkeys = useMemo(() => {
|
||||||
let contactLists = feed?.notes.filter(a => a.kind === EventKind.ContactList && a.tags.some(b => b[0] === "p" && b[1] === props.pubkey));
|
let contactLists = feed?.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))];
|
return [...new Set(contactLists?.map(a => a.pubkey))];
|
||||||
}, [feed]);
|
}, [feed]);
|
||||||
|
|
||||||
return (
|
return <FollowListBase pubkeys={pubkeys} />
|
||||||
<>
|
|
||||||
{pubKeys?.map(a => <ProfilePreview pubkey={a} key={a} options={{ about: false }}/>)}
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
}
|
16
src/element/FollowsList.js
Normal file
16
src/element/FollowsList.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { useMemo } from "react";
|
||||||
|
import useFollowsFeed from "../feed/FollowsFeed";
|
||||||
|
import EventKind from "../nostr/EventKind";
|
||||||
|
import FollowListBase from "./FollowListBase";
|
||||||
|
|
||||||
|
export default function FollowsList({ pubkey }) {
|
||||||
|
const feed = useFollowsFeed(pubkey);
|
||||||
|
|
||||||
|
const pubkeys = useMemo(() => {
|
||||||
|
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())];
|
||||||
|
}, [feed]);
|
||||||
|
|
||||||
|
return <FollowListBase pubkeys={pubkeys} />
|
||||||
|
}
|
@ -103,10 +103,15 @@ export default function useEventPublisher() {
|
|||||||
let ev = Event.ForPubKey(pubKey);
|
let ev = Event.ForPubKey(pubKey);
|
||||||
ev.Kind = EventKind.ContactList;
|
ev.Kind = EventKind.ContactList;
|
||||||
ev.Content = JSON.stringify(relays);
|
ev.Content = JSON.stringify(relays);
|
||||||
for (let pk of follows) {
|
let temp = new Set(follows);
|
||||||
|
if (Array.isArray(pkAdd)) {
|
||||||
|
pkAdd.forEach(a => temp.add(a));
|
||||||
|
} else {
|
||||||
|
temp.add(pkAdd);
|
||||||
|
}
|
||||||
|
for (let pk of temp) {
|
||||||
ev.Tags.push(new Tag(["p", pk]));
|
ev.Tags.push(new Tag(["p", pk]));
|
||||||
}
|
}
|
||||||
ev.Tags.push(new Tag(["p", pkAdd]));
|
|
||||||
|
|
||||||
return await signEvent(ev);
|
return await signEvent(ev);
|
||||||
},
|
},
|
||||||
|
17
src/feed/FollowsFeed.js
Normal file
17
src/feed/FollowsFeed.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { useMemo } from "react";
|
||||||
|
import EventKind from "../nostr/EventKind";
|
||||||
|
import { Subscriptions } from "../nostr/Subscriptions";
|
||||||
|
import useSubscription from "./Subscription";
|
||||||
|
|
||||||
|
export default function useFollowsFeed(pubkey) {
|
||||||
|
const sub = useMemo(() => {
|
||||||
|
let x = new Subscriptions();
|
||||||
|
x.Id = "follows";
|
||||||
|
x.Kinds.add(EventKind.ContactList);
|
||||||
|
x.Authors.add(pubkey);
|
||||||
|
|
||||||
|
return x;
|
||||||
|
}, [pubkey]);
|
||||||
|
|
||||||
|
return useSubscription(sub);
|
||||||
|
}
|
@ -17,10 +17,11 @@ import Nip05 from "../element/Nip05";
|
|||||||
import Copy from "../element/Copy";
|
import Copy from "../element/Copy";
|
||||||
import ProfilePreview from "../element/ProfilePreview";
|
import ProfilePreview from "../element/ProfilePreview";
|
||||||
import FollowersList from "../element/FollowersList";
|
import FollowersList from "../element/FollowersList";
|
||||||
|
import FollowsList from "../element/FollowsList";
|
||||||
|
|
||||||
const ProfileTab = {
|
const ProfileTab = {
|
||||||
Notes: 0,
|
Notes: 0,
|
||||||
Reactions: 1,
|
//Reactions: 1,
|
||||||
Followers: 2,
|
Followers: 2,
|
||||||
Follows: 3
|
Follows: 3
|
||||||
};
|
};
|
||||||
@ -84,6 +85,8 @@ export default function ProfilePage() {
|
|||||||
case ProfileTab.Follows: {
|
case ProfileTab.Follows: {
|
||||||
if (isMe) {
|
if (isMe) {
|
||||||
return follows.map(a => <ProfilePreview key={a} pubkey={a.toLowerCase()} options={{ about: false }} />)
|
return follows.map(a => <ProfilePreview key={a} pubkey={a.toLowerCase()} options={{ about: false }} />)
|
||||||
|
} else {
|
||||||
|
return <FollowsList pubkey={id} />;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case ProfileTab.Followers: {
|
case ProfileTab.Followers: {
|
||||||
|
Loading…
Reference in New Issue
Block a user