Skip to content

Commit fbe8fb8

Browse files
authored
Merge pull request #816 from GetStream/actions-box-functionality
updates actions box to not show up if user has no available actions
2 parents 3daf545 + cf828a6 commit fbe8fb8

File tree

5 files changed

+53
-10
lines changed

5 files changed

+53
-10
lines changed

src/components/Message/MessageLivestream.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
ReactionIcon,
2121
ThreadIcon,
2222
} from './icons';
23-
import { areMessageUIPropsEqual } from './utils';
23+
import { areMessageUIPropsEqual, showMessageActionsBox } from './utils';
2424

2525
import { Attachment as DefaultAttachment } from '../Attachment';
2626
import { Avatar as DefaultAvatar } from '../Avatar';
@@ -356,6 +356,8 @@ const MessageLivestreamActions = <
356356
const messageDeletedAt = !!message.deleted_at;
357357
const messageWrapper = messageWrapperRef?.current;
358358

359+
const showActionsBox = showMessageActionsBox(getMessageActions());
360+
359361
useEffect(() => {
360362
if (messageWrapper) {
361363
messageWrapper.addEventListener('mouseleave', hideOptions);
@@ -425,12 +427,14 @@ const MessageLivestreamActions = <
425427
<ThreadIcon />
426428
</span>
427429
)}
428-
<MessageActions
429-
{...props}
430-
customWrapperClass={''}
431-
getMessageActions={getMessageActions}
432-
inline
433-
/>
430+
{showActionsBox && (
431+
<MessageActions
432+
{...props}
433+
customWrapperClass={''}
434+
getMessageActions={getMessageActions}
435+
inline
436+
/>
437+
)}
434438
</div>
435439
);
436440
};

src/components/Message/MessageSimple.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
getReadByTooltipText,
1313
messageHasAttachments,
1414
messageHasReactions,
15+
showMessageActionsBox,
1516
} from './utils';
1617

1718
import { Attachment as DefaultAttachment } from '../Attachment';
@@ -82,6 +83,7 @@ const MessageSimpleWithContext = <
8283
editing,
8384
EditMessageInput = DefaultEditMessageForm,
8485
formatDate,
86+
getMessageActions,
8587
handleAction,
8688
handleOpenThread,
8789
handleReaction,
@@ -109,6 +111,8 @@ const MessageSimpleWithContext = <
109111
? 'str-chat__message str-chat__message--me str-chat__message-simple str-chat__message-simple--me'
110112
: 'str-chat__message str-chat__message-simple';
111113

114+
const showActionsBox = showMessageActionsBox(getMessageActions());
115+
112116
if (message.type === 'message.read' || message.type === 'message.date') {
113117
return null;
114118
}
@@ -208,6 +212,7 @@ const MessageSimpleWithContext = <
208212
<MessageText
209213
{...props}
210214
customOptionProps={{
215+
displayActions: showActionsBox,
211216
handleOpenThread,
212217
messageWrapperRef,
213218
}}

src/components/Message/MessageTeam.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import {
1111
ReactionIcon,
1212
ThreadIcon,
1313
} from './icons';
14-
import { areMessageUIPropsEqual, getReadByTooltipText } from './utils';
14+
import {
15+
areMessageUIPropsEqual,
16+
getReadByTooltipText,
17+
showMessageActionsBox,
18+
} from './utils';
1519

1620
import { Attachment as DefaultAttachment } from '../Attachment';
1721
import { Avatar as DefaultAvatar } from '../Avatar';
@@ -128,6 +132,8 @@ const MessageTeamWithContext = <
128132

129133
const channelConfig = propChannelConfig || channel?.getConfig();
130134

135+
const showActionsBox = showMessageActionsBox(getMessageActions());
136+
131137
const messageTextToRender =
132138
message.i18n?.[`${userLanguage}_text` as `${TranslationLanguages}_text`] ||
133139
message.text;
@@ -278,7 +284,7 @@ const MessageTeamWithContext = <
278284
<ThreadIcon />
279285
</span>
280286
)}
281-
{getMessageActions().length > 0 && (
287+
{showActionsBox && (
282288
<MessageActions
283289
addNotification={addNotification}
284290
customWrapperClass={''}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ async function renderMessageLivestream(
5353
userLanguage: 'en',
5454
}}
5555
>
56-
<MessageLivestream message={message} typing={false} {...props} />
56+
<MessageLivestream
57+
getMessageActions={() => []}
58+
message={message}
59+
typing={false}
60+
{...props}
61+
/>
5762
</TranslationContext.Provider>
5863
</ChannelContext.Provider>,
5964
);

src/components/Message/utils.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,29 @@ export const getMessageActions = (
205205
return messageActionsAfterPermission;
206206
};
207207

208+
export const showMessageActionsBox = (actions: MessageActionsArray) => {
209+
if (actions.length === 0) {
210+
return false;
211+
}
212+
213+
if (
214+
actions.length === 1 &&
215+
(actions.includes('react') || actions.includes('reply'))
216+
) {
217+
return false;
218+
}
219+
220+
if (
221+
actions.length === 2 &&
222+
actions.includes('react') &&
223+
actions.includes('reply')
224+
) {
225+
return false;
226+
}
227+
228+
return true;
229+
};
230+
208231
export const areMessagePropsEqual = <
209232
At extends DefaultAttachmentType = DefaultAttachmentType,
210233
Ch extends DefaultChannelType = DefaultChannelType,

0 commit comments

Comments
 (0)