Skip to content

Commit

Permalink
fix: change Block user action to Ban user action
Browse files Browse the repository at this point in the history
  • Loading branch information
khushal87 committed Sep 2, 2024
1 parent 0b9f18a commit 781ba1d
Show file tree
Hide file tree
Showing 25 changed files with 70 additions and 70 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Function called when the _Block User_ action is invoked from message actions list.
This function does not override the default behavior of the _Block User_ action.
Function called when the _Ban User_ action is invoked from message actions list.
This function does not override the default behavior of the _Ban User_ action.
Please refer to [the guide on customizing message actions](../../../../guides/custom-message-actions.mdx) for details.

| Type |
Expand Down
6 changes: 3 additions & 3 deletions docusaurus/docs/reactnative/contexts/messages-context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import FormatDate from '../common-content/ui-components/channel/props/format_dat
import Gallery from '../common-content/ui-components/channel/props/gallery.mdx';
import Giphy from '../common-content/ui-components/channel/props/giphy.mdx';
import GiphyVersion from '../common-content/ui-components/channel/props/giphy_version.mdx';
import HandleBlock from '../common-content/ui-components/channel/props/handle_block.mdx';
import HandleBan from '../common-content/ui-components/channel/props/handle_ban.mdx';
import HandleCopy from '../common-content/ui-components/channel/props/handle_copy.mdx';
import HandleDelete from '../common-content/ui-components/channel/props/handle_delete.mdx';
import HandleEdit from '../common-content/ui-components/channel/props/handle_edit.mdx';
Expand Down Expand Up @@ -110,9 +110,9 @@ Id of current channel.

<FormatDate />

### <div class="label description">_forwarded from [Channel](../../core-components/channel#handleblock)_ props</div> `handleBlock` {#handleblock}
### <div class="label description">_forwarded from [Channel](../../core-components/channel#handleban)_ props</div> `handleBan` {#handleban}

<HandleBlock />
<HandleBan />

### <div class="label description">_forwarded from [Channel](../../core-components/channel#handlecopy)_ props</div> `handleCopy` {#handlecopy}

Expand Down
6 changes: 3 additions & 3 deletions docusaurus/docs/reactnative/core-components/channel.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import Giphy from '../common-content/ui-components/channel/props/giphy.mdx';
import GiphyEnabled from '../common-content/ui-components/channel/props/giphy_enabled.mdx';
import GiphyVersion from '../common-content/ui-components/channel/props/giphy_version.mdx';
import HandleAttachButtonPress from '../common-content/ui-components/channel/props/handle_attach_button_press.mdx';
import HandleBlock from '../common-content/ui-components/channel/props/handle_block.mdx';
import HandleBan from '../common-content/ui-components/channel/props/handle_ban.mdx';
import HandleCopy from '../common-content/ui-components/channel/props/handle_copy.mdx';
import HandleDelete from '../common-content/ui-components/channel/props/handle_delete.mdx';
import HandleEdit from '../common-content/ui-components/channel/props/handle_edit.mdx';
Expand Down Expand Up @@ -486,9 +486,9 @@ The max allowable is 255, which when reached displays as `255+`.

<HandleAttachButtonPress />

### `handleBlock`
### `handleBan`

<HandleBlock />
<HandleBan />

### `handleCopy`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ These functions will be called right before the underlying default handlers.
Please note that these intercepts will neither change the standard functions nor block them.
:::
- `handleBlock`
- `handleBan`
- `handleCopy`
- `handleDelete`
- `handleEdit`
Expand Down
6 changes: 3 additions & 3 deletions docusaurus/docs/reactnative/object-types/message_action.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ Callback when user presses the action button.

Type of the action performed.

| Type |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| enum('blockUser', 'copyMessage', 'deleteMessage', 'editMessage', 'flagMessage', 'muteUser', 'pinMessage', 'selectReaction', 'reply', 'retry', 'quotedReply', 'threadReply', 'unpinMessage') |
| Type |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| enum('banUser', 'copyMessage', 'deleteMessage', 'editMessage', 'flagMessage', 'muteUser', 'pinMessage', 'selectReaction', 'reply', 'retry', 'quotedReply', 'threadReply', 'unpinMessage') |

