From 9e05ea1c09a66386042a1304da08f2d2da3a2067 Mon Sep 17 00:00:00 2001 From: Silberengel Date: Thu, 13 Nov 2025 08:45:37 +0100 Subject: [PATCH] fix following and add mute display on following list --- src/components/FollowButton/index.tsx | 51 +++++++++++++++++++ src/components/MuteButton/index.tsx | 4 +- src/components/OthersRelayList/index.tsx | 6 +-- src/pages/secondary/FollowPacksPage/index.tsx | 39 +++++++++----- .../secondary/FollowingListPage/index.tsx | 8 +-- src/pages/secondary/MuteListPage/index.tsx | 2 +- .../OthersRelaySettingsPage/index.tsx | 2 +- 7 files changed, 88 insertions(+), 24 deletions(-) diff --git a/src/components/FollowButton/index.tsx b/src/components/FollowButton/index.tsx index d48dd32..32cf7f9 100644 --- a/src/components/FollowButton/index.tsx +++ b/src/components/FollowButton/index.tsx @@ -11,6 +11,7 @@ import { } from '@/components/ui/alert-dialog' import { Button } from '@/components/ui/button' import { useFollowList } from '@/providers/FollowListProvider' +import { useMuteList } from '@/providers/MuteListProvider' import { useNostr } from '@/providers/NostrProvider' import { Loader } from 'lucide-react' import { useMemo, useState } from 'react' @@ -21,9 +22,11 @@ export default function FollowButton({ pubkey }: { pubkey: string }) { const { t } = useTranslation() const { pubkey: accountPubkey, checkLogin } = useNostr() const { followings, follow, unfollow } = useFollowList() + const { mutePubkeySet, unmutePubkey } = useMuteList() const [updating, setUpdating] = useState(false) const [hover, setHover] = useState(false) const isFollowing = useMemo(() => followings.includes(pubkey), [followings, pubkey]) + const isMuted = useMemo(() => mutePubkeySet.has(pubkey), [mutePubkeySet, pubkey]) if (!accountPubkey || (pubkey && pubkey === accountPubkey)) return null @@ -59,6 +62,54 @@ export default function FollowButton({ pubkey }: { pubkey: string }) { }) } + const handleUnmute = async (e: React.MouseEvent) => { + e.stopPropagation() + checkLogin(async () => { + if (!isMuted) return + + setUpdating(true) + try { + await unmutePubkey(pubkey) + toast.success(t('User unmuted')) + } catch (error) { + toast.error(t('Unmute failed') + ': ' + (error as Error).message) + } finally { + setUpdating(false) + } + }) + } + + // If following and muted, show "Muted" button instead of "Following" + if (isFollowing && isMuted) { + return ( + + + + + + + {t('Unmute user')}? + + {t('Are you sure you want to unmute this user? This will restore the follow button.')} + + + + {t('Cancel')} + + {t('Unmute')} + + + + + ) + } + return isFollowing ? ( diff --git a/src/components/MuteButton/index.tsx b/src/components/MuteButton/index.tsx index 651c3a9..5a8f86b 100644 --- a/src/components/MuteButton/index.tsx +++ b/src/components/MuteButton/index.tsx @@ -64,12 +64,12 @@ export default function MuteButton({ pubkey }: { pubkey: string }) { if (isMuted) { return ( ) } diff --git a/src/components/OthersRelayList/index.tsx b/src/components/OthersRelayList/index.tsx index 55d1519..e536cec 100644 --- a/src/components/OthersRelayList/index.tsx +++ b/src/components/OthersRelayList/index.tsx @@ -1,4 +1,4 @@ -import { useSecondaryPage } from '@/PageManager' +import { useSmartRelayNavigation } from '@/PageManager' import { Badge } from '@/components/ui/badge' import { useFetchRelayInfo, useFetchRelayList } from '@/hooks' import { toRelay } from '@/lib/link' @@ -28,12 +28,12 @@ export default function OthersRelayList({ userId }: { userId: string }) { function RelayItem({ relay }: { relay: TMailboxRelay }) { const { t } = useTranslation() - const { push } = useSecondaryPage() + const { navigateToRelay } = useSmartRelayNavigation() const { relayInfo } = useFetchRelayInfo(relay.url) const { url, scope } = relay return ( -
push(toRelay(url))}> +
navigateToRelay(toRelay(url))}>
{['both', 'read'].includes(scope) && ( diff --git a/src/pages/secondary/FollowPacksPage/index.tsx b/src/pages/secondary/FollowPacksPage/index.tsx index 2329e69..bebec28 100644 --- a/src/pages/secondary/FollowPacksPage/index.tsx +++ b/src/pages/secondary/FollowPacksPage/index.tsx @@ -2,6 +2,7 @@ import { Button } from '@/components/ui/button' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Skeleton } from '@/components/ui/skeleton' import { useFollowList } from '@/providers/FollowListProvider' +import { useMuteList } from '@/providers/MuteListProvider' import { useNostr } from '@/providers/NostrProvider' import { getPubkeysFromPTags } from '@/lib/tag' import { Event } from 'nostr-tools' @@ -22,6 +23,7 @@ const FollowPacksPage = forwardRef([]) const [isLoading, setIsLoading] = useState(true) const [_followingPacks, setFollowingPacks] = useState>(new Set()) @@ -77,22 +79,29 @@ const FollowPacksPage = forwardRef !followingSet.has(p)) + // Filter out users that are already followed OR muted + const toFollow = packPubkeys.filter(p => !followingSet.has(p) && !mutePubkeySet.has(p)) if (toFollow.length === 0) { - toast.info(t('You are already following all members of this pack')) + const mutedCount = packPubkeys.filter(p => mutePubkeySet.has(p) && !followingSet.has(p)).length + if (mutedCount > 0) { + toast.info(t('All available members are already followed or muted')) + } else { + toast.info(t('You are already following all members of this pack')) + } return } try { - // Follow all pubkeys in the pack + // Follow all pubkeys in the pack (excluding muted users) for (const pubkeyToFollow of toFollow) { await follow(pubkeyToFollow) } toast.success(t('Followed {{count}} users', { count: toFollow.length })) - // Update followingPacks if all members are now followed - if (packPubkeys.every(p => followingSet.has(p) || toFollow.includes(p))) { + // Update followingPacks if all non-muted members are now followed + const nonMutedPackPubkeys = packPubkeys.filter(p => !mutePubkeySet.has(p)) + if (nonMutedPackPubkeys.length > 0 && nonMutedPackPubkeys.every(p => followingSet.has(p) || toFollow.includes(p))) { setFollowingPacks(prev => new Set([...prev, pack.id])) } } catch (error) { @@ -127,7 +136,7 @@ const FollowPacksPage = forwardRef +
{t('Please log in')}
{t('You need to be logged in to browse follow packs')}
@@ -137,7 +146,7 @@ const FollowPacksPage = forwardRef +
{!isLoading && packs.length > 0 && (
@@ -178,8 +187,10 @@ const FollowPacksPage = forwardRef { const packPubkeys = getPubkeysFromPTags(pack.tags) const followingSet = new Set(followings) - const alreadyFollowingAll = packPubkeys.length > 0 && packPubkeys.every(p => followingSet.has(p)) - const toFollowCount = packPubkeys.filter(p => !followingSet.has(p)).length + // Exclude muted users from calculations + const availablePubkeys = packPubkeys.filter(p => !mutePubkeySet.has(p)) + const alreadyFollowingAll = availablePubkeys.length > 0 && availablePubkeys.every(p => followingSet.has(p)) + const toFollowCount = availablePubkeys.filter(p => !followingSet.has(p)).length return ( @@ -192,12 +203,12 @@ const FollowPacksPage = forwardRef
- {t('{{count}} profiles', { count: packPubkeys.length })} + {t('{{count}} profiles', { count: availablePubkeys.length })}
- {packPubkeys.length > 0 && ( + {availablePubkeys.length > 0 && (
- {packPubkeys.slice(0, 5).map((pubkey) => ( + {availablePubkeys.slice(0, 5).map((pubkey) => ( ))} - {packPubkeys.length > 5 && ( + {availablePubkeys.length > 5 && (
- +{packPubkeys.length - 5} + +{availablePubkeys.length - 5}
)}
diff --git a/src/pages/secondary/FollowingListPage/index.tsx b/src/pages/secondary/FollowingListPage/index.tsx index 481807a..13dfc25 100644 --- a/src/pages/secondary/FollowingListPage/index.tsx +++ b/src/pages/secondary/FollowingListPage/index.tsx @@ -14,9 +14,11 @@ const FollowingListPage = forwardRef(({ id, index, hideTitlebar = false }: { id? ref={ref} index={index} title={ - profile?.username - ? t("username's following", { username: profile.username }) - : t('Following') + hideTitlebar + ? undefined + : profile?.username + ? t("username's following", { username: profile.username }) + : t('Following') } hideBackButton={hideTitlebar} displayScrollToTopButton diff --git a/src/pages/secondary/MuteListPage/index.tsx b/src/pages/secondary/MuteListPage/index.tsx index 388b0f9..2e5f451 100644 --- a/src/pages/secondary/MuteListPage/index.tsx +++ b/src/pages/secondary/MuteListPage/index.tsx @@ -60,7 +60,7 @@ const MuteListPage = forwardRef(({ index, hideTitlebar = false }: { index?: numb diff --git a/src/pages/secondary/OthersRelaySettingsPage/index.tsx b/src/pages/secondary/OthersRelaySettingsPage/index.tsx index 31a8eca..4601ac9 100644 --- a/src/pages/secondary/OthersRelaySettingsPage/index.tsx +++ b/src/pages/secondary/OthersRelaySettingsPage/index.tsx @@ -16,7 +16,7 @@ const RelaySettingsPage = forwardRef(({ id, index, hideTitlebar = false }: { id?