Skip to content

Commit 6e4afef

Browse files
chohongmbang9
andauthored
feat: Apply lastMessage suggestedReplies disable chat input flag (#957)
Fixes: [AC-1106](https://sendbird.atlassian.net/browse/AC-1106) ### Changelogs - Added `enableSuggestedReplies` global option - How to use? ```tsx <App appId={appId} userId={userId} uikitOptions={{ groupChannel: { // Below turns on the suggested replies feature. Default value is false. enableSuggestedReplies: true, } }} /> ``` - `MessageInput` is now being disabled if `channel.lastMessage.extendedMessagePayload['disable_chat_input']` is true [AC-1106]: https://sendbird.atlassian.net/browse/AC-1106?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --------- Co-authored-by: Hyungu Kang | Airen <[email protected]>
1 parent 99d00a6 commit 6e4afef

File tree

14 files changed

+62
-15
lines changed

14 files changed

+62
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
},
6969
"dependencies": {
7070
"@sendbird/chat": "^4.10.8",
71-
"@sendbird/uikit-tools": "0.0.1-alpha.58",
71+
"@sendbird/uikit-tools": "0.0.1-alpha.61",
7272
"css-vars-ponyfill": "^2.3.2",
7373
"date-fns": "^2.16.1",
7474
"dompurify": "^3.0.1"

src/lib/Sendbird.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ const SendbirdSDK = ({
383383
threadReplySelectType: getCaseResolvedThreadReplySelectType(configs.groupChannel.channel.threadReplySelectType).lowerCase,
384384
typingIndicatorTypes: configs.groupChannel.channel.typingIndicatorTypes,
385385
enableFeedback: configs.groupChannel.channel.enableFeedback,
386+
enableSuggestedReplies: configs.groupChannel.channel.enableSuggestedReplies,
386387
},
387388
openChannel: {
388389
enableOgtag:

src/lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export interface SendBirdStateConfig {
105105
threadReplySelectType: SBUConfig['groupChannel']['channel']['threadReplySelectType'];
106106
typingIndicatorTypes: SBUConfig['groupChannel']['channel']['typingIndicatorTypes'];
107107
enableFeedback: SBUConfig['groupChannel']['channel']['enableFeedback'];
108+
enableSuggestedReplies: SBUConfig['groupChannel']['channel']['enableSuggestedReplies'];
108109
},
109110
openChannel: {
110111
enableOgtag: SBUConfig['openChannel']['channel']['enableOgtag'];

src/lib/utils/uikitConfigMapper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export function uikitConfigMapper({
3636
},
3737
typingIndicatorTypes: uikitOptions.groupChannel?.typingIndicatorTypes,
3838
enableFeedback: uikitOptions.groupChannel?.enableFeedback,
39+
enableSuggestedReplies: uikitOptions.groupChannel?.enableSuggestedReplies,
3940
},
4041
groupChannelList: {
4142
enableTypingIndicator: uikitOptions.groupChannelList?.enableTypingIndicator ?? isTypingIndicatorEnabledOnChannelList,

src/modules/App/stories/integrated.stories.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ export const GroupChannel = () => {
351351
// enableTypingIndicator: false,
352352
typingIndicatorTypes: new Set([TypingIndicatorType.Bubble, TypingIndicatorType.Text]),
353353
enableFeedback: true, // This enables feedback message feature.
354+
enableSuggestedReplies: true, // This enables suggested replies feature.
354355
}
355356
}}
356357
imageCompression={{ compressionRate: sampleOptions.imageCompression ? 0.7 : 1 }}

src/modules/Channel/components/ChannelUI/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ const ChannelUI = (props: ChannelUIProps) => {
4444
isInvalid={isInvalid}
4545
renderChannelHeader={(props) => (<ChannelHeader {...props} />)}
4646
renderMessageList={(props) => (<MessageList {...props} />)}
47-
renderMessageInput={() => (<MessageInputWrapper {...props} />)}
47+
renderMessageInput={() => (
48+
props.renderMessageInput?.()
49+
?? <MessageInputWrapper {...props} />
50+
)}
4851
/>
4952
);
5053
};

src/modules/Channel/components/Message/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import type { UserMessage } from '@sendbird/chat/message';
32

43
import useSendbirdStateContext from '../../../../hooks/useSendbirdStateContext';
54
import { useChannelContext } from '../../context/ChannelProvider';
@@ -49,9 +48,10 @@ const Message = (props: MessageProps): React.ReactElement => {
4948
!initialized || isDisabledBecauseFrozen(currentGroupChannel) || isDisabledBecauseMuted(currentGroupChannel) || !config.isOnline
5049
}
5150
shouldRenderSuggestedReplies={
52-
message.messageId === currentGroupChannel?.lastMessage?.messageId
51+
config?.groupChannel?.enableSuggestedReplies
52+
&& message.messageId === currentGroupChannel?.lastMessage?.messageId
5353
// the options should appear only when there's no failed or pending messages
54-
&& localMessages.every((message) => (message as UserMessage).sendingStatus === 'succeeded')
54+
&& localMessages?.length === 0
5555
&& getSuggestedReplies(message).length > 0
5656
}
5757
isReactionEnabled={isReactionEnabled}

src/modules/Channel/components/MessageInputWrapper/index.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react';
22
import type { FileMessageCreateParams } from '@sendbird/chat/message';
33

4-
import type { SendableMessageType } from '../../../../utils';
4+
import { getSuggestedReplies, SendableMessageType } from '../../../../utils';
55
import MessageInputWrapperView from '../../../GroupChannel/components/MessageInputWrapper/MessageInputWrapperView';
66
import { useChannelContext } from '../../context/ChannelProvider';
7+
import useSendbirdStateContext from '../../../../hooks/useSendbirdStateContext';
78

89
export interface MessageInputWrapperProps {
910
value?: string;
@@ -15,18 +16,28 @@ export interface MessageInputWrapperProps {
1516
}
1617

1718
export const MessageInputWrapper = (props: MessageInputWrapperProps) => {
19+
const { config } = useSendbirdStateContext();
1820
const context = useChannelContext();
1921
const {
2022
currentGroupChannel,
23+
localMessages,
2124
sendMessage,
2225
sendFileMessage,
2326
sendVoiceMessage,
2427
sendMultipleFilesMessage,
2528
} = context;
2629

30+
const lastMessage = currentGroupChannel?.lastMessage;
31+
const isLastMessageSuggestedRepliesEnabled = config?.groupChannel?.enableSuggestedReplies
32+
&& getSuggestedReplies(lastMessage).length > 0
33+
&& localMessages?.length === 0;
34+
const disableMessageInput = props.disabled
35+
|| isLastMessageSuggestedRepliesEnabled && !!lastMessage.extendedMessagePayload?.['disable_chat_input'];
36+
2737
return (
2838
<MessageInputWrapperView
2939
{...props}
40+
disabled={disableMessageInput}
3041
{...context}
3142
currentChannel={currentGroupChannel}
3243
quoteMessage={context.quoteMessage}

src/modules/GroupChannel/components/GroupChannelUI/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { RenderCustomSeparatorProps, RenderMessageParamsType } from '../../../..
77
import { useGroupChannelContext } from '../../context/GroupChannelProvider';
88
import { GroupChannelUIView } from './GroupChannelUIView';
99
import type { MessageContentProps } from '../../../../ui/MessageContent';
10+
import MessageInputWrapper from '../MessageInputWrapper';
1011

1112
export interface GroupChannelUIProps {
1213
renderPlaceholderLoader?: () => React.ReactElement;
@@ -40,6 +41,10 @@ export const GroupChannelUI = (props: GroupChannelUIProps) => {
4041
requestedChannelUrl={channelUrl}
4142
loading={loading}
4243
isInvalid={channelUrl && !currentChannel}
44+
renderMessageInput={() => (
45+
props.renderMessageInput?.()
46+
?? <MessageInputWrapper {...props} />
47+
)}
4348
/>
4449
);
4550
};

src/modules/GroupChannel/components/Message/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const Message = (props: MessageProps): React.ReactElement => {
3838
const initialized = !loading && Boolean(currentChannel);
3939

4040
const shouldRenderSuggestedReplies = useIIFE(() => {
41+
if (!config?.groupChannel?.enableSuggestedReplies) return false;
4142
if (message.messageId !== currentChannel?.lastMessage?.messageId) return false;
4243
if (getSuggestedReplies(message).length === 0) return false;
4344
const lastMessage = messages[messages.length - 1];

0 commit comments

Comments
 (0)