From fcf6d258effd610f72d1c386a13106b98fd307db Mon Sep 17 00:00:00 2001 From: Chewbacca Date: Tue, 18 Apr 2023 16:51:55 -0400 Subject: [PATCH] Prevent request to endpoint if not member --- .../features/ui/components/group-media-panel.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/soapbox/features/ui/components/group-media-panel.tsx b/app/soapbox/features/ui/components/group-media-panel.tsx index 85432d74c..1d9428f33 100644 --- a/app/soapbox/features/ui/components/group-media-panel.tsx +++ b/app/soapbox/features/ui/components/group-media-panel.tsx @@ -21,6 +21,9 @@ const GroupMediaPanel: React.FC = ({ group }) => { const [loading, setLoading] = useState(true); + const isMember = !!group?.relationship?.member; + const isPrivate = group?.locked; + const attachments: ImmutableList = useAppSelector((state) => group ? getGroupGallery(state, group?.id) : ImmutableList()); const handleOpenMedia = (attachment: Attachment): void => { @@ -37,13 +40,13 @@ const GroupMediaPanel: React.FC = ({ group }) => { useEffect(() => { setLoading(true); - if (group) { + if (group && (isMember || !isPrivate)) { dispatch(expandGroupMediaTimeline(group.id)) // @ts-ignore .then(() => setLoading(false)) .catch(() => {}); } - }, [group?.id]); + }, [group?.id, isMember, isPrivate]); const renderAttachments = () => { const nineAttachments = attachments.slice(0, 9); @@ -69,6 +72,10 @@ const GroupMediaPanel: React.FC = ({ group }) => { } }; + if (isPrivate && !isMember) { + return null; + } + return ( }> {group && (