Skip to content

Commit

Permalink
feat(chat): set limit for linkifying and replacing non unicode emoji …
Browse files Browse the repository at this point in the history
…messages
  • Loading branch information
Calinteodor committed Aug 7, 2024
1 parent b1c0cc5 commit ce103c3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
49 changes: 35 additions & 14 deletions react/features/chat/components/native/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Avatar from '../../../base/avatar/components/Avatar';
import { translate } from '../../../base/i18n/functions';
import Linkify from '../../../base/react/components/native/Linkify';
import { isGifMessage } from '../../../gifs/functions.native';
import { MESSAGE_TYPE_ERROR, MESSAGE_TYPE_LOCAL } from '../../constants';
import { CHAR_LIMIT, MESSAGE_TYPE_ERROR, MESSAGE_TYPE_LOCAL } from '../../constants';
import {
getCanReplyToMessage,
getFormattedTimestamp,
Expand Down Expand Up @@ -73,7 +73,7 @@ class ChatMessage extends Component<IChatMessageProps> {
messageBubbleStyle.push(styles.lobbyMessageBubble);
}

const messageText = replaceNonUnicodeEmojis(getMessageText(this.props.message));
const messageText = getMessageText(this.props.message);

return (
<View style = { styles.messageWrapper as ViewStyle } >
Expand All @@ -84,13 +84,7 @@ class ChatMessage extends Component<IChatMessageProps> {
{ this._renderDisplayName() }
{ isGifMessage(messageText)
? <GifMessage message = { messageText } />
: (
<Linkify
linkStyle = { styles.chatLink }
style = { styles.chatMessage }>
{ messageText }
</Linkify>
)}
: this._renderMessageTextComponent(messageText) }
{ this._renderPrivateNotice() }
</View>
{ this._renderPrivateReplyButton() }
Expand All @@ -104,7 +98,7 @@ class ChatMessage extends Component<IChatMessageProps> {
/**
* Renders the avatar of the sender.
*
* @returns {React$Element<*>}
* @returns {React.ReactElement<*>}
*/
_renderAvatar() {
const { message } = this.props;
Expand All @@ -123,7 +117,7 @@ class ChatMessage extends Component<IChatMessageProps> {
/**
* Renders the display name of the sender if necessary.
*
* @returns {React$Element<*> | null}
* @returns {React.ReactElement<*> | null}
*/
_renderDisplayName() {
const { message, showDisplayName } = this.props;
Expand All @@ -139,10 +133,36 @@ class ChatMessage extends Component<IChatMessageProps> {
);
}

/**
* Renders the message text based on number of characters.
*
* @param {string} messageText - The message text.
* @returns {React.ReactElement<*>}
*/
_renderMessageTextComponent(messageText: string) {

if (messageText.length >= CHAR_LIMIT) {
return (
<Text
style = { styles.chatMessage }>
{ messageText }
</Text>
);
}

return (
<Linkify
linkStyle = { styles.chatLink }
style = { styles.chatMessage }>
{ replaceNonUnicodeEmojis(messageText) }
</Linkify>
);
}

/**
* Renders the message privacy notice, if necessary.
*
* @returns {React$Element<*> | null}
* @returns {React.ReactElement<*> | null}
*/
_renderPrivateNotice() {
const { message, knocking } = this.props;
Expand All @@ -161,7 +181,7 @@ class ChatMessage extends Component<IChatMessageProps> {
/**
* Renders the private reply button, if necessary.
*
* @returns {React$Element<*> | null}
* @returns {React.ReactElement<*> | null}
*/
_renderPrivateReplyButton() {
const { message, canReply } = this.props;
Expand All @@ -186,7 +206,7 @@ class ChatMessage extends Component<IChatMessageProps> {
/**
* Renders the time at which the message was sent, if necessary.
*
* @returns {React$Element<*> | null}
* @returns {React.ReactElement<*> | null}
*/
_renderTimestamp() {
if (!this.props.showTimestamp) {
Expand All @@ -205,6 +225,7 @@ class ChatMessage extends Component<IChatMessageProps> {
* Maps part of the redux state to the props of this component.
*
* @param {Object} state - The Redux state.
* @param {IChatMessageProps} message - Message object.
* @returns {IProps}
*/
function _mapStateToProps(state: IReduxState, { message }: IChatMessageProps) {
Expand Down
2 changes: 2 additions & 0 deletions react/features/chat/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ export const TIMESTAMP_FORMAT = 'H:mm';
* The namespace for system messages.
*/
export const MESSAGE_TYPE_SYSTEM = 'system_chat_message';

export const CHAR_LIMIT = 500;
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import BaseTheme from '../../../base/ui/components/BaseTheme.native';
import Button from '../../../base/ui/components/native/Button';
import IconButton from '../../../base/ui/components/native/IconButton';
import { BUTTON_MODES, BUTTON_TYPES } from '../../../base/ui/constants.native';
import { CHAR_LIMIT } from '../../../chat/constants';
import { replaceNonUnicodeEmojis } from '../../../chat/functions';
import { NOTIFICATION_ICON, NOTIFICATION_TYPE } from '../../constants';
import { INotificationProps } from '../../types';
Expand Down Expand Up @@ -163,7 +164,7 @@ const Notification = ({
key = { index }
numberOfLines = { 3 }
style = { styles.contentText }>
{ replaceNonUnicodeEmojis(line) }
{ line.length >= CHAR_LIMIT ? line : replaceNonUnicodeEmojis(line) }
</Text>
))
}
Expand Down

0 comments on commit ce103c3

Please sign in to comment.