|
@@ -12,8 +12,8 @@ import AbstractChat, {
|
12
|
12
|
type Props
|
13
|
13
|
} from '../AbstractChat';
|
14
|
14
|
import ChatInput from './ChatInput';
|
15
|
|
-import ChatMessageGroup from './ChatMessageGroup';
|
16
|
15
|
import DisplayNameForm from './DisplayNameForm';
|
|
16
|
+import MessageContainer from './MessageContainer';
|
17
|
17
|
|
18
|
18
|
/**
|
19
|
19
|
* React Component for holding the chat feature in a side panel that slides in
|
|
@@ -27,12 +27,6 @@ class Chat extends AbstractChat<Props> {
|
27
|
27
|
*/
|
28
|
28
|
_isExited: boolean;
|
29
|
29
|
|
30
|
|
- /**
|
31
|
|
- * Reference to the HTML element at the end of the list of displayed chat
|
32
|
|
- * messages. Used for scrolling to the end of the chat messages.
|
33
|
|
- */
|
34
|
|
- _messagesListEnd: ?HTMLElement;
|
35
|
|
-
|
36
|
30
|
/**
|
37
|
31
|
* Initializes a new {@code Chat} instance.
|
38
|
32
|
*
|
|
@@ -43,32 +37,9 @@ class Chat extends AbstractChat<Props> {
|
43
|
37
|
super(props);
|
44
|
38
|
|
45
|
39
|
this._isExited = true;
|
46
|
|
- this._messagesListEnd = null;
|
47
|
40
|
|
48
|
41
|
// Bind event handlers so they are only bound once for every instance.
|
49
|
42
|
this._renderPanelContent = this._renderPanelContent.bind(this);
|
50
|
|
- this._setMessageListEndRef = this._setMessageListEndRef.bind(this);
|
51
|
|
- }
|
52
|
|
-
|
53
|
|
- /**
|
54
|
|
- * Implements React's {@link Component#componentDidMount()}.
|
55
|
|
- *
|
56
|
|
- * @inheritdoc
|
57
|
|
- */
|
58
|
|
- componentDidMount() {
|
59
|
|
- this._scrollMessagesToBottom();
|
60
|
|
- }
|
61
|
|
-
|
62
|
|
- /**
|
63
|
|
- * Updates chat input focus.
|
64
|
|
- *
|
65
|
|
- * @inheritdoc
|
66
|
|
- */
|
67
|
|
- componentDidUpdate(prevProps) {
|
68
|
|
- if (this.props._messages !== prevProps._messages) {
|
69
|
|
- this._scrollMessagesToBottom();
|
70
|
|
-
|
71
|
|
- }
|
72
|
43
|
}
|
73
|
44
|
|
74
|
45
|
/**
|
|
@@ -126,28 +97,9 @@ class Chat extends AbstractChat<Props> {
|
126
|
97
|
* @returns {ReactElement}
|
127
|
98
|
*/
|
128
|
99
|
_renderChat() {
|
129
|
|
- const groupedMessages = this._getMessagesGroupedBySender();
|
130
|
|
-
|
131
|
|
- const messages = groupedMessages.map((group, index) => {
|
132
|
|
- const messageType = group[0] && group[0].messageType;
|
133
|
|
-
|
134
|
|
- return (
|
135
|
|
- <ChatMessageGroup
|
136
|
|
- className = { messageType || 'remote' }
|
137
|
|
- key = { index }
|
138
|
|
- messages = { group } />
|
139
|
|
- );
|
140
|
|
- });
|
141
|
|
-
|
142
|
|
- messages.push(<div
|
143
|
|
- key = 'end-marker'
|
144
|
|
- ref = { this._setMessageListEndRef } />);
|
145
|
|
-
|
146
|
100
|
return (
|
147
|
101
|
<>
|
148
|
|
- <div id = 'chatconversation'>
|
149
|
|
- { messages }
|
150
|
|
- </div>
|
|
102
|
+ <MessageContainer messages = { this.props._messages } />
|
151
|
103
|
<ChatInput />
|
152
|
104
|
</>
|
153
|
105
|
);
|
|
@@ -210,33 +162,6 @@ class Chat extends AbstractChat<Props> {
|
210
|
162
|
</div>
|
211
|
163
|
);
|
212
|
164
|
}
|
213
|
|
-
|
214
|
|
- /**
|
215
|
|
- * Automatically scrolls the displayed chat messages down to the latest.
|
216
|
|
- *
|
217
|
|
- * @private
|
218
|
|
- * @returns {void}
|
219
|
|
- */
|
220
|
|
- _scrollMessagesToBottom() {
|
221
|
|
- if (this._messagesListEnd) {
|
222
|
|
- this._messagesListEnd.scrollIntoView({
|
223
|
|
- behavior: this._isExited ? 'auto' : 'smooth'
|
224
|
|
- });
|
225
|
|
- }
|
226
|
|
- }
|
227
|
|
-
|
228
|
|
- _setMessageListEndRef: (?HTMLElement) => void;
|
229
|
|
-
|
230
|
|
- /**
|
231
|
|
- * Sets a reference to the HTML element at the bottom of the message list.
|
232
|
|
- *
|
233
|
|
- * @param {Object} messageListEnd - The HTML element.
|
234
|
|
- * @private
|
235
|
|
- * @returns {void}
|
236
|
|
- */
|
237
|
|
- _setMessageListEndRef(messageListEnd: ?HTMLElement) {
|
238
|
|
- this._messagesListEnd = messageListEnd;
|
239
|
|
- }
|
240
|
165
|
}
|
241
|
166
|
|
242
|
167
|
export default translate(connect(_mapStateToProps, _mapDispatchToProps)(Chat));
|