Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Label, {
} from '../../../../ui/Label';

import EditDetailsModal from '../EditDetailsModal';
import { isDefaultChannelName } from '../../../../utils';

const ChannelProfile: React.FC = () => {
const state = useSendbirdStateContext();
Expand All @@ -28,10 +29,10 @@ const ChannelProfile: React.FC = () => {
const channel = channelSettingStore?.channel;

const channelName = useMemo(() => {
if (channel?.name && channel.name !== 'Group Channel') {
if (!isDefaultChannelName(channel)) {
return channel.name;
}
if (channel?.name === 'Group Channel' || !channel?.name) {
if (isDefaultChannelName(channel)) {
return (channel?.members || []).map((member) => member.nickname || stringSet.NO_NAME).join(', ');
}

Expand Down
5 changes: 3 additions & 2 deletions src/modules/ChannelSettings/components/LeaveChannel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Label, {
LabelTypography,
LabelColors,
} from '../../../../ui/Label';
import { isDefaultChannelName } from '../../../../utils';

export type LeaveChannelProps = {
onSubmit: () => void;
Expand All @@ -34,10 +35,10 @@ const LeaveChannel: React.FC<LeaveChannelProps> = (props: LeaveChannelProps) =>
const isOnline = state?.config?.isOnline;
const { isMobile } = useMediaQueryContext();
const getChannelName = (channel: GroupChannel | null) => {
if (channel?.name && channel?.name !== 'Group Channel') {
if (!isDefaultChannelName(channel)) {
return channel.name;
}
if (channel?.name === 'Group Channel' || !channel?.name) {
if (isDefaultChannelName(channel)) {
return (channel?.members || []).map((member) => member.nickname || stringSet.NO_NAME).join(', ');
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { GroupChannel } from '@sendbird/chat/groupChannel';
import { LabelStringSet } from '../../../../ui/Label';
import { isDefaultChannelName } from '../../../../utils';

export const getChannelTitle = (
channel: GroupChannel,
Expand All @@ -10,7 +11,7 @@ export const getChannelTitle = (
if (!channel?.name && !channel?.members) {
return LABEL_STRING_SET.NO_TITLE;
}
if (channel?.name && channel.name !== 'Group Channel') {
if (!isDefaultChannelName(channel)) {
return channel.name;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ import isToday from 'date-fns/isToday';
import format from 'date-fns/format';
import isThisYear from 'date-fns/isThisYear';
import isYesterday from 'date-fns/isYesterday';
import { isAudio, isGif, isImage, isTemplateMessage, isVideo, isVoiceMessageMimeType } from '../../../../utils';
import {
isAudio,
isDefaultChannelName,
isGif,
isImage,
isTemplateMessage,
isVideo,
isVoiceMessageMimeType,
} from '../../../../utils';
import { LabelStringSet } from '../../../../ui/Label';

export const getChannelTitle = (channel?: GroupChannel, currentUserId?: string, stringSet = LabelStringSet) => {
if (!channel?.name && !channel?.members) {
return stringSet.NO_TITLE;
}
if (channel?.name && channel.name !== 'Group Channel') {
if (!isDefaultChannelName(channel)) {
return channel.name;
}
if (channel?.members?.length === 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import MessageSearchItem from '../../../../ui/MessageSearchItem';
import PlaceHolder, { PlaceHolderTypes } from '../../../../ui/PlaceHolder';
import MessageSearchFileItem from '../../../../ui/MessageSearchFileItem';
import { ClientSentMessages } from '../../../../types';
import { isDefaultChannelName } from '../../../../utils';

export interface MessageSearchUIProps {
renderPlaceHolderError?: (props: void) => React.ReactElement;
Expand Down Expand Up @@ -75,13 +76,14 @@ export const MessageSearchUI: React.FC<MessageSearchUIProps> = ({
};

const getChannelName = () => {
if (currentChannel && currentChannel?.name && currentChannel?.name !== 'Group Channel') {
if (!currentChannel) return stringSet.NO_TITLE;

if (!isDefaultChannelName(currentChannel)) {
return currentChannel?.name;
}
if (currentChannel && (currentChannel?.name === 'Group Channel' || !currentChannel?.name)) {
if (isDefaultChannelName(currentChannel)) {
return currentChannel.members.map((member) => member.nickname || stringSet.NO_NAME).join(', ');
}
return stringSet.NO_TITLE;
};

if (isInvalid && searchString && requestString) {
Expand Down
12 changes: 12 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -994,3 +994,15 @@ export const isChannelJustCreated = (channel: GroupChannel): boolean => {
export const getHTMLTextDirection = (direction: HTMLTextDirection, forceLeftToRightMessageLayout: boolean): string => {
return forceLeftToRightMessageLayout ? 'ltr' : direction;
};

export const DEFAULT_GROUP_CHANNEL_NAME = 'Group Channel';

export const DEFAULT_AI_CHATBOT_CHANNEL_NAME = 'AI Chatbot Widget Channel';

export const isDefaultChannelName = (channel: GroupChannel) => {
return (
!channel?.name
|| channel.name === DEFAULT_GROUP_CHANNEL_NAME
|| channel.name === DEFAULT_AI_CHATBOT_CHANNEL_NAME
);
};