Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

ref(chat): on native, show messages as grouped by sender

Leonard Kim7187e540a800
diff --git a/react/features/chat/components/AbstractChatMessage.js b/react/features/chat/components/AbstractChatMessage.js
index 4ef592c8e4..822896fdbc 100644
--- a/react/features/chat/components/AbstractChatMessage.js
+++ b/react/features/chat/components/AbstractChatMessage.js
@@ -19,12 +19,24 @@ export type Props = {
*/
message: Object,
+ /**
+ * Whether or not the avatar image of the participant which sent the message
+ * should be displayed.
+ */
+ showAvatar: boolean,
+
/**
* Whether or not the name of the participant which sent the message should
* be displayed.
*/
showDisplayName: boolean,
+ /**
+ * Whether or not the time at which the message was sent should be
+ * displayed.
+ */
+ showTimestamp: boolean,
+
/**
* Invoked to receive translated strings.
*/
@@ -36,7 +48,9 @@ export type Props = {
*/
export default class AbstractChatMessage<P: Props> extends PureComponent<P> {
static defaultProps = {
- showDisplayName: true
+ showAvatar: false,
+ showDisplayName: false,
+ showTimestamp: false
};
}
diff --git a/react/features/chat/components/AbstractMessageContainer.js b/react/features/chat/components/AbstractMessageContainer.js
index ad1409c79c..c05b0714e9 100644
--- a/react/features/chat/components/AbstractMessageContainer.js
+++ b/react/features/chat/components/AbstractMessageContainer.js
@@ -39,7 +39,7 @@ export default class AbstractMessageContainer<P: Props> extends PureComponent<P>
if (message.id === currentGroupParticipantId) {
currentGrouping.push(message);
} else {
- groups.push(currentGrouping);
+ currentGrouping.length && groups.push(currentGrouping);
currentGrouping = [ message ];
currentGroupParticipantId = message.id;
diff --git a/react/features/chat/components/native/ChatMessage.js b/react/features/chat/components/native/ChatMessage.js
index f46146a8b7..993920b798 100644
--- a/react/features/chat/components/native/ChatMessage.js
+++ b/react/features/chat/components/native/ChatMessage.js
@@ -13,11 +13,6 @@ import AbstractChatMessage, {
} from '../AbstractChatMessage';
import styles from './styles';
-/**
- * Size of the rendered avatar in the message.
- */
-const AVATAR_SIZE = 32;
-
/**
* Formatter string to display the message timestamp.
*/
@@ -34,8 +29,6 @@ class ChatMessage extends AbstractChatMessage<Props> {
*/
render() {
const { message } = this.props;
- const timeStamp = getLocalizedDateFormatter(
- new Date(message.timestamp)).format(TIMESTAMP_FORMAT);
const localMessage = message.messageType === 'local';
// Style arrays that need to be updated in various scenarios, such as
@@ -60,18 +53,12 @@ class ChatMessage extends AbstractChatMessage<Props> {
return (
<View style = { styles.messageWrapper } >
- {
-
- // Avatar is only rendered for remote messages.
- !localMessage && this._renderAvatar()
- }
+ { this._renderAvatar() }
<View style = { detailsWrapperStyle }>
<View style = { textWrapperStyle } >
{
-
- // Display name is only rendered for remote
- // messages.
- !localMessage && this._renderDisplayName()
+ this.props.showDisplayName
+ && this._renderDisplayName()
}
<Text style = { styles.messageText }>
{ message.messageType === 'error'
@@ -82,9 +69,7 @@ class ChatMessage extends AbstractChatMessage<Props> {
: message.message }
</Text>
</View>
- <Text style = { styles.timeText }>
- { timeStamp }
- </Text>
+ { this.props.showTimestamp && this._renderTimestamp() }
</View>
</View>
);
@@ -96,13 +81,12 @@ class ChatMessage extends AbstractChatMessage<Props> {
* @returns {React$Element<*>}
*/
_renderAvatar() {
- const { _avatarURL } = this.props;
-
return (
<View style = { styles.avatarWrapper }>
- <Avatar
- size = { AVATAR_SIZE }
- uri = { _avatarURL } />
+ { this.props.showAvatar && <Avatar
+ size = { styles.avatarWrapper.width }
+ uri = { this.props._avatarURL } />
+ }
</View>
);
}
@@ -113,11 +97,26 @@ class ChatMessage extends AbstractChatMessage<Props> {
* @returns {React$Element<*>}
*/
_renderDisplayName() {
- const { message } = this.props;
-
return (
<Text style = { styles.displayName }>
- { message.displayName }
+ { this.props.message.displayName }
+ </Text>
+ );
+ }
+
+ /**
+ * Renders the time at which the message was sent.
+ *
+ * @returns {React$Element<*>}
+ */
+ _renderTimestamp() {
+ return (
+ <Text style = { styles.timeText }>
+ {
+ getLocalizedDateFormatter(
+ new Date(this.props.message.timestamp)
+ ).format(TIMESTAMP_FORMAT)
+ }
</Text>
);
}
diff --git a/react/features/chat/components/native/ChatMessageGroup.js b/react/features/chat/components/native/ChatMessageGroup.js
index 31ca2b5344..36d10534f0 100644
--- a/react/features/chat/components/native/ChatMessageGroup.js
+++ b/react/features/chat/components/native/ChatMessageGroup.js
@@ -68,9 +68,19 @@ export default class ChatMessageGroup extends Component<Props> {
* @param {Object} message - The chat message to render.
* @returns {React$Element<*>}
*/
- _renderMessage({ item: message }) {
+ _renderMessage({ index, item: message }) {
return (
- <ChatMessage message = { message } />
+ <ChatMessage
+ message = { message }
+ showAvatar = {
+ this.props.messages[0].messageType !== 'local'
+ && index === this.props.messages.length - 1
+ }
+ showDisplayName = {
+ this.props.messages[0].messageType === 'remote'
+ && index === this.props.messages.length - 1
+ }
+ showTimestamp = { index === 0 } />
);
}
}
diff --git a/react/features/chat/components/native/styles.js b/react/features/chat/components/native/styles.js
index fc4ca2fb4c..7a54d29e18 100644
--- a/react/features/chat/components/native/styles.js
+++ b/react/features/chat/components/native/styles.js
@@ -16,7 +16,8 @@ export default {
* Wrapper View for the avatar.
*/
avatarWrapper: {
- marginRight: 8
+ marginRight: 8,
+ width: 32
},
/**