Skip to content

Commit fe9a28e

Browse files
authored
fix: rename onUserProfileMessage to onStartDirectMessage (#1192)
[CLNP-4601](https://sendbird.atlassian.net/browse/CLNP-4601) ### Fix * Made `useUserProfileContext` hook and applied it ### Changelog * Renamed the prop `onUserProfileMessage` to `onStartDirectMessage` * Deprecated `onUserProfileMessage` prop in `SendbirdProvider` and `UserProfileProvider` * Deprecated `onUserProfileMessage` interface in `SendbirdStateContext` and `UserProfileContext` * Use a `onStartDirectMessage` instead. [CLNP-4601]: https://sendbird.atlassian.net/browse/CLNP-4601?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent acb6820 commit fe9a28e

File tree

20 files changed

+140
-161
lines changed

20 files changed

+140
-161
lines changed

src/lib/Sendbird.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,18 @@ export interface SendbirdProviderProps extends CommonUIKitConfigProps, React.Pro
104104
breakpoint?: string | boolean;
105105
htmlTextDirection?: HTMLTextDirection;
106106
forceLeftToRightMessageLayout?: boolean;
107-
renderUserProfile?: (props: RenderUserProfileProps) => React.ReactElement;
108-
onUserProfileMessage?: (channel: GroupChannel) => void;
109107
uikitOptions?: UIKitOptions;
110108
isUserIdUsedForNickname?: boolean;
111109
sdkInitParams?: SendbirdChatInitParams;
112110
customExtensionParams?: CustomExtensionParams;
113111
isMultipleFilesMessageEnabled?: boolean;
112+
// UserProfile
113+
renderUserProfile?: (props: RenderUserProfileProps) => React.ReactElement;
114+
onStartDirectMessage?: (channel: GroupChannel) => void;
115+
/**
116+
* @deprecated Please use `onStartDirectMessage` instead. It's renamed.
117+
*/
118+
onUserProfileMessage?: (channel: GroupChannel) => void;
114119

115120
// Customer provided callbacks
116121
eventHandlers?: SBUEventHandlers;
@@ -171,7 +176,8 @@ const SendbirdSDK = ({
171176
allowProfileEdit = false,
172177
disableMarkAsDelivered = false,
173178
renderUserProfile,
174-
onUserProfileMessage,
179+
onUserProfileMessage: _onUserProfileMessage,
180+
onStartDirectMessage: _onStartDirectMessage,
175181
breakpoint = false,
176182
isUserIdUsedForNickname = true,
177183
sdkInitParams,
@@ -181,6 +187,7 @@ const SendbirdSDK = ({
181187
htmlTextDirection = 'ltr',
182188
forceLeftToRightMessageLayout = false,
183189
}: SendbirdProviderProps): React.ReactElement => {
190+
const onStartDirectMessage = _onStartDirectMessage ?? _onUserProfileMessage;
184191
const { logLevel = '', userMention = {}, isREMUnitEnabled = false, pubSub: customPubSub } = config;
185192
const { isMobile } = useMediaQueryContext();
186193
const [logger, setLogger] = useState(LoggerFactory(logLevel as LogLevel));
@@ -332,7 +339,8 @@ const SendbirdSDK = ({
332339
config: {
333340
disableMarkAsDelivered,
334341
renderUserProfile,
335-
onUserProfileMessage,
342+
onStartDirectMessage,
343+
onUserProfileMessage: onStartDirectMessage, // legacy of onStartDirectMessage
336344
allowProfileEdit,
337345
isOnline,
338346
userId,

src/lib/UserProfileContext.tsx

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,64 @@
1-
import React from 'react';
1+
import React, { useContext } from 'react';
22
import type { GroupChannel } from '@sendbird/chat/groupChannel';
33
import type { RenderUserProfileProps } from '../types';
4+
import { useSendbirdStateContext } from './Sendbird';
45

56
interface UserProfileContextInterface {
6-
disableUserProfile: boolean;
77
isOpenChannel: boolean;
8+
disableUserProfile: boolean;
89
renderUserProfile?: (props: RenderUserProfileProps) => React.ReactElement;
10+
onStartDirectMessage?: (channel: GroupChannel) => void;
11+
12+
/**
13+
* @deprecated This prop has been renamed to `onStartDirectMessage`.
14+
*/
915
onUserProfileMessage?: (channel: GroupChannel) => void;
1016
}
1117

1218
/**
1319
* user profile goes deep inside the component tree
1420
* use this context as a short circuit to send in values
1521
*/
16-
const UserProfileContext = React.createContext<UserProfileContextInterface>({
22+
export const UserProfileContext = React.createContext<UserProfileContextInterface>({
1723
disableUserProfile: true,
1824
isOpenChannel: false,
1925
});
2026

21-
export type UserProfileProviderProps = React.PropsWithChildren<{
22-
disableUserProfile?: boolean;
23-
isOpenChannel?: boolean;
24-
renderUserProfile?: (props: RenderUserProfileProps) => React.ReactElement;
25-
onUserProfileMessage?: (channel: GroupChannel) => void;
26-
}>;
27+
export type UserProfileProviderProps = React.PropsWithChildren<
28+
Partial<UserProfileContextInterface>
29+
& {
30+
/** This prop is optional. It is no longer necessary to provide it because the value can be accessed through SendbirdStateContext. */
31+
disableUserProfile?: boolean;
32+
/** This prop is optional. It is no longer necessary to provide it because the value can be accessed through SendbirdStateContext. */
33+
renderUserProfile?: (props: RenderUserProfileProps) => React.ReactElement;
34+
}
35+
>;
36+
37+
export const useUserProfileContext = () => useContext(UserProfileContext);
2738

28-
const UserProfileProvider = ({
39+
export const UserProfileProvider = ({
2940
isOpenChannel = false,
30-
disableUserProfile = false,
31-
renderUserProfile,
32-
onUserProfileMessage,
41+
disableUserProfile: _disableUserProfile = false,
42+
renderUserProfile: _renderUserProfile,
43+
onUserProfileMessage: _onUserProfileMessage,
44+
onStartDirectMessage: _onStartDirectMessage,
3345
children,
3446
}: UserProfileProviderProps) => {
47+
const { config } = useSendbirdStateContext();
48+
const onStartDirectMessage = _onStartDirectMessage ?? _onUserProfileMessage ?? config.onStartDirectMessage;
49+
3550
return (
3651
<UserProfileContext.Provider
3752
value={{
3853
isOpenChannel,
39-
disableUserProfile,
40-
renderUserProfile,
41-
onUserProfileMessage,
54+
disableUserProfile: _disableUserProfile ?? !config.common.enableUsingDefaultUserProfile,
55+
renderUserProfile: _renderUserProfile ?? config.renderUserProfile,
56+
onStartDirectMessage,
57+
/** legacy of onStartDirectMessage */
58+
onUserProfileMessage: onStartDirectMessage,
4259
}}
4360
>
4461
{children}
4562
</UserProfileContext.Provider>
4663
);
4764
};
48-
49-
export { UserProfileContext, UserProfileProvider };

src/lib/types.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export interface SBUEventHandlers {
6565

6666
export interface SendBirdStateConfig {
6767
renderUserProfile?: (props: RenderUserProfileProps) => React.ReactElement;
68-
onUserProfileMessage?: (props: GroupChannel) => void;
68+
onStartDirectMessage?: (props: GroupChannel) => void;
6969
allowProfileEdit: boolean;
7070
isOnline: boolean;
7171
userId: string;
@@ -128,21 +128,29 @@ export interface SendBirdStateConfig {
128128
enableOgtag: SBUConfig['openChannel']['channel']['enableOgtag'];
129129
enableDocument: SBUConfig['openChannel']['channel']['input']['enableDocument'];
130130
},
131-
/** @deprecated Please use `common.enableUsingDefaultUserProfile` instead * */
131+
/**
132+
* @deprecated Please use `onStartDirectMessage` instead. It's renamed.
133+
*/
134+
onUserProfileMessage?: (props: GroupChannel) => void;
135+
/**
136+
* @deprecated Please use `!config.common.enableUsingDefaultUserProfile` instead.
137+
* Note that you should use the negation of `config.common.enableUsingDefaultUserProfile`
138+
* to replace `disableUserProfile`.
139+
*/
132140
disableUserProfile: boolean;
133-
/** @deprecated Please use `groupChannel.enableReactions` instead * */
141+
/** @deprecated Please use `config.groupChannel.enableReactions` instead * */
134142
isReactionEnabled: boolean;
135-
/** @deprecated Please use `groupChannel.enableMention` instead * */
143+
/** @deprecated Please use `config.groupChannel.enableMention` instead * */
136144
isMentionEnabled: boolean;
137-
/** @deprecated Please use `groupChannel.enableVoiceMessage` instead * */
145+
/** @deprecated Please use `config.groupChannel.enableVoiceMessage` instead * */
138146
isVoiceMessageEnabled?: boolean;
139-
/** @deprecated Please use `groupChannel.replyType` instead * */
147+
/** @deprecated Please use `config.groupChannel.replyType` instead * */
140148
replyType: ReplyType;
141-
/** @deprecated Please use `groupChannelSettings.enableMessageSearch` instead * */
149+
/** @deprecated Please use `config.groupChannelSettings.enableMessageSearch` instead * */
142150
showSearchIcon?: boolean;
143-
/** @deprecated Please use `groupChannelList.enableTypingIndicator` instead * */
151+
/** @deprecated Please use `config.groupChannelList.enableTypingIndicator` instead * */
144152
isTypingIndicatorEnabledOnChannelList?: boolean;
145-
/** @deprecated Please use `groupChannelList.enableMessageReceiptStatus` instead * */
153+
/** @deprecated Please use `config.groupChannelList.enableMessageReceiptStatus` instead * */
146154
isMessageReceiptStatusEnabledOnChannelList?: boolean;
147155
/** @deprecated Please use setCurrentTheme instead * */
148156
setCurrenttheme: (theme: 'light' | 'dark') => void;

src/modules/App/index.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,16 @@ export default function App(props: AppProps) {
139139
imageCompression={imageCompression}
140140
isMultipleFilesMessageEnabled={isMultipleFilesMessageEnabled}
141141
voiceRecord={voiceRecord}
142-
onUserProfileMessage={(channel) => {
142+
onStartDirectMessage={(channel) => {
143143
setCurrentChannel(channel);
144144
}}
145145
uikitOptions={uikitOptions}
146146
isUserIdUsedForNickname={isUserIdUsedForNickname}
147147
sdkInitParams={sdkInitParams}
148148
customExtensionParams={customExtensionParams}
149149
eventHandlers={eventHandlers}
150-
isTypingIndicatorEnabledOnChannelList={
151-
isTypingIndicatorEnabledOnChannelList
152-
}
153-
isMessageReceiptStatusEnabledOnChannelList={
154-
isMessageReceiptStatusEnabledOnChannelList
155-
}
150+
isTypingIndicatorEnabledOnChannelList={isTypingIndicatorEnabledOnChannelList}
151+
isMessageReceiptStatusEnabledOnChannelList={isMessageReceiptStatusEnabledOnChannelList}
156152
replyType={replyType}
157153
showSearchIcon={showSearchIcon}
158154
disableUserProfile={disableUserProfile}

src/modules/Channel/context/ChannelProvider.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import type {
1919
} from '@sendbird/chat/message';
2020
import type { EmojiContainer, SendbirdError, User } from '@sendbird/chat';
2121

22-
import { ReplyType, RenderUserProfileProps, Nullable } from '../../../types';
23-
import { UserProfileProvider } from '../../../lib/UserProfileContext';
22+
import { ReplyType, Nullable } from '../../../types';
23+
import { UserProfileProvider, UserProfileProviderProps } from '../../../lib/UserProfileContext';
2424
import useSendbirdStateContext from '../../../hooks/useSendbirdStateContext';
2525
import { CoreMessageType, SendableMessageType } from '../../../utils';
2626
import { ThreadReplySelectType } from './const';
@@ -61,7 +61,8 @@ export type ChannelQueries = {
6161
messageListParams?: MessageListParams;
6262
};
6363

64-
export type ChannelContextProps = {
64+
export interface ChannelContextProps extends
65+
Pick<UserProfileProviderProps, 'disableUserProfile' | 'renderUserProfile'> {
6566
children?: React.ReactElement;
6667
channelUrl: string;
6768
isReactionEnabled?: boolean;
@@ -82,17 +83,15 @@ export type ChannelContextProps = {
8283
replyType?: ReplyType;
8384
threadReplySelectType?: ThreadReplySelectType;
8485
queries?: ChannelQueries;
85-
renderUserProfile?: (props: RenderUserProfileProps) => React.ReactElement;
8686
filterMessageList?(messages: BaseMessage): boolean;
87-
disableUserProfile?: boolean;
8887
disableMarkAsRead?: boolean;
8988
onReplyInThread?: (props: { message: SendableMessageType }) => void;
9089
onQuoteMessageClick?: (props: { message: SendableMessageType }) => void;
9190
onMessageAnimated?: () => void;
9291
onMessageHighlighted?: () => void;
9392
scrollBehavior?: 'smooth' | 'auto';
9493
reconnectOnIdle?: boolean;
95-
};
94+
}
9695

9796
interface MessageStoreInterface {
9897
allMessages: CoreMessageType[];
@@ -209,7 +208,6 @@ const ChannelProvider = (props: ChannelContextProps) => {
209208
userId,
210209
isOnline,
211210
imageCompression,
212-
onUserProfileMessage,
213211
markAsReadScheduler,
214212
groupChannel,
215213
htmlTextDirection,
@@ -523,11 +521,7 @@ const ChannelProvider = (props: ChannelContextProps) => {
523521
isScrolled,
524522
setIsScrolled,
525523
}}>
526-
<UserProfileProvider
527-
disableUserProfile={props?.disableUserProfile ?? !config.common.enableUsingDefaultUserProfile}
528-
renderUserProfile={props?.renderUserProfile}
529-
onUserProfileMessage={onUserProfileMessage}
530-
>
524+
<UserProfileProvider {...props}>
531525
{children}
532526
</UserProfileProvider>
533527
</ChannelContext.Provider>

src/modules/ChannelList/context/ChannelListProvider.tsx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import {
1616
UnreadChannelFilter,
1717
} from '@sendbird/chat/groupChannel';
1818

19-
import { RenderUserProfileProps } from '../../../types';
20-
2119
import setupChannelList, { pubSubHandler, pubSubHandleRemover } from '../utils';
2220
import { uuidv4 } from '../../../utils/uuid';
2321
import { noop } from '../../../utils/utils';
@@ -26,7 +24,7 @@ import { DELIVERY_RECEIPT } from '../../../utils/consts';
2624
import * as channelListActions from '../dux/actionTypes';
2725
import { ChannelListActionTypes } from '../dux/actionTypes';
2826

29-
import { UserProfileProvider } from '../../../lib/UserProfileContext';
27+
import { UserProfileProvider, UserProfileProviderProps } from '../../../lib/UserProfileContext';
3028
import useSendbirdStateContext from '../../../hooks/useSendbirdStateContext';
3129
import channelListReducers from '../dux/reducers';
3230
import channelListInitialState from '../dux/initialState';
@@ -75,7 +73,8 @@ type OverrideInviteUserType = {
7573
channelType: CHANNEL_TYPE;
7674
};
7775

78-
export interface ChannelListProviderProps {
76+
export interface ChannelListProviderProps extends
77+
Pick<UserProfileProviderProps, 'disableUserProfile' | 'renderUserProfile'> {
7978
allowProfileEdit?: boolean;
8079
onBeforeCreateChannel?(users: Array<string>): GroupChannelCreateParams;
8180
overrideInviteUser?(params: OverrideInviteUserType): void;
@@ -86,8 +85,6 @@ export interface ChannelListProviderProps {
8685
queries?: ChannelListQueries;
8786
children?: React.ReactElement;
8887
className?: string | string[];
89-
renderUserProfile?: (props: RenderUserProfileProps) => React.ReactElement;
90-
disableUserProfile?: boolean;
9188
disableAutoSelect?: boolean;
9289
activeChannelUrl?: string;
9390
typingChannels?: Array<GroupChannel>;
@@ -142,7 +139,7 @@ const ChannelListProvider: React.FC<ChannelListProviderProps> = (props: ChannelL
142139
const globalStore = useSendbirdStateContext();
143140
const { config, stores } = globalStore;
144141
const { sdkStore } = stores;
145-
const { pubSub, logger, onUserProfileMessage } = config;
142+
const { pubSub, logger } = config;
146143
const {
147144
markAsDeliveredScheduler,
148145
disableMarkAsDelivered = false,
@@ -153,8 +150,6 @@ const ChannelListProvider: React.FC<ChannelListProviderProps> = (props: ChannelL
153150

154151
// derive some variables
155152
// enable if it is true at least once(both are false by default)
156-
const userDefinedDisableUserProfile = disableUserProfile ?? !config.common.enableUsingDefaultUserProfile;
157-
const userDefinedRenderProfile = config?.renderUserProfile;
158153
const enableEditProfile = allowProfileEdit || config.allowProfileEdit;
159154

160155
const userFilledChannelListQuery = queries?.channelListQuery;
@@ -384,11 +379,7 @@ const ChannelListProvider: React.FC<ChannelListProviderProps> = (props: ChannelL
384379
fetchChannelList,
385380
}}
386381
>
387-
<UserProfileProvider
388-
disableUserProfile={userDefinedDisableUserProfile ?? !config.common.enableUsingDefaultUserProfile}
389-
renderUserProfile={userDefinedRenderProfile}
390-
onUserProfileMessage={onUserProfileMessage}
391-
>
382+
<UserProfileProvider {...props}>
392383
<div className={`sendbird-channel-list ${className}`}>{children}</div>
393384
</UserProfileProvider>
394385
</ChannelListContext.Provider>

0 commit comments

Comments
 (0)