From 31f326b74fd6a3a8e057aa59ac9db6cad572f45d Mon Sep 17 00:00:00 2001 From: Hirbod Mirjavadi Date: Wed, 27 Sep 2023 21:58:13 +0200 Subject: [PATCH] fix: wrong channel permission management --- .../components/message-item.tsx | 18 +++++++++--------- .../hooks/use-channel-detail.ts | 7 ++++++- .../components/creator-channels/messages.tsx | 9 ++++++++- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/packages/app/components/creator-channels/components/message-item.tsx b/packages/app/components/creator-channels/components/message-item.tsx index d5bd6d5f84..0470c531e2 100644 --- a/packages/app/components/creator-channels/components/message-item.tsx +++ b/packages/app/components/creator-channels/components/message-item.tsx @@ -52,7 +52,7 @@ import { MenuItemIcon } from "../../dropdown/menu-item-icon"; import { MessageReactions } from "../../reaction/message-reactions"; import { useDeleteMessage } from "../hooks/use-delete-message"; import { useReactOnMessage } from "../hooks/use-react-on-message"; -import { ChannelMessageItem, MessageItemProps } from "../types"; +import { ChannelById, ChannelMessageItem, MessageItemProps } from "../types"; import { generateLoremIpsum } from "../utils"; import { CreatorBadge } from "./creator-badge"; import { LeanText, LeanView } from "./lean-text"; @@ -109,11 +109,12 @@ export const MessageItem = memo( setEditMessage, editMessageIdSharedValue, editMessageItemDimension, - edition, + permissions, isUserAdmin, }: MessageItemProps & { edition?: CreatorEditionResponse; isUserAdmin?: boolean; + permissions?: ChannelById["permissions"]; listRef: RefObject>; editMessageIdSharedValue: SharedValue; editMessageItemDimension: SharedValue<{ @@ -196,16 +197,13 @@ export const MessageItem = memo( }, [channel_message.created_at]); const isByCreator = channel_message.sent_by.admin; - const isStarDrop = channel_message.is_payment_gated; - const isUnlockedStarDrop = isStarDrop && channel_message.body; - const messageNotViewable = isStarDrop && !isUnlockedStarDrop && edition; const loremText = useMemo( () => - messageNotViewable && item.channel_message.body_text_length > 0 + item.channel_message.body_text_length > 0 ? generateLoremIpsum(item.channel_message.body_text_length) : "", - [item.channel_message.body_text_length, messageNotViewable] + [item.channel_message.body_text_length] ); // TODO: remove and support video @@ -260,7 +258,9 @@ export const MessageItem = memo( style={{ gap: 12, display: - messageNotViewable && !isUserAdmin ? "none" : undefined, + isByCreator && !permissions?.can_view_creator_messages + ? "none" + : undefined, }} > - {messageNotViewable && !isUserAdmin ? ( + {isByCreator && !permissions?.can_view_creator_messages ? ( {Platform.OS === "web" ? ( // INFO: I had to do it like that because blur-sm would crash for no reason even with web prefix diff --git a/packages/app/components/creator-channels/hooks/use-channel-detail.ts b/packages/app/components/creator-channels/hooks/use-channel-detail.ts index 54b46fafe9..e2fcc38bb0 100644 --- a/packages/app/components/creator-channels/hooks/use-channel-detail.ts +++ b/packages/app/components/creator-channels/hooks/use-channel-detail.ts @@ -11,7 +11,12 @@ export const getChannelByIdCacheKey = (channelId: string | number) => { export const useChannelById = (channelId?: string | number) => { const queryState = useSWR( channelId ? getChannelByIdCacheKey(channelId) : null, - fetcher + fetcher, + { + focusThrottleInterval: 5000, + dedupingInterval: 5000, + revalidateIfStale: false, + } ); return queryState; diff --git a/packages/app/components/creator-channels/messages.tsx b/packages/app/components/creator-channels/messages.tsx index 9186795524..12045bdd9d 100644 --- a/packages/app/components/creator-channels/messages.tsx +++ b/packages/app/components/creator-channels/messages.tsx @@ -355,10 +355,17 @@ export const Messages = memo(() => { editMessageItemDimension={editMessageItemDimension} edition={edition} isUserAdmin={isUserAdmin} + permissions={channelDetail.data?.permissions} /> ); }, - [editMessageIdSharedValue, editMessageItemDimension, edition, isUserAdmin] + [ + channelDetail.data?.permissions, + editMessageIdSharedValue, + editMessageItemDimension, + edition, + isUserAdmin, + ] ); // TODO: add back to keyboard controller?