Skip to content

Commit a49aa64

Browse files
authored
Merge branch 'main' into release/v3.15.10
2 parents c25863f + 6cb6ba0 commit a49aa64

File tree

9 files changed

+119
-29
lines changed

9 files changed

+119
-29
lines changed

src/modules/ChannelSettings/components/ChannelProfile/index.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Label, {
1313
} from '../../../../ui/Label';
1414

1515
import EditDetailsModal from '../EditDetailsModal';
16+
import { isDefaultChannelName } from '../../../../utils';
1617

1718
const ChannelProfile: React.FC = () => {
1819
const state = useSendbirdStateContext();
@@ -28,14 +29,11 @@ const ChannelProfile: React.FC = () => {
2829
const channel = channelSettingStore?.channel;
2930

3031
const channelName = useMemo(() => {
31-
if (channel?.name && channel.name !== 'Group Channel') {
32-
return channel.name;
33-
}
34-
if (channel?.name === 'Group Channel' || !channel?.name) {
35-
return (channel?.members || []).map((member) => member.nickname || stringSet.NO_NAME).join(', ');
36-
}
32+
if (!channel?.name && !channel?.members) return stringSet.NO_TITLE;
3733

38-
return stringSet.NO_TITLE;
34+
if (isDefaultChannelName(channel)) return (channel?.members || []).map((member) => member.nickname || stringSet.NO_NAME).join(', ');
35+
36+
return channel.name;
3937
}, [channel?.name, channel?.joinedMemberCount]);
4038

4139
return (

src/modules/ChannelSettings/components/LeaveChannel/index.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Label, {
1515
LabelTypography,
1616
LabelColors,
1717
} from '../../../../ui/Label';
18+
import { isDefaultChannelName } from '../../../../utils';
1819

1920
export type LeaveChannelProps = {
2021
onSubmit: () => void;
@@ -34,14 +35,11 @@ const LeaveChannel: React.FC<LeaveChannelProps> = (props: LeaveChannelProps) =>
3435
const isOnline = state?.config?.isOnline;
3536
const { isMobile } = useMediaQueryContext();
3637
const getChannelName = (channel: GroupChannel | null) => {
37-
if (channel?.name && channel?.name !== 'Group Channel') {
38-
return channel.name;
39-
}
40-
if (channel?.name === 'Group Channel' || !channel?.name) {
41-
return (channel?.members || []).map((member) => member.nickname || stringSet.NO_NAME).join(', ');
42-
}
38+
if (!channel?.name && !channel?.members) return stringSet.NO_TITLE;
4339

44-
return stringSet.NO_TITLE;
40+
if (isDefaultChannelName(channel)) return (channel?.members || []).map((member) => member.nickname || stringSet.NO_NAME).join(', ');
41+
42+
return channel.name;
4543
};
4644
if (isMobile) {
4745
return (

src/modules/GroupChannel/components/GroupChannelHeader/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { GroupChannel } from '@sendbird/chat/groupChannel';
22
import { LabelStringSet } from '../../../../ui/Label';
3+
import { isDefaultChannelName } from '../../../../utils';
34

45
export const getChannelTitle = (
56
channel: GroupChannel,
@@ -10,7 +11,7 @@ export const getChannelTitle = (
1011
if (!channel?.name && !channel?.members) {
1112
return LABEL_STRING_SET.NO_TITLE;
1213
}
13-
if (channel?.name && channel.name !== 'Group Channel') {
14+
if (!isDefaultChannelName(channel)) {
1415
return channel.name;
1516
}
1617

src/modules/GroupChannel/context/GroupChannelProvider.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,15 @@ export const GroupChannelProvider = (props: GroupChannelProviderProps) => {
320320
},
321321
);
322322

323-
const messageActions = useMessageActions({ ...props, ...messageDataSource, scrollToBottom, quoteMessage, replyType });
323+
const messageActions = useMessageActions({
324+
...props,
325+
...messageDataSource,
326+
scrollToBottom,
327+
quoteMessage,
328+
replyType,
329+
pubSub: config.pubSub,
330+
channel: currentChannel,
331+
});
324332

325333
return (
326334
<GroupChannelContext.Provider

src/modules/GroupChannel/context/hooks/useMessageActions.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { match } from 'ts-pattern';
22
import { useCallback } from 'react';
33
import { useGroupChannelMessages } from '@sendbird/uikit-tools';
4-
import { MessageMetaArray } from '@sendbird/chat/message';
54
import type {
65
BaseMessageCreateParams,
76
FileMessage,
@@ -12,6 +11,7 @@ import type {
1211
UserMessageCreateParams,
1312
UserMessageUpdateParams,
1413
} from '@sendbird/chat/message';
14+
import { MessageMetaArray } from '@sendbird/chat/message';
1515

1616
import {
1717
META_ARRAY_MESSAGE_TYPE_KEY,
@@ -20,10 +20,12 @@ import {
2020
VOICE_MESSAGE_FILE_NAME,
2121
VOICE_MESSAGE_MIME_TYPE,
2222
} from '../../../../utils/consts';
23-
import type { SendableMessageType, CoreMessageType } from '../../../../utils';
23+
import type { CoreMessageType, SendableMessageType } from '../../../../utils';
2424
import type { ReplyType } from '../../../../types';
2525
import type { GroupChannelProviderProps, OnBeforeHandler } from '../GroupChannelProvider';
2626
import useSendbirdStateContext from '../../../../hooks/useSendbirdStateContext';
27+
import { PublishingModuleType, PUBSUB_TOPICS, SBUGlobalPubSub } from '../../../../lib/pubSub/topics';
28+
import { GroupChannel } from '@sendbird/chat/groupChannel';
2729

2830
type MessageListDataSource = ReturnType<typeof useGroupChannelMessages>;
2931
type MessageActions = {
@@ -38,6 +40,8 @@ interface Params extends GroupChannelProviderProps, MessageListDataSource {
3840
scrollToBottom(animated?: boolean): Promise<void>;
3941
quoteMessage?: SendableMessageType | null;
4042
replyType: ReplyType;
43+
pubSub: SBUGlobalPubSub;
44+
channel: GroupChannel;
4145
}
4246

4347
const pass = <T>(value: T) => value;
@@ -68,6 +72,8 @@ export function useMessageActions(params: Params): MessageActions {
6872
scrollToBottom,
6973
quoteMessage,
7074
replyType,
75+
channel,
76+
pubSub,
7177
} = params;
7278
const { eventHandlers } = useSendbirdStateContext();
7379
const buildInternalMessageParams = useCallback(
@@ -185,9 +191,18 @@ export function useMessageActions(params: Params): MessageActions {
185191
async (messageId: number, params: UserMessageUpdateParams) => {
186192
const internalParams = buildInternalMessageParams<UserMessageUpdateParams>(params);
187193
const processedParams = await processParams(onBeforeUpdateUserMessage, internalParams, 'update');
188-
return updateUserMessage(messageId, processedParams);
194+
return updateUserMessage(messageId, processedParams)
195+
.then((message) => {
196+
pubSub.publish(PUBSUB_TOPICS.UPDATE_USER_MESSAGE, {
197+
channel,
198+
message,
199+
publishingModules: [PublishingModuleType.CHANNEL],
200+
});
201+
202+
return message;
203+
});
189204
},
190-
[buildInternalMessageParams, updateUserMessage, processParams],
205+
[buildInternalMessageParams, updateUserMessage, processParams, channel?.url],
191206
),
192207
};
193208
}

src/modules/GroupChannelList/components/GroupChannelListItem/utils.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@ import isToday from 'date-fns/isToday';
33
import format from 'date-fns/format';
44
import isThisYear from 'date-fns/isThisYear';
55
import isYesterday from 'date-fns/isYesterday';
6-
import { isAudio, isGif, isImage, isTemplateMessage, isVideo, isVoiceMessageMimeType } from '../../../../utils';
6+
import {
7+
isAudio,
8+
isDefaultChannelName,
9+
isGif,
10+
isImage,
11+
isTemplateMessage,
12+
isVideo,
13+
isVoiceMessageMimeType,
14+
} from '../../../../utils';
715
import { LabelStringSet } from '../../../../ui/Label';
816

917
export const getChannelTitle = (channel?: GroupChannel, currentUserId?: string, stringSet = LabelStringSet) => {
1018
if (!channel?.name && !channel?.members) {
1119
return stringSet.NO_TITLE;
1220
}
13-
if (channel?.name && channel.name !== 'Group Channel') {
21+
if (!isDefaultChannelName(channel)) {
1422
return channel.name;
1523
}
1624
if (channel?.members?.length === 1) {

src/modules/MessageSearch/components/MessageSearchUI/index.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import MessageSearchItem from '../../../../ui/MessageSearchItem';
99
import PlaceHolder, { PlaceHolderTypes } from '../../../../ui/PlaceHolder';
1010
import MessageSearchFileItem from '../../../../ui/MessageSearchFileItem';
1111
import { ClientSentMessages } from '../../../../types';
12+
import { isDefaultChannelName } from '../../../../utils';
1213

1314
export interface MessageSearchUIProps {
1415
renderPlaceHolderError?: (props: void) => React.ReactElement;
@@ -75,13 +76,13 @@ export const MessageSearchUI: React.FC<MessageSearchUIProps> = ({
7576
};
7677

7778
const getChannelName = () => {
78-
if (currentChannel && currentChannel?.name && currentChannel?.name !== 'Group Channel') {
79-
return currentChannel?.name;
79+
if (!currentChannel?.name && !currentChannel?.members) {
80+
return stringSet.NO_TITLE;
8081
}
81-
if (currentChannel && (currentChannel?.name === 'Group Channel' || !currentChannel?.name)) {
82-
return currentChannel.members.map((member) => member.nickname || stringSet.NO_NAME).join(', ');
83-
}
84-
return stringSet.NO_TITLE;
82+
83+
if (isDefaultChannelName(currentChannel)) return currentChannel.members.map((member) => member.nickname || stringSet.NO_NAME).join(', ');
84+
85+
return currentChannel?.name;
8586
};
8687

8788
if (isInvalid && searchString && requestString) {

src/utils/__tests__/utils.spec.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import {
33
isFileMessage,
44
isUrl,
55
isUserMessage,
6-
isMultipleFilesMessage,
6+
isMultipleFilesMessage, isDefaultChannelName, DEFAULT_GROUP_CHANNEL_NAME, DEFAULT_AI_CHATBOT_CHANNEL_NAME,
77
} from '../index';
88
import { AdminMessage, FileMessage, MultipleFilesMessage, UserMessage } from '@sendbird/chat/message';
99
import { deleteNullish } from '../utils';
1010
import { isMobileIOS } from '../browser';
11+
import { GroupChannel } from '@sendbird/chat/groupChannel';
1112

1213
describe('Global-utils: verify message type util functions', () => {
1314
it('should return true for each message', () => {
@@ -234,3 +235,51 @@ describe('deleteNullish', () => {
234235
expect(component({ a: null, b: '3', c: 4 })).toEqual({ a: 1, b: '3', c: 4 });
235236
});
236237
});
238+
239+
describe('isDefaultChannelName', () => {
240+
it('return true if channel is undefined', () => {
241+
const result = isDefaultChannelName(undefined);
242+
243+
expect(result).toBe(true);
244+
});
245+
246+
it('return true if channel name is undefined', () => {
247+
const channel = {
248+
name: undefined,
249+
} as GroupChannel;
250+
251+
const result = isDefaultChannelName(channel);
252+
253+
expect(result).toBe(true);
254+
});
255+
256+
it('return true if channel name is the default group channel name', () => {
257+
const channel = {
258+
name: DEFAULT_GROUP_CHANNEL_NAME,
259+
} as GroupChannel;
260+
261+
const result = isDefaultChannelName(channel);
262+
263+
expect(result).toBe(true);
264+
});
265+
266+
it('return true if channel name is the default AI chatbot channel name', () => {
267+
const channel = {
268+
name: DEFAULT_AI_CHATBOT_CHANNEL_NAME,
269+
} as GroupChannel;
270+
271+
const result = isDefaultChannelName(channel);
272+
273+
expect(result).toBe(true);
274+
});
275+
276+
it('return false if channel name is not default', () => {
277+
const channel = {
278+
name: 'test-channel-name',
279+
} as GroupChannel;
280+
281+
const result = isDefaultChannelName(channel);
282+
283+
expect(result).toBe(false);
284+
});
285+
});

src/utils/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,3 +994,15 @@ export const isChannelJustCreated = (channel: GroupChannel): boolean => {
994994
export const getHTMLTextDirection = (direction: HTMLTextDirection, forceLeftToRightMessageLayout: boolean): string => {
995995
return forceLeftToRightMessageLayout ? 'ltr' : direction;
996996
};
997+
998+
export const DEFAULT_GROUP_CHANNEL_NAME = 'Group Channel';
999+
1000+
export const DEFAULT_AI_CHATBOT_CHANNEL_NAME = 'AI Chatbot Widget Channel';
1001+
1002+
export const isDefaultChannelName = (channel: GroupChannel) => {
1003+
return (
1004+
!channel?.name
1005+
|| channel.name === DEFAULT_GROUP_CHANNEL_NAME
1006+
|| channel.name === DEFAULT_AI_CHATBOT_CHANNEL_NAME
1007+
);
1008+
};

0 commit comments

Comments
 (0)