fix: dont alter followed tags

This commit is contained in:
Alejandro Gomez
2023-07-25 16:30:53 +02:00
parent 0d9a5b3b86
commit feab147fb9
2 changed files with 9 additions and 8 deletions

View File

@ -11,18 +11,20 @@ export function LoggedInFollowButton({
loggedIn: string; loggedIn: string;
pubkey: string; pubkey: string;
}) { }) {
const { contacts, relays } = useFollows(loggedIn, true);
const login = useLogin(); const login = useLogin();
const isFollowing = contacts.find((t) => t.at(1) === pubkey); const { tags, relays } = useFollows(loggedIn, true);
const follows = tags.filter((t) => t.at(0) === "p")
const isFollowing = follows.find((t) => t.at(1) === pubkey);
async function unfollow() { async function unfollow() {
const pub = login?.publisher(); const pub = login?.publisher();
if (pub) { if (pub) {
const ev = await pub.generic((eb) => { const ev = await pub.generic((eb) => {
eb.kind(EventKind.ContactList).content(JSON.stringify(relays)); eb.kind(EventKind.ContactList).content(JSON.stringify(relays));
for (const c of contacts) { for (const t of tags) {
if (c.at(1) !== pubkey) { const isFollow = t.at(0) === "p" && t.at(1) === pubkey
eb.tag(c); if (!isFollow) {
eb.tag(t);
} }
} }
return eb; return eb;
@ -37,7 +39,7 @@ export function LoggedInFollowButton({
if (pub) { if (pub) {
const ev = await pub.generic((eb) => { const ev = await pub.generic((eb) => {
eb.kind(EventKind.ContactList).content(JSON.stringify(relays)); eb.kind(EventKind.ContactList).content(JSON.stringify(relays));
for (const tag of contacts) { for (const tag of tags) {
eb.tag(tag); eb.tag(tag);
} }
eb.tag(["p", pubkey]); eb.tag(["p", pubkey]);

View File

@ -21,8 +21,7 @@ export default function useFollows(pubkey: string, leaveOpen = false) {
sub sub
); );
const contacts = (data?.tags ?? []).filter((t) => t.at(0) === "p");
const relays = JSON.parse(data?.content ?? "{}"); const relays = JSON.parse(data?.content ?? "{}");
return { contacts, relays }; return { tags: data?.tags ?? [], relays };
} }