ref(chat): on web, move timestamp to chat message

This commit is contained in:
Leonard Kim 2019-05-06 12:30:38 -07:00 committed by virtuacoplenny
parent 7187e540a8
commit 504fadaf71
5 changed files with 63 additions and 34 deletions

View File

@ -287,13 +287,17 @@
&.local { &.local {
align-items: flex-end; align-items: flex-end;
.chatmessage {
background-color: $chatLocalMessageBackgroundColor;
border-radius: 6px 0px 6px 6px;
}
.display-name { .display-name {
display: none; display: none;
} }
.chatmessage { .timestamp {
background-color: $chatLocalMessageBackgroundColor; text-align: right;
border-radius: 6px 0px 6px 6px;
} }
} }

View File

@ -2,8 +2,14 @@
import { PureComponent } from 'react'; import { PureComponent } from 'react';
import { getLocalizedDateFormatter } from '../../base/i18n';
import { getAvatarURLByParticipantId } from '../../base/participants'; import { getAvatarURLByParticipantId } from '../../base/participants';
/**
* Formatter string to display the message timestamp.
*/
const TIMESTAMP_FORMAT = 'H:mm';
/** /**
* The type of the React {@code Component} props of {@code AbstractChatMessage}. * The type of the React {@code Component} props of {@code AbstractChatMessage}.
*/ */
@ -47,11 +53,15 @@ export type Props = {
* Abstract component to display a chat message. * Abstract component to display a chat message.
*/ */
export default class AbstractChatMessage<P: Props> extends PureComponent<P> { export default class AbstractChatMessage<P: Props> extends PureComponent<P> {
static defaultProps = { /**
showAvatar: false, * Returns the timestamp to display for the message.
showDisplayName: false, *
showTimestamp: false * @returns {string}
}; */
_getFormattedTimestamp() {
return getLocalizedDateFormatter(new Date(this.props.message.timestamp))
.format(TIMESTAMP_FORMAT);
}
} }
/** /**

View File

@ -3,7 +3,7 @@
import React from 'react'; import React from 'react';
import { Text, View } from 'react-native'; import { Text, View } from 'react-native';
import { getLocalizedDateFormatter, translate } from '../../../base/i18n'; import { translate } from '../../../base/i18n';
import { Avatar } from '../../../base/participants'; import { Avatar } from '../../../base/participants';
import { connect } from '../../../base/redux'; import { connect } from '../../../base/redux';
@ -13,11 +13,6 @@ import AbstractChatMessage, {
} from '../AbstractChatMessage'; } from '../AbstractChatMessage';
import styles from './styles'; import styles from './styles';
/**
* Formatter string to display the message timestamp.
*/
const TIMESTAMP_FORMAT = 'H:mm';
/** /**
* Renders a single chat message. * Renders a single chat message.
*/ */
@ -75,6 +70,8 @@ class ChatMessage extends AbstractChatMessage<Props> {
); );
} }
_getFormattedTimestamp: () => string;
/** /**
* Renders the avatar of the sender. * Renders the avatar of the sender.
* *
@ -112,11 +109,7 @@ class ChatMessage extends AbstractChatMessage<Props> {
_renderTimestamp() { _renderTimestamp() {
return ( return (
<Text style = { styles.timeText }> <Text style = { styles.timeText }>
{ { this._getFormattedTimestamp() }
getLocalizedDateFormatter(
new Date(this.props.message.timestamp)
).format(TIMESTAMP_FORMAT)
}
</Text> </Text>
); );
} }

View File

@ -56,14 +56,43 @@ class ChatMessage extends AbstractChatMessage<Props> {
}); });
return ( return (
<div>
<div className = 'chatmessage'> <div className = 'chatmessage'>
{ this.props.showDisplayName && <div className = 'display-name'> { this.props.showDisplayName && this._renderDisplayName() }
{ message.displayName }
</div> }
<div className = 'usermessage'> <div className = 'usermessage'>
{ processedMessage } { processedMessage }
</div> </div>
</div> </div>
{ this.props.showTimestamp && this._renderTimestamp() }
</div>
);
}
_getFormattedTimestamp: () => string;
/**
* Renders the display name of the sender.
*
* @returns {React$Element<*>}
*/
_renderDisplayName() {
return (
<div className = 'display-name'>
{ this.props.message.displayName }
</div>
);
}
/**
* Renders the time at which the message was sent.
*
* @returns {React$Element<*>}
*/
_renderTimestamp() {
return (
<div className = 'timestamp'>
{ this._getFormattedTimestamp() }
</div>
); );
} }
} }

View File

@ -3,8 +3,6 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import ChatMessage from './ChatMessage'; import ChatMessage from './ChatMessage';
import { getLocalizedDateFormatter } from '../../../base/i18n';
type Props = { type Props = {
/** /**
@ -43,8 +41,6 @@ class ChatMessageGroup extends Component<Props> {
return null; return null;
} }
const { timestamp } = messages[messagesLength - 1];
return ( return (
<div className = { `chat-message-group ${className}` }> <div className = { `chat-message-group ${className}` }>
{ {
@ -52,13 +48,10 @@ class ChatMessageGroup extends Component<Props> {
<ChatMessage <ChatMessage
key = { i } key = { i }
message = { message } message = { message }
showDisplayName = { i === 0 } /> showDisplayName = { i === 0 }
showTimestamp = { i === messages.length - 1 } />
)) ))
} }
<div className = 'chat-message-group-footer'>
{ getLocalizedDateFormatter(
new Date(timestamp)).format('H:mm') }
</div>
</div> </div>
); );
} }