2019-05-05 15:34:37 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { FlatList } from 'react-native';
|
|
|
|
|
2019-10-15 14:08:23 +00:00
|
|
|
import { MESSAGE_TYPE_LOCAL, MESSAGE_TYPE_REMOTE } from '../../constants';
|
|
|
|
|
2019-05-05 15:34:37 +00:00
|
|
|
import ChatMessage from './ChatMessage';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The messages array to render.
|
|
|
|
*/
|
|
|
|
messages: Array<Object>
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a container to render all the chat messages in a conference.
|
|
|
|
*/
|
|
|
|
export default class ChatMessageGroup extends Component<Props> {
|
|
|
|
/**
|
|
|
|
* Instantiates a new instance of the component.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this._keyExtractor = this._keyExtractor.bind(this);
|
|
|
|
this._renderMessage = this._renderMessage.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements {@code Component#render}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<FlatList
|
|
|
|
data = { this.props.messages }
|
|
|
|
inverted = { true }
|
|
|
|
keyExtractor = { this._keyExtractor }
|
2021-11-16 13:42:02 +00:00
|
|
|
renderItem = { this._renderMessage } />
|
2019-05-05 15:34:37 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-11-04 21:10:43 +00:00
|
|
|
_keyExtractor: Object => string;
|
2019-05-05 15:34:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Key extractor for the flatlist.
|
|
|
|
*
|
|
|
|
* @param {Object} item - The flatlist item that we need the key to be
|
|
|
|
* generated for.
|
|
|
|
* @param {number} index - The index of the element.
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
_keyExtractor(item, index) {
|
|
|
|
return `key_${index}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
_renderMessage: Object => React$Element<*>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders a single chat message.
|
|
|
|
*
|
|
|
|
* @param {Object} message - The chat message to render.
|
|
|
|
* @returns {React$Element<*>}
|
|
|
|
*/
|
2019-05-06 18:21:41 +00:00
|
|
|
_renderMessage({ index, item: message }) {
|
2019-05-05 15:34:37 +00:00
|
|
|
return (
|
2019-05-06 18:21:41 +00:00
|
|
|
<ChatMessage
|
|
|
|
message = { message }
|
|
|
|
showAvatar = {
|
2019-10-15 14:08:23 +00:00
|
|
|
this.props.messages[0].messageType !== MESSAGE_TYPE_LOCAL
|
2019-05-06 18:21:41 +00:00
|
|
|
&& index === this.props.messages.length - 1
|
|
|
|
}
|
|
|
|
showDisplayName = {
|
2019-10-15 14:08:23 +00:00
|
|
|
this.props.messages[0].messageType === MESSAGE_TYPE_REMOTE
|
2019-05-06 18:21:41 +00:00
|
|
|
&& index === this.props.messages.length - 1
|
|
|
|
}
|
|
|
|
showTimestamp = { index === 0 } />
|
2019-05-05 15:34:37 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|