Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 0 additions & 14 deletions src/hooks/useHTMLTextDirection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,4 @@ const useHTMLTextDirection = (direction: HTMLTextDirection) => {
}, [direction]);
};

export const useMessageLayoutDirection = (direction: HTMLTextDirection, forceLeftToRightMessageLayout: boolean, loading: boolean) => {
useEffect(() => {
if (loading) return;
const messageListElements = document.getElementsByClassName('sendbird-conversation__messages');
if (messageListElements.length > 0) {
Array.from(messageListElements).forEach((elem: HTMLElement) => {
elem.dir = forceLeftToRightMessageLayout
? 'ltr'
: direction;
});
}
}, [direction, forceLeftToRightMessageLayout, loading]);
};

export default useHTMLTextDirection;
9 changes: 8 additions & 1 deletion src/modules/Channel/components/MessageList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { getMessagePartsInfo } from '../../../GroupChannel/components/MessageLis
import { GroupChannelMessageListProps } from '../../../GroupChannel/components/MessageList';
import { GroupChannelUIBasicProps } from '../../../GroupChannel/components/GroupChannelUI/GroupChannelUIView';
import { deleteNullish } from '../../../../utils/utils';
import { getHTMLTextDirection } from '../../../../utils';

const SCROLL_BOTTOM_PADDING = 50;

