|
|
@@ -13,11 +13,6 @@ import AbstractChatMessage, {
|
|
13
|
13
|
} from '../AbstractChatMessage';
|
|
14
|
14
|
import styles from './styles';
|
|
15
|
15
|
|
|
16
|
|
-/**
|
|
17
|
|
- * Size of the rendered avatar in the message.
|
|
18
|
|
- */
|
|
19
|
|
-const AVATAR_SIZE = 32;
|
|
20
|
|
-
|
|
21
|
16
|
/**
|
|
22
|
17
|
* Formatter string to display the message timestamp.
|
|
23
|
18
|
*/
|
|
|
@@ -34,8 +29,6 @@ class ChatMessage extends AbstractChatMessage<Props> {
|
|
34
|
29
|
*/
|
|
35
|
30
|
render() {
|
|
36
|
31
|
const { message } = this.props;
|
|
37
|
|
- const timeStamp = getLocalizedDateFormatter(
|
|
38
|
|
- new Date(message.timestamp)).format(TIMESTAMP_FORMAT);
|
|
39
|
32
|
const localMessage = message.messageType === 'local';
|
|
40
|
33
|
|
|
41
|
34
|
// Style arrays that need to be updated in various scenarios, such as
|
|
|
@@ -60,18 +53,12 @@ class ChatMessage extends AbstractChatMessage<Props> {
|
|
60
|
53
|
|
|
61
|
54
|
return (
|
|
62
|
55
|
<View style = { styles.messageWrapper } >
|
|
63
|
|
- {
|
|
64
|
|
-
|
|
65
|
|
- // Avatar is only rendered for remote messages.
|
|
66
|
|
- !localMessage && this._renderAvatar()
|
|
67
|
|
- }
|
|
|
56
|
+ { this._renderAvatar() }
|
|
68
|
57
|
<View style = { detailsWrapperStyle }>
|
|
69
|
58
|
<View style = { textWrapperStyle } >
|
|
70
|
59
|
{
|
|
71
|
|
-
|
|
72
|
|
- // Display name is only rendered for remote
|
|
73
|
|
- // messages.
|
|
74
|
|
- !localMessage && this._renderDisplayName()
|
|
|
60
|
+ this.props.showDisplayName
|
|
|
61
|
+ && this._renderDisplayName()
|
|
75
|
62
|
}
|
|
76
|
63
|
<Text style = { styles.messageText }>
|
|
77
|
64
|
{ message.messageType === 'error'
|
|
|
@@ -82,9 +69,7 @@ class ChatMessage extends AbstractChatMessage<Props> {
|
|
82
|
69
|
: message.message }
|
|
83
|
70
|
</Text>
|
|
84
|
71
|
</View>
|
|
85
|
|
- <Text style = { styles.timeText }>
|
|
86
|
|
- { timeStamp }
|
|
87
|
|
- </Text>
|
|
|
72
|
+ { this.props.showTimestamp && this._renderTimestamp() }
|
|
88
|
73
|
</View>
|
|
89
|
74
|
</View>
|
|
90
|
75
|
);
|
|
|
@@ -96,13 +81,12 @@ class ChatMessage extends AbstractChatMessage<Props> {
|
|
96
|
81
|
* @returns {React$Element<*>}
|
|
97
|
82
|
*/
|
|
98
|
83
|
_renderAvatar() {
|
|
99
|
|
- const { _avatarURL } = this.props;
|
|
100
|
|
-
|
|
101
|
84
|
return (
|
|
102
|
85
|
<View style = { styles.avatarWrapper }>
|
|
103
|
|
- <Avatar
|
|
104
|
|
- size = { AVATAR_SIZE }
|
|
105
|
|
- uri = { _avatarURL } />
|
|
|
86
|
+ { this.props.showAvatar && <Avatar
|
|
|
87
|
+ size = { styles.avatarWrapper.width }
|
|
|
88
|
+ uri = { this.props._avatarURL } />
|
|
|
89
|
+ }
|
|
106
|
90
|
</View>
|
|
107
|
91
|
);
|
|
108
|
92
|
}
|
|
|
@@ -113,11 +97,26 @@ class ChatMessage extends AbstractChatMessage<Props> {
|
|
113
|
97
|
* @returns {React$Element<*>}
|
|
114
|
98
|
*/
|
|
115
|
99
|
_renderDisplayName() {
|
|
116
|
|
- const { message } = this.props;
|
|
117
|
|
-
|
|
118
|
100
|
return (
|
|
119
|
101
|
<Text style = { styles.displayName }>
|
|
120
|
|
- { message.displayName }
|
|
|
102
|
+ { this.props.message.displayName }
|
|
|
103
|
+ </Text>
|
|
|
104
|
+ );
|
|
|
105
|
+ }
|
|
|
106
|
+
|
|
|
107
|
+ /**
|
|
|
108
|
+ * Renders the time at which the message was sent.
|
|
|
109
|
+ *
|
|
|
110
|
+ * @returns {React$Element<*>}
|
|
|
111
|
+ */
|
|
|
112
|
+ _renderTimestamp() {
|
|
|
113
|
+ return (
|
|
|
114
|
+ <Text style = { styles.timeText }>
|
|
|
115
|
+ {
|
|
|
116
|
+ getLocalizedDateFormatter(
|
|
|
117
|
+ new Date(this.props.message.timestamp)
|
|
|
118
|
+ ).format(TIMESTAMP_FORMAT)
|
|
|
119
|
+ }
|
|
121
|
120
|
</Text>
|
|
122
|
121
|
);
|
|
123
|
122
|
}
|