Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
fix: wrong channel permission management
Browse files Browse the repository at this point in the history
  • Loading branch information
hirbod committed Sep 27, 2023
1 parent c2082c0 commit 31f326b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -109,11 +109,12 @@ export const MessageItem = memo(
setEditMessage,
editMessageIdSharedValue,
editMessageItemDimension,
edition,
permissions,
isUserAdmin,
}: MessageItemProps & {
edition?: CreatorEditionResponse;
isUserAdmin?: boolean;
permissions?: ChannelById["permissions"];
listRef: RefObject<FlashList<any>>;
editMessageIdSharedValue: SharedValue<number | undefined>;
editMessageItemDimension: SharedValue<{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -260,7 +258,9 @@ export const MessageItem = memo(
style={{
gap: 12,
display:
messageNotViewable && !isUserAdmin ? "none" : undefined,
isByCreator && !permissions?.can_view_creator_messages
? "none"
: undefined,
}}
>
<Reaction
Expand Down Expand Up @@ -414,7 +414,7 @@ export const MessageItem = memo(
</LeanView>
</LeanView>

{messageNotViewable && !isUserAdmin ? (
{isByCreator && !permissions?.can_view_creator_messages ? (
<LeanView tw="-mb-0.5 -ml-2 -mt-0.5 select-none overflow-hidden px-2 py-0.5">
{Platform.OS === "web" ? (
// INFO: I had to do it like that because blur-sm would crash for no reason even with web prefix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ export const getChannelByIdCacheKey = (channelId: string | number) => {
export const useChannelById = (channelId?: string | number) => {
const queryState = useSWR<ChannelById>(
channelId ? getChannelByIdCacheKey(channelId) : null,
fetcher
fetcher,
{
focusThrottleInterval: 5000,
dedupingInterval: 5000,
revalidateIfStale: false,
}
);

return queryState;
Expand Down
9 changes: 8 additions & 1 deletion packages/app/components/creator-channels/messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit 31f326b

Please sign in to comment.