Skip to content

Commit

Permalink
fix: enable frozen channel message actions behaviour (#2598)
Browse files Browse the repository at this point in the history
* fix: enable frozen channel message actions behaviour

* fix: remove disabled prop from MessageContext

* docs: remove disabled prop from message-context

* fix: remive disabled prop from useless component

* fix: message input disabled state

* fix: message input disabled state

* fix: channel frozen disabled behaviout
  • Loading branch information
khushal87 authored Aug 1, 2024
1 parent 3ae97ed commit eb4ae4c
Show file tree
Hide file tree
Showing 22 changed files with 176 additions and 467 deletions.
6 changes: 0 additions & 6 deletions docusaurus/docs/reactnative/contexts/message-context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ id: message-context
title: MessageContext
---

import Disabled from '../common-content/contexts/channel-context/disabled.mdx';

import Alignment from '../common-content/contexts/message-context/alignment.mdx';
import Files from '../common-content/contexts/message-context/files.mdx';
import GroupStyles from '../common-content/contexts/message-context/group_styles.mdx';
Expand Down Expand Up @@ -80,10 +78,6 @@ True if one of the following condition is true:
| ------- |
| boolean |

### disabled

<Disabled />

### files

<Files />
Expand Down
1 change: 0 additions & 1 deletion package/src/components/Channel/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2219,7 +2219,6 @@ const ChannelWithContext = <
CommandsButton,
compressImageQuality,
CooldownTimer,
disabled: disabledValue,
doDocUploadRequest,
doImageUploadRequest,
editing,
Expand Down
18 changes: 0 additions & 18 deletions package/src/components/Channel/__tests__/ownCapabilities.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,24 +314,6 @@ describe('Own capabilities', () => {
});
});

describe(`${allOwnCapabilities.sendMessage} capability`, () => {
it(`should not render SendMessageDisallowedIndicator when "${allOwnCapabilities.sendMessage}" capability is enabled`, async () => {
await generateChannelWithCapabilities([allOwnCapabilities.sendMessage]);
const { queryByTestId } = render(getComponent());

await waitFor(() => expect(!!queryByTestId('send-message-disallowed-indicator')).toBeFalsy());
});

it(`should render SendMessageDisallowedIndicator when "${allOwnCapabilities.sendMessage}" capability is disabled`, async () => {
await generateChannelWithCapabilities();
const { queryByTestId } = render(getComponent());

await waitFor(() =>
expect(!!queryByTestId('send-message-disallowed-indicator')).toBeTruthy(),
);
});
});

