From feab147fb952e38620453d8d88896a8bba296a13 Mon Sep 17 00:00:00 2001 From: Alejandro Gomez Date: Tue, 25 Jul 2023 16:30:53 +0200 Subject: [PATCH] fix: dont alter followed tags --- src/element/follow-button.tsx | 14 ++++++++------ src/hooks/follows.ts | 3 +-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/element/follow-button.tsx b/src/element/follow-button.tsx index 8d34fce..813086d 100644 --- a/src/element/follow-button.tsx +++ b/src/element/follow-button.tsx @@ -11,18 +11,20 @@ export function LoggedInFollowButton({ loggedIn: string; pubkey: string; }) { - const { contacts, relays } = useFollows(loggedIn, true); 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() { const pub = login?.publisher(); if (pub) { const ev = await pub.generic((eb) => { eb.kind(EventKind.ContactList).content(JSON.stringify(relays)); - for (const c of contacts) { - if (c.at(1) !== pubkey) { - eb.tag(c); + for (const t of tags) { + const isFollow = t.at(0) === "p" && t.at(1) === pubkey + if (!isFollow) { + eb.tag(t); } } return eb; @@ -37,7 +39,7 @@ export function LoggedInFollowButton({ if (pub) { const ev = await pub.generic((eb) => { eb.kind(EventKind.ContactList).content(JSON.stringify(relays)); - for (const tag of contacts) { + for (const tag of tags) { eb.tag(tag); } eb.tag(["p", pubkey]); diff --git a/src/hooks/follows.ts b/src/hooks/follows.ts index 657354d..c9d349c 100644 --- a/src/hooks/follows.ts +++ b/src/hooks/follows.ts @@ -21,8 +21,7 @@ export default function useFollows(pubkey: string, leaveOpen = false) { sub ); - const contacts = (data?.tags ?? []).filter((t) => t.at(0) === "p"); const relays = JSON.parse(data?.content ?? "{}"); - return { contacts, relays }; + return { tags: data?.tags ?? [], relays }; }