Skip to content

Commit 75a5dfb

Browse files
author
jaapbakker88
authored
Merge pull request #547 from GetStream/CRS-289-react-reply-configurable
CRS-289: make reply/reactions available in messageActions
2 parents 18c4b26 + f147f1e commit 75a5dfb

File tree

6 files changed

+46
-6
lines changed

6 files changed

+46
-6
lines changed

src/components/Message/Message.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ const Message = (props) => {
7878
onUserHoverHandler: propOnUserHover,
7979
});
8080
const { isMyMessage, isAdmin, isModerator, isOwner } = useUserRole(message);
81+
const canReact = true;
82+
const canReply = true;
8183
const canEdit = isMyMessage || isModerator || isOwner || isAdmin;
8284
const canDelete = canEdit;
8385
const messageActionsHandler = useCallback(() => {
@@ -88,10 +90,21 @@ const Message = (props) => {
8890
return getMessageActions(messageActions, {
8991
canDelete,
9092
canEdit,
93+
canReply,
94+
canReact,
9195
canFlag: !isMyMessage,
9296
canMute: !isMyMessage && !!channelConfig?.mutes,
9397
});
94-
}, [channelConfig, message, messageActions, canDelete, canEdit, isMyMessage]);
98+
}, [
99+
channelConfig,
100+
message,
101+
messageActions,
102+
canDelete,
103+
canEdit,
104+
canReply,
105+
canReact,
106+
isMyMessage,
107+
]);
95108

96109
const actionsEnabled =
97110
message && message.type === 'regular' && message.status === 'received';

src/components/Message/MessageOptions.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, { useContext } from 'react';
33
import { useUserRole, useOpenThreadHandler } from './hooks';
44
import { ChannelContext } from '../../context';
55
import { MessageActions } from '../MessageActions';
6+
import { MESSAGE_ACTIONS } from './utils';
67
import { ThreadIcon, ReactionIcon } from './icons';
78

89
/**
@@ -28,9 +29,19 @@ const MessageOptionsComponent = (props) => {
2829
*/
2930
const { channel } = useContext(ChannelContext);
3031
const channelConfig = channel?.getConfig();
32+
const messageActions = props.getMessageActions();
33+
const shouldShowReactions =
34+
messageActions.indexOf(MESSAGE_ACTIONS.react) > -1 &&
35+
channelConfig &&
36+
channelConfig.reactions;
37+
3138
const shouldShowReplies =
32-
displayReplies && !threadList && channelConfig && channelConfig.replies;
33-
const shouldShowReactions = channelConfig && channelConfig.reactions;
39+
messageActions.indexOf(MESSAGE_ACTIONS.reply) > -1 &&
40+
displayReplies &&
41+
!threadList &&
42+
channelConfig &&
43+
channelConfig.replies;
44+
3445
if (
3546
!message ||
3647
message.type === 'error' ||
@@ -53,7 +64,7 @@ const MessageOptionsComponent = (props) => {
5364
<div
5465
data-testid="thread-action"
5566
onClick={propHandleOpenThread || handleOpenThread}
56-
className={`str-chat__message-${theme} str-chat__message-${theme}__actions__action--thread`}
67+
className={`str-chat__message-${theme}__actions__action str-chat__message-${theme}__actions__action--thread`}
5768
>
5869
<ThreadIcon />
5970
</div>

src/components/Message/__tests__/MessageCommerce.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async function renderMessageCommerce(
3737
>
3838
<MessageCommerce
3939
message={message}
40-
getMessageActions={() => ['flag', 'mute']}
40+
getMessageActions={() => ['flag', 'mute', 'react', 'reply']}
4141
{...props}
4242
/>
4343
</ChannelContext.Provider>,

src/components/Message/__tests__/MessageOptions.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from 'mock-builders';
1010
import { ChannelContext } from '../../../context';
1111
import { MessageActions as MessageActionsMock } from '../../MessageActions';
12+
import { MESSAGE_ACTIONS } from '../utils';
1213
import MessageOptions from '../MessageOptions';
1314

1415
jest.mock('../../MessageActions', () => ({
@@ -22,6 +23,7 @@ const defaultProps = {
2223
threadList: false,
2324
messageWrapperRef: { current: document.createElement('div') },
2425
onReactionListClick: () => {},
26+
getMessageActions: () => Object.keys(MESSAGE_ACTIONS),
2527
};
2628

2729
function generateAliceMessage(messageOptions) {

src/components/Message/__tests__/utils.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ describe('Message utils', () => {
7575
canEdit: true,
7676
canFlag: true,
7777
canMute: true,
78+
canReply: true,
79+
canReact: true,
7880
};
7981
const actions = Object.values(MESSAGE_ACTIONS);
8082

src/components/Message/utils.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export const MESSAGE_ACTIONS = {
4040
delete: 'delete',
4141
flag: 'flag',
4242
mute: 'mute',
43+
react: 'react',
44+
reply: 'reply',
4345
};
4446

4547
/**
@@ -48,12 +50,14 @@ export const MESSAGE_ACTIONS = {
4850
* canDelete?: boolean;
4951
* canMute?: boolean;
5052
* canFlag?: boolean;
53+
* canReact?: boolean;
54+
* canReply?: boolean;
5155
* }} Capabilities
5256
* @type {(actions: string[] | boolean, capabilities: Capabilities) => string[]} Typescript syntax
5357
*/
5458
export const getMessageActions = (
5559
actions,
56-
{ canDelete, canFlag, canEdit, canMute },
60+
{ canDelete, canFlag, canEdit, canMute, canReact, canReply },
5761
) => {
5862
const messageActionsAfterPermission = [];
5963
let messageActions = [];
@@ -83,6 +87,14 @@ export const getMessageActions = (
8387
messageActionsAfterPermission.push(MESSAGE_ACTIONS.mute);
8488
}
8589

90+
if (canReact && messageActions.indexOf(MESSAGE_ACTIONS.react) > -1) {
91+
messageActionsAfterPermission.push(MESSAGE_ACTIONS.react);
92+
}
93+
94+
if (canReply && messageActions.indexOf(MESSAGE_ACTIONS.reply) > -1) {
95+
messageActionsAfterPermission.push(MESSAGE_ACTIONS.reply);
96+
}
97+
8698
return messageActionsAfterPermission;
8799
};
88100

0 commit comments

Comments
 (0)