Expand Down Expand Up @@ -175,7 +176,13 @@ export const MessageList = (props: MessageListProps) => {
return (
<>
{!isScrolled && <PlaceHolder type={PlaceHolderTypes.LOADING} />}
<div className={`sendbird-conversation__messages ${className}`}>
<div
className={`sendbird-conversation__messages ${className}`}
dir={getHTMLTextDirection(
store?.config?.htmlTextDirection,
store?.config?.forceLeftToRightMessageLayout,
)}
>
<div className="sendbird-conversation__scroll-container">
<div className="sendbird-conversation__padding" />
<div
Expand Down
9 changes: 0 additions & 9 deletions src/modules/Channel/context/ChannelProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import { useSendMultipleFilesMessage } from './hooks/useSendMultipleFilesMessage
import { useHandleChannelPubsubEvents } from './hooks/useHandleChannelPubsubEvents';
import { PublishingModuleType } from '../../internalInterfaces';
import { ChannelActionTypes } from './dux/actionTypes';
import { useMessageLayoutDirection } from '../../../hooks/useHTMLTextDirection';

export { ThreadReplySelectType } from './const'; // export for external usage

Expand Down Expand Up @@ -212,8 +211,6 @@ const ChannelProvider = (props: ChannelContextProps) => {
imageCompression,
markAsReadScheduler,
groupChannel,
htmlTextDirection,
forceLeftToRightMessageLayout,
} = config;
const sdk = globalStore?.stores?.sdkStore?.sdk;
const sdkInit = globalStore?.stores?.sdkStore?.initialized;
Expand Down Expand Up @@ -381,12 +378,6 @@ const ChannelProvider = (props: ChannelContextProps) => {
markAsReadScheduler,
});

useMessageLayoutDirection(
htmlTextDirection,
forceLeftToRightMessageLayout,
loading,
);

// callbacks for Message CURD actions
const deleteMessage = useDeleteMessageCallback(
{ currentGroupChannel, messagesDispatcher },
Expand Down
10 changes: 8 additions & 2 deletions src/modules/GroupChannel/components/MessageList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useEffect, useState } from 'react';
import type { Member } from '@sendbird/chat/groupChannel';
import { useGroupChannelHandler } from '@sendbird/uikit-tools';

import { CoreMessageType, isSendableMessage } from '../../../../utils';
import { CoreMessageType, isSendableMessage, getHTMLTextDirection } from '../../../../utils';
import { EveryMessage, RenderMessageParamsType, TypingIndicatorType } from '../../../../types';

import PlaceHolder, { PlaceHolderTypes } from '../../../../ui/PlaceHolder';
Expand Down Expand Up @@ -160,7 +160,13 @@ export const MessageList = (props: GroupChannelMessageListProps) => {

return (
<>
<div className={`sendbird-conversation__messages ${className}`}>
<div
className={`sendbird-conversation__messages ${className}`}
dir={getHTMLTextDirection(
store?.config?.htmlTextDirection,
store?.config?.forceLeftToRightMessageLayout,
)}
>
<InfiniteList
ref={scrollRef}
initDeps={[channelUrl]}
Expand Down
9 changes: 1 addition & 8 deletions src/modules/GroupChannel/context/GroupChannelProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import PUBSUB_TOPICS, { PubSubSendMessagePayload } from '../../../lib/pubSub/top
import { PubSubTypes } from '../../../lib/pubSub';
import { useMessageActions } from './hooks/useMessageActions';
import { getIsReactionEnabled } from '../../../utils/getIsReactionEnabled';
import { useMessageLayoutDirection } from '../../../hooks/useHTMLTextDirection';

export { ThreadReplySelectType } from './const'; // export for external usage

Expand Down Expand Up @@ -146,7 +145,7 @@ export const GroupChannelProvider = (props: GroupChannelProviderProps) => {
const { config, stores } = useSendbirdStateContext();

const { sdkStore } = stores;
const { markAsReadScheduler, logger, htmlTextDirection, forceLeftToRightMessageLayout } = config;
const { markAsReadScheduler, logger } = config;

// State
const [quoteMessage, setQuoteMessage] = useState<SendableMessageType | null>(null);
Expand Down Expand Up @@ -262,12 +261,6 @@ export const GroupChannelProvider = (props: GroupChannelProviderProps) => {
if (_animatedMessageId) setAnimatedMessageId(_animatedMessageId);
}, [_animatedMessageId]);

useMessageLayoutDirection(
htmlTextDirection,
forceLeftToRightMessageLayout,
messageDataSource.loading,
);

const scrollToBottom = usePreservedCallback(async (animated?: boolean) => {
if (!scrollRef.current) return;

Expand Down
4 changes: 3 additions & 1 deletion src/modules/Thread/components/ThreadUI/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import useMemorizedThreadList from './useMemorizedThreadList';
import Label, { LabelTypography, LabelColors } from '../../../../ui/Label';
import { isAboutSame } from '../../context/utils';
import { MessageProvider } from '../../../Message/context/MessageProvider';
import { SendableMessageType } from '../../../../utils';
import { SendableMessageType, getHTMLTextDirection } from '../../../../utils';
import { classnames } from '../../../../utils/utils';

export interface ThreadUIProps {
Expand Down Expand Up @@ -52,6 +52,7 @@ const ThreadUI: React.FC<ThreadUIProps> = ({
}: ThreadUIProps): React.ReactElement => {
const {
stores,
config,
} = useSendbirdStateContext();
const currentUserId = stores?.sdkStore?.sdk?.currentUser?.userId;
const {
Expand Down Expand Up @@ -152,6 +153,7 @@ const ThreadUI: React.FC<ThreadUIProps> = ({
className={classnames('sendbird-thread-ui--scroll', 'sendbird-conversation__messages')}
ref={scrollRef}
onScroll={onScroll}
dir={getHTMLTextDirection(config?.htmlTextDirection, config?.forceLeftToRightMessageLayout)}
>
<MessageProvider message={parentMessage} isByMe={isByMe}>
{MemorizedParentMessageInfo}
Expand Down
12 changes: 1 addition & 11 deletions src/modules/Thread/context/ThreadProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import useSendVoiceMessageCallback from './hooks/useSendVoiceMessageCallback';
import { PublishingModuleType, useSendMultipleFilesMessage } from './hooks/useSendMultipleFilesMessage';
import { SendableMessageType } from '../../../utils';
import { useThreadFetchers } from './hooks/useThreadFetchers';
import { useMessageLayoutDirection } from '../../../hooks/useHTMLTextDirection';
import { ChannelStateTypes, ParentMessageStateTypes, ThreadListStateTypes } from '../types';

export interface ThreadProviderProps extends
Pick<UserProfileProviderProps, 'disableUserProfile' | 'renderUserProfile'> {
Expand Down Expand Up @@ -92,7 +90,7 @@ export const ThreadProvider = (props: ThreadProviderProps) => {
const { user } = userStore;
const sdkInit = sdkStore?.initialized;
// // config
const { logger, pubSub, htmlTextDirection, forceLeftToRightMessageLayout } = config;
const { logger, pubSub } = config;

const isMentionEnabled = config.groupChannel.enableMention;
const isReactionEnabled = config.groupChannel.enableReactions;
Expand Down Expand Up @@ -166,14 +164,6 @@ export const ThreadProvider = (props: ThreadProviderProps) => {
}
}, [stores.sdkStore.initialized, config.isOnline, initialize]);

useMessageLayoutDirection(
htmlTextDirection,
forceLeftToRightMessageLayout,
channelState === ChannelStateTypes.LOADING
|| threadListState === ThreadListStateTypes.LOADING
|| parentMessageState === ParentMessageStateTypes.LOADING,
);

const toggleReaction = useToggleReactionCallback({ currentChannel }, { logger });

// Send Message Hooks
Expand Down
4 changes: 4 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -990,3 +990,7 @@ export const isSendableMessage = (message?: BaseMessage | null): message is Send
export const isChannelJustCreated = (channel: GroupChannel): boolean => {
return isSameSecond(channel.createdAt, channel.invitedAt) && !channel.lastMessage;
};

export const getHTMLTextDirection = (direction: HTMLTextDirection, forceLeftToRightMessageLayout: boolean): string => {
return forceLeftToRightMessageLayout ? 'ltr' : direction;
};