describe(`${allOwnCapabilities.sendLinks} capability`, () => {
it(`should not allow sending links when "${allOwnCapabilities.sendLinks}" capability is disabled`, async () => {
await generateChannelWithCapabilities([allOwnCapabilities.sendMessage]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const useCreateInputMessageInputContext = <
CommandsButton,
compressImageQuality,
CooldownTimer,
disabled,
doDocUploadRequest,
doImageUploadRequest,
editing,
Expand Down Expand Up @@ -96,7 +95,6 @@ export const useCreateInputMessageInputContext = <
CommandsButton,
compressImageQuality,
CooldownTimer,
disabled,
doDocUploadRequest,
doImageUploadRequest,
editing,
Expand Down Expand Up @@ -131,15 +129,7 @@ export const useCreateInputMessageInputContext = <
StartAudioRecordingButton,
UploadProgressIndicator,
}),
[
compressImageQuality,
channelId,
disabled,
editingDep,
initialValue,
maxMessageLength,
quotedMessageId,
],
[compressImageQuality, channelId, editingDep, initialValue, maxMessageLength, quotedMessageId],
);

return inputMessageInputContext;
Expand Down
18 changes: 3 additions & 15 deletions package/src/components/Message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ export type MessageActionHandlers<

export type MessagePropsWithContext<
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
> = Pick<
ChannelContextValue<StreamChatGenerics>,
'channel' | 'disabled' | 'enforceUniqueReaction' | 'members'
> &
> = Pick<ChannelContextValue<StreamChatGenerics>, 'channel' | 'enforceUniqueReaction' | 'members'> &
Pick<KeyboardContextValue, 'dismissKeyboard'> &
Partial<Omit<MessageContextValue<StreamChatGenerics>, 'groupStyles' | 'message'>> &
Pick<MessageContextValue<StreamChatGenerics>, 'groupStyles' | 'message'> &
Expand Down Expand Up @@ -245,7 +242,6 @@ const MessageWithContext = <
chatContext,
deleteMessage: deleteMessageFromContext,
deleteReaction,
disabled,
dismissKeyboard,
dismissKeyboardOnMessageTouch,
enableLongPress = true,
Expand Down Expand Up @@ -627,7 +623,7 @@ const MessageWithContext = <
};

const onLongPressMessage =
disabled || hasAttachmentActions || isBlockedMessage(message)
hasAttachmentActions || isBlockedMessage(message)
? () => null
: onLongPressMessageProp
? (payload?: TouchableHandlerPayload) =>
Expand Down Expand Up @@ -662,7 +658,6 @@ const MessageWithContext = <
actionsEnabled,
alignment,
channel,
disabled,
files: attachments.files,
goToMessage,
groupStyles,
Expand Down Expand Up @@ -780,7 +775,6 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
) => {
const {
chatContext: { mutedUsers: prevMutedUsers },
disabled: prevDisabled,
goToMessage: prevGoToMessage,
groupStyles: prevGroupStyles,
isAttachmentEqual,
Expand All @@ -794,7 +788,6 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
} = prevProps;
const {
chatContext: { mutedUsers: nextMutedUsers },
disabled: nextDisabled,
goToMessage: nextGoToMessage,
groupStyles: nextGroupStyles,
isTargetedMessage: nextIsTargetedMessage,
Expand All @@ -806,9 +799,6 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
t: nextT,
} = nextProps;

const disabledEqual = prevDisabled === nextDisabled;
if (!disabledEqual) return false;

const membersEqual = Object.keys(prevMembers).length === Object.keys(nextMembers).length;
if (!membersEqual) return false;

Expand Down Expand Up @@ -935,8 +925,7 @@ export const Message = <
>(
props: MessageProps<StreamChatGenerics>,
) => {
const { channel, disabled, enforceUniqueReaction, members } =
useChannelContext<StreamChatGenerics>();
const { channel, enforceUniqueReaction, members } = useChannelContext<StreamChatGenerics>();
const chatContext = useChatContext<StreamChatGenerics>();
const { dismissKeyboard } = useKeyboardContext();
const { setData } = useMessageOverlayContext<StreamChatGenerics>();
Expand All @@ -951,7 +940,6 @@ export const Message = <
{...{
channel,
chatContext,
disabled,
dismissKeyboard,
enforceUniqueReaction,
members,
Expand Down
11 changes: 1 addition & 10 deletions package/src/components/Message/MessageSimple/MessageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export type MessageContentPropsWithContext<
> = Pick<
MessageContextValue<StreamChatGenerics>,
| 'alignment'
| 'disabled'
| 'isEditedMessageOpen'
| 'goToMessage'
| 'groupStyles'
Expand Down Expand Up @@ -116,7 +115,6 @@ const MessageContentWithContext = <
additionalTouchableProps,
alignment,
Attachment,
disabled,
FileAttachmentGroup,
Gallery,
groupStyles,
Expand Down Expand Up @@ -272,7 +270,7 @@ const MessageContentWithContext = <
return (
<TouchableOpacity
activeOpacity={0.7}
disabled={disabled || preventPress}
disabled={preventPress}
onLongPress={(event) => {
if (onLongPress) {
onLongPress({
Expand Down Expand Up @@ -402,7 +400,6 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
nextProps: MessageContentPropsWithContext<StreamChatGenerics>,
) => {
const {
disabled: prevDisabled,
goToMessage: prevGoToMessage,
groupStyles: prevGroupStyles,
hasReactions: prevHasReactions,
Expand All @@ -418,7 +415,6 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
t: prevT,
} = prevProps;
const {
disabled: nextDisabled,
goToMessage: nextGoToMessage,
groupStyles: nextGroupStyles,
hasReactions: nextHasReactions,
Expand All @@ -433,9 +429,6 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
t: nextT,
} = nextProps;

const disabledEqual = prevDisabled === nextDisabled;
if (!disabledEqual) return false;

const hasReactionsEqual = prevHasReactions === nextHasReactions;
if (!hasReactionsEqual) return false;

Expand Down Expand Up @@ -554,7 +547,6 @@ export const MessageContent = <
) => {
const {
alignment,
disabled,
goToMessage,
groupStyles,
hasReactions,
Expand Down Expand Up @@ -598,7 +590,6 @@ export const MessageContent = <
additionalTouchableProps,
alignment,
Attachment,
disabled,
FileAttachmentGroup,
Gallery,
goToMessage,
Expand Down
16 changes: 2 additions & 14 deletions package/src/components/Message/MessageSimple/MessageSimple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ export type MessageSimplePropsWithContext<
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
> = Pick<
MessageContextValue<StreamChatGenerics>,
| 'alignment'
| 'channel'
| 'disabled'
| 'isEditedMessageOpen'
| 'groupStyles'
| 'hasReactions'
| 'message'
'alignment' | 'channel' | 'isEditedMessageOpen' | 'groupStyles' | 'hasReactions' | 'message'
> &
Pick<
MessagesContextValue<StreamChatGenerics>,
Expand Down Expand Up @@ -125,7 +119,6 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
) => {
const {
channel: prevChannel,
disabled: prevDisabled,
groupStyles: prevGroupStyles,
hasReactions: prevHasReactions,
isEditedMessageOpen: prevIsEditedMessageOpen,
Expand All @@ -134,17 +127,13 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
} = prevProps;
const {
channel: nextChannel,
disabled: nextDisabled,
groupStyles: nextGroupStyles,
hasReactions: nextHasReactions,
isEditedMessageOpen: nextIsEditedMessageOpen,
message: nextMessage,
myMessageTheme: nextMyMessageTheme,
} = nextProps;

const disabledEqual = prevDisabled === nextDisabled;
if (!disabledEqual) return false;

const hasReactionsEqual = prevHasReactions === nextHasReactions;
if (!hasReactionsEqual) return false;

Expand Down Expand Up @@ -231,7 +220,7 @@ export const MessageSimple = <
>(
props: MessageSimpleProps<StreamChatGenerics>,
) => {
const { alignment, channel, disabled, groupStyles, hasReactions, isEditedMessageOpen, message } =
const { alignment, channel, groupStyles, hasReactions, isEditedMessageOpen, message } =
useMessageContext<StreamChatGenerics>();
const {
enableMessageGroupingByUser,
Expand All @@ -246,7 +235,6 @@ export const MessageSimple = <
{...{
alignment,
channel,
disabled,
enableMessageGroupingByUser,
groupStyles,
hasReactions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const useCreateMessageContext = <
actionsEnabled,
alignment,
channel,
disabled,
files,
goToMessage,
groupStyles,
Expand Down Expand Up @@ -63,7 +62,6 @@ export const useCreateMessageContext = <
actionsEnabled,
alignment,
channel,
disabled,
files,
goToMessage,
groupStyles,
Expand Down Expand Up @@ -106,7 +104,6 @@ export const useCreateMessageContext = <
actionsEnabled,
quotedMessageDeletedValue,
alignment,
disabled,
goToMessage,
groupStylesLength,
hasReactions,
Expand Down
Loading

0 comments on commit eb4ae4c

Please sign in to comment.