### icon

Expand Down
10 changes: 6 additions & 4 deletions package/src/components/Channel/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export type ChannelPropsWithContext<
| 'getMessagesGroupStyles'
| 'Giphy'
| 'giphyVersion'
| 'handleBlock'
| 'handleBan'
| 'handleCopy'
| 'handleDelete'
| 'handleEdit'
Expand Down Expand Up @@ -481,7 +481,7 @@ const ChannelWithContext = <
giphyEnabled,
giphyVersion = 'fixed_height',
handleAttachButtonPress,
handleBlock,
handleBan,
handleCopy,
handleDelete,
handleEdit,
Expand Down Expand Up @@ -660,7 +660,9 @@ const ChannelWithContext = <

if (messageId) {
loadChannelAroundMessage({ messageId });
} else if (
}
// The condition, where if the count of unread messages is greater than 4, then scroll to the first unread message.
else if (
initialScrollToFirstUnreadMessage &&
channel.countUnread() > scrollToFirstUnreadThreshold
) {
Expand Down Expand Up @@ -2310,7 +2312,7 @@ const ChannelWithContext = <
getMessagesGroupStyles,
Giphy,
giphyVersion,
handleBlock,
handleBan,
handleCopy,
handleDelete,
handleEdit,
Expand Down
10 changes: 5 additions & 5 deletions package/src/components/Channel/__tests__/ownCapabilities.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@ describe('Own capabilities', () => {
});

describe(`${allOwnCapabilities.banChannelMembers} capability`, () => {
it(`should render "Block User" message action when ${allOwnCapabilities.banChannelMembers} capability is enabled`, async () => {
it(`should render "Ban User" message action when ${allOwnCapabilities.banChannelMembers} capability is enabled`, async () => {
await generateChannelWithCapabilities([allOwnCapabilities.banChannelMembers]);
const { queryByTestId } = await renderChannelAndOpenMessageActionsList(receivedMessage);
expect(!!queryByTestId('blockUser-list-item')).toBeTruthy();
expect(!!queryByTestId('banUser-list-item')).toBeTruthy();
});

it(`should not render "Block User" message action when ${allOwnCapabilities.banChannelMembers} capability is disabled`, async () => {
it(`should not render "Ban User" message action when ${allOwnCapabilities.banChannelMembers} capability is disabled`, async () => {
await generateChannelWithCapabilities();

const { queryByTestId } = await renderChannelAndOpenMessageActionsList(receivedMessage);
expect(!!queryByTestId('blockUser-list-item')).toBeFalsy();
expect(!!queryByTestId('banUser-list-item')).toBeFalsy();
});

it(`should override capability from "overrideOwnCapability.banChannelMembers" prop`, async () => {
Expand All @@ -128,7 +128,7 @@ describe('Own capabilities', () => {
banChannelMembers: false,
},
});
expect(!!queryByTestId('blockUser-list-item')).toBeFalsy();
expect(!!queryByTestId('banUser-list-item')).toBeFalsy();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const useCreateMessagesContext = <
getMessagesGroupStyles,
Giphy,
giphyVersion,
handleBlock,
handleBan,
handleCopy,
handleDelete,
handleEdit,
Expand Down Expand Up @@ -128,7 +128,7 @@ export const useCreateMessagesContext = <
getMessagesGroupStyles,
Giphy,
giphyVersion,
handleBlock,
handleBan,
handleCopy,
handleDelete,
handleEdit,
Expand Down
10 changes: 5 additions & 5 deletions package/src/components/Message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export type MessagePropsWithContext<
| 'deleteMessage'
| 'dismissKeyboardOnMessageTouch'
| 'forceAlignMessages'
| 'handleBlock'
| 'handleBan'
| 'handleCopy'
| 'handleDelete'
| 'handleEdit'
Expand Down Expand Up @@ -249,7 +249,7 @@ const MessageWithContext = <
forceAlignMessages = false,
goToMessage,
groupStyles = ['bottom'],
handleBlock,
handleBan,
handleCopy,
handleDelete,
handleEdit,
Expand Down Expand Up @@ -507,7 +507,7 @@ const MessageWithContext = <
});

const {
blockUser,
banUser,
copyMessage,
deleteMessage,
editMessage,
Expand All @@ -525,7 +525,7 @@ const MessageWithContext = <
deleteMessage: deleteMessageFromContext,
deleteReaction,
enforceUniqueReaction,
handleBlock,
handleBan,
handleCopy,
handleDelete,
handleEdit,
Expand Down Expand Up @@ -564,7 +564,7 @@ const MessageWithContext = <
typeof messageActionsProp !== 'function'
? messageActionsProp
: messageActionsProp({
blockUser,
banUser,
copyMessage,
deleteMessage,
dismissOverlay,
Expand Down
16 changes: 8 additions & 8 deletions package/src/components/Message/hooks/useMessageActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const useMessageActions = <
deleteMessage: deleteMessageFromContext,
deleteReaction,
enforceUniqueReaction,
handleBlock,
handleBan,
handleCopy,
handleDelete,
handleEdit,
Expand All @@ -65,7 +65,7 @@ export const useMessageActions = <
MessagesContextValue<StreamChatGenerics>,
| 'deleteMessage'
| 'sendReaction'
| 'handleBlock'
| 'handleBan'
| 'handleCopy'
| 'handleDelete'
| 'handleEdit'
Expand Down Expand Up @@ -138,20 +138,20 @@ export const useMessageActions = <
(mute) => mute.user.id === client.userID && mute.target.id === message.user?.id,
);

const blockUser: MessageActionType = {
const banUser: MessageActionType = {
action: async () => {
setOverlay('none');
if (message.user?.id) {
if (handleBlock) {
handleBlock(message);
if (handleBan) {
handleBan(message);
}

await handleToggleBanUser();
}
},
actionType: 'blockUser',
actionType: 'banUser',
icon: <UserDelete pathFill={grey} />,
title: message.user?.banned ? t('Unblock User') : t('Block User'),
title: message.user?.banned ? t('Unban User') : t('Ban User'),
};

const copyMessage: MessageActionType | undefined =
Expand Down Expand Up @@ -307,7 +307,7 @@ export const useMessageActions = <
};

return {
blockUser,
banUser,
copyMessage,
deleteMessage,
editMessage,
Expand Down
8 changes: 3 additions & 5 deletions package/src/components/Message/utils/messageActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { MessageActionType } from '../../MessageOverlay/MessageActionListIt
export type MessageActionsParams<
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
> = {
blockUser: MessageActionType;
banUser: MessageActionType;
deleteMessage: MessageActionType;
dismissOverlay: () => void;
editMessage: MessageActionType;
Expand All @@ -31,7 +31,7 @@ export type MessageActionsProp<
export const messageActions = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>({
blockUser,
banUser,
copyMessage,
deleteMessage,
editMessage,
Expand Down Expand Up @@ -89,9 +89,7 @@ export const messageActions = <
actions.push(unpinMessage);
}

if (!isMyMessage && ownCapabilities.banChannelMembers) {
actions.push(blockUser);
}
actions.push(banUser);

if (
(isMyMessage && ownCapabilities.deleteOwnMessage) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { DefaultStreamChatGenerics } from '../../types/types';
import type { MessageOverlayPropsWithContext } from '../MessageOverlay/MessageOverlay';

export type ActionType =
| 'blockUser'
| 'banUser'
| 'copyMessage'
| 'deleteMessage'
| 'editMessage'
Expand All @@ -32,7 +32,7 @@ export type MessageActionType = {
action: () => void;
/**
* Type of the action performed.
* Eg: 'blockUser', 'copyMessage', 'deleteMessage', 'editMessage', 'flagMessage', 'muteUser', 'pinMessage', 'selectReaction', 'reply', 'retry', 'quotedReply', 'threadReply', 'unpinMessage'
* Eg: 'banUser', 'copyMessage', 'deleteMessage', 'editMessage', 'flagMessage', 'muteUser', 'pinMessage', 'selectReaction', 'reply', 'retry', 'quotedReply', 'threadReply', 'unpinMessage'
*/
actionType: ActionType;
/**
Expand Down
4 changes: 2 additions & 2 deletions package/src/contexts/messagesContext/MessagesContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export type MessagesContextValue<
*/
forceAlignMessages?: Alignment | boolean;
getMessagesGroupStyles?: typeof getGroupStyles;
handleBlock?: (message: MessageType<StreamChatGenerics>) => Promise<void>;
handleBan?: (message: MessageType<StreamChatGenerics>) => Promise<void>;
/** Handler to access when a copy message action is invoked */
handleCopy?: (message: MessageType<StreamChatGenerics>) => Promise<void>;
/** Handler to access when a delete message action is invoked */
Expand Down Expand Up @@ -380,7 +380,7 @@ export type MessagesContextValue<
* ```
* <Channel
* messageActions={({
* blockUser,
* banUser,
* copyMessage,
* deleteMessage,
* editMessage,
Expand Down
4 changes: 2 additions & 2 deletions package/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Also send to channel": "Also send to channel",
"Are you sure you want to permanently delete this message?": "Are you sure you want to permanently delete this message?",
"Are you sure?": "Are you sure?",
"Block User": "Block User",
"Ban User": "Ban User",
"Cancel": "Cancel",
"Cannot Flag Message": "Cannot Flag Message",
"Consider how your comment might make others feel and be sure to follow our Community Guidelines": "Consider how your comment might make others feel and be sure to follow our Community Guidelines",
Expand Down Expand Up @@ -67,7 +67,7 @@
"Slow mode ON": "Slow mode ON",
"The message has been reported to a moderator.": "The message has been reported to a moderator.",
"Thread Reply": "Thread Reply",
"Unblock User": "Unblock User",
"Unban User": "Unban User",
"Unknown User": "Unknown User",
"Unmute User": "Unmute User",
"Unpin from Conversation": "Unpin from Conversation",
Expand Down
6 changes: 3 additions & 3 deletions package/src/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Also send to channel": "Tambiรฉn enviar al canal",
"Are you sure you want to permanently delete this message?": "ยฟEstรกs seguro de que deseas eliminar permanentemente este mensaje?",
"Are you sure?": "ยฟEstรกs seguro?",
"Block User": "Bloquear usuario",
"Ban User": "Bloquear Usuario",
"Cancel": "Cancelar",
"Cannot Flag Message": "No se puede reportar el mensaje",
"Consider how your comment might make others feel and be sure to follow our Community Guidelines": "Considera cรณmo tu comentario podrรญa hacer sentir a los demรกs y asegรบrate de seguir nuestras Normas de la Comunidad",
Expand Down Expand Up @@ -67,8 +67,8 @@
"Slow mode ON": "Modo lento ACTIVADO",
"The message has been reported to a moderator.": "El mensaje ha sido reportado a un moderador.",
"Thread Reply": "Respuesta de hilo",
"Unblock User": "Desbloquear usuario",
"Unknown User": "Usuario desconocido",
"Unban User": "Desbloquear usuario",
"Unknown User": "Desbloquear Usuario",
"Unmute User": "Activar sonido del usuario",
"Unpin from Conversation": "Desmarcar de la conversaciรณn",
"Unread Messages": "Mensajes no leรญdos",
Expand Down
4 changes: 2 additions & 2 deletions package/src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Also send to channel": "Envoyer รฉgalement ร  la chaรฎne",
"Are you sure you want to permanently delete this message?": "รŠtes-vous sรปr de vouloir supprimer dรฉfinitivement ce message?",
"Are you sure?": "Es-tu sรปr ?",
"Block User": "Bloquer un utilisateur",
"Ban User": "Bannir Utilisateur",
"Cancel": "Annuler",
"Cannot Flag Message": "Impossible de signaler le message",
"Consider how your comment might make others feel and be sure to follow our Community Guidelines": "Considรฉrez comment votre commentaire pourrait faire sentir les autres et assurez-vous de suivre nos directives communautaires",
Expand Down Expand Up @@ -67,7 +67,7 @@
"Slow mode ON": "Mode lent activรฉ",
"The message has been reported to a moderator.": "Le message a รฉtรฉ signalรฉ ร  un modรฉrateur.",
"Thread Reply": "Rรฉponse ร  la discussion",
"Unblock User": "Dรฉbloquer Utilisateur",
"Unban User": "Dรฉbannir Utilisateur",
"Unknown User": "Utilisateur inconnu",
"Unmute User": "Activer le son de Utilisateur",
"Unpin from Conversation": "Dรฉcrocher de la conversation",
Expand Down
4 changes: 2 additions & 2 deletions package/src/i18n/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Also send to channel": "ืฉืœื—/ื™ ื”ื•ื“ืขื” ืœืฉื™ื—ื”",
"Are you sure you want to permanently delete this message?": "ื”ืื ืืช/ื” ื‘ื˜ื•ื—/ื” ืฉืืช/ื” ืจื•ืฆื” ืœืžื—ื•ืง ืืช ื”ื”ื•ื“ืขื” ื”ื–ื• ืœืฆืžื™ืชื•ืช?",
"Are you sure?": "ื”ืื ืืชื” ื‘ื˜ื•ื—?",
"Block User": "ื—ืกื•ื ืžืฉืชืžืฉ",
"Ban User": "ืœื—ืกื•ื ืžืฉืชืžืฉ",
"Cancel": "ื‘ื™ื˜ื•ืœ",
"Cannot Flag Message": "ืกื™ืžื•ืŸ ื”ื•ื“ืขื” ืœื ืืคืฉืจื™",
"Consider how your comment might make others feel and be sure to follow our Community Guidelines": "ืฉืงื•ืœ ืื™ืš ื”ืชื’ื•ื‘ื” ืฉืœืš ืขืฉื•ื™ื” ืœื”ืฉืคื™ืข ืขืœ ืื—ืจื™ื ื•ื•ื•ื“ื ืฉืืชื” ืขื•ืงื‘ ืื—ืจ ื”ื”ื ื—ื™ื•ืช ืฉืœ ื”ืงื”ื™ืœื” ืฉืœื ื•",
Expand Down Expand Up @@ -67,7 +67,7 @@
"Slow mode ON": "ืžืฆื‘ ืื™ื˜ื™ ืžื•ืคืขืœ",
"The message has been reported to a moderator.": "ื”ื”ื•ื“ืขื” ื“ื•ื•ื—ื” ืœืžื ื”ืœ",
"Thread Reply": "ื”ื’ื‘/ื™ ื‘ืฉืจืฉื•ืจ",
"Unblock User": "ื‘ื˜ืœ/ื™ ื—ืกื™ืžืช ืžืฉืชืžืฉ",
"Unban User": "ืœื‘ื˜ืœ ื—ืกื™ืžืช ืžืฉืชืžืฉ",
"Unknown User": "ืžืฉืชืžืฉ ืœื ื™ื“ื•ืข",
"Unmute User": "ื‘ื˜ืœ/ื™ ื”ืฉืชืงืช ืžืฉืชืžืฉ",
"Unpin from Conversation": "ื‘ื˜ืœ/ื™ ื”ืฆืžื“ื” ืœืฉื™ื—ื”",
Expand Down
Loading

0 comments on commit 781ba1d

Please sign in to comment.