Преглед изворни кода

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

master
Leonard Kim пре 6 година
родитељ
комит
504fadaf71

+ 7
- 3
css/_chat.scss Прегледај датотеку

287
     &.local {
287
     &.local {
288
         align-items: flex-end;
288
         align-items: flex-end;
289
 
289
 
290
+        .chatmessage {
291
+            background-color: $chatLocalMessageBackgroundColor;
292
+            border-radius: 6px 0px 6px 6px;
293
+        }
294
+
290
         .display-name {
295
         .display-name {
291
             display: none;
296
             display: none;
292
         }
297
         }
293
 
298
 
294
-        .chatmessage {
295
-            background-color: $chatLocalMessageBackgroundColor;
296
-            border-radius: 6px 0px 6px 6px;
299
+        .timestamp {
300
+            text-align: right;
297
         }
301
         }
298
     }
302
     }
299
 
303
 

+ 15
- 5
react/features/chat/components/AbstractChatMessage.js Прегледај датотеку

2
 
2
 
3
 import { PureComponent } from 'react';
3
 import { PureComponent } from 'react';
4
 
4
 
5
+import { getLocalizedDateFormatter } from '../../base/i18n';
5
 import { getAvatarURLByParticipantId } from '../../base/participants';
6
 import { getAvatarURLByParticipantId } from '../../base/participants';
6
 
7
 
8
+/**
9
+ * Formatter string to display the message timestamp.
10
+ */
11
+const TIMESTAMP_FORMAT = 'H:mm';
12
+
7
 /**
13
 /**
8
  * The type of the React {@code Component} props of {@code AbstractChatMessage}.
14
  * The type of the React {@code Component} props of {@code AbstractChatMessage}.
9
  */
15
  */
47
  * Abstract component to display a chat message.
53
  * Abstract component to display a chat message.
48
  */
54
  */
49
 export default class AbstractChatMessage<P: Props> extends PureComponent<P> {
55
 export default class AbstractChatMessage<P: Props> extends PureComponent<P> {
50
-    static defaultProps = {
51
-        showAvatar: false,
52
-        showDisplayName: false,
53
-        showTimestamp: false
54
-    };
56
+    /**
57
+     * Returns the timestamp to display for the message.
58
+     *
59
+     * @returns {string}
60
+     */
61
+    _getFormattedTimestamp() {
62
+        return getLocalizedDateFormatter(new Date(this.props.message.timestamp))
63
+            .format(TIMESTAMP_FORMAT);
64
+    }
55
 }
65
 }
56
 
66
 
57
 /**
67
 /**

+ 4
- 11
react/features/chat/components/native/ChatMessage.js Прегледај датотеку

3
 import React from 'react';
3
 import React from 'react';
4
 import { Text, View } from 'react-native';
4
 import { Text, View } from 'react-native';
5
 
5
 
6
-import { getLocalizedDateFormatter, translate } from '../../../base/i18n';
6
+import { translate } from '../../../base/i18n';
7
 import { Avatar } from '../../../base/participants';
7
 import { Avatar } from '../../../base/participants';
8
 import { connect } from '../../../base/redux';
8
 import { connect } from '../../../base/redux';
9
 
9
 
13
 } from '../AbstractChatMessage';
13
 } from '../AbstractChatMessage';
14
 import styles from './styles';
14
 import styles from './styles';
15
 
15
 
16
-/**
17
- * Formatter string to display the message timestamp.
18
- */
19
-const TIMESTAMP_FORMAT = 'H:mm';
20
-
21
 /**
16
 /**
22
  * Renders a single chat message.
17
  * Renders a single chat message.
23
  */
18
  */
75
         );
70
         );
76
     }
71
     }
77
 
72
 
73
+    _getFormattedTimestamp: () => string;
74
+
78
     /**
75
     /**
79
      * Renders the avatar of the sender.
76
      * Renders the avatar of the sender.
80
      *
77
      *
112
     _renderTimestamp() {
109
     _renderTimestamp() {
113
         return (
110
         return (
114
             <Text style = { styles.timeText }>
111
             <Text style = { styles.timeText }>
115
-                {
116
-                    getLocalizedDateFormatter(
117
-                        new Date(this.props.message.timestamp)
118
-                    ).format(TIMESTAMP_FORMAT)
119
-                }
112
+                { this._getFormattedTimestamp() }
120
             </Text>
113
             </Text>
121
         );
114
         );
122
     }
115
     }

+ 35
- 6
react/features/chat/components/web/ChatMessage.js Прегледај датотеку

56
         });
56
         });
57
 
57
 
58
         return (
58
         return (
59
-            <div className = 'chatmessage'>
60
-                { this.props.showDisplayName && <div className = 'display-name'>
61
-                    { message.displayName }
62
-                </div> }
63
-                <div className = 'usermessage'>
64
-                    { processedMessage }
59
+            <div>
60
+                <div className = 'chatmessage'>
61
+                    { this.props.showDisplayName && this._renderDisplayName() }
62
+                    <div className = 'usermessage'>
63
+                        { processedMessage }
64
+                    </div>
65
                 </div>
65
                 </div>
66
+                { this.props.showTimestamp && this._renderTimestamp() }
67
+            </div>
68
+        );
69
+    }
70
+
71
+    _getFormattedTimestamp: () => string;
72
+
73
+    /**
74
+     * Renders the display name of the sender.
75
+     *
76
+     * @returns {React$Element<*>}
77
+     */
78
+    _renderDisplayName() {
79
+        return (
80
+            <div className = 'display-name'>
81
+                { this.props.message.displayName }
82
+            </div>
83
+        );
84
+    }
85
+
86
+    /**
87
+     * Renders the time at which the message was sent.
88
+     *
89
+     * @returns {React$Element<*>}
90
+     */
91
+    _renderTimestamp() {
92
+        return (
93
+            <div className = 'timestamp'>
94
+                { this._getFormattedTimestamp() }
66
             </div>
95
             </div>
67
         );
96
         );
68
     }
97
     }

+ 2
- 9
react/features/chat/components/web/ChatMessageGroup.js Прегледај датотеку

3
 import React, { Component } from 'react';
3
 import React, { Component } from 'react';
4
 import ChatMessage from './ChatMessage';
4
 import ChatMessage from './ChatMessage';
5
 
5
 
6
-import { getLocalizedDateFormatter } from '../../../base/i18n';
7
-
8
 type Props = {
6
 type Props = {
9
 
7
 
10
     /**
8
     /**
43
             return null;
41
             return null;
44
         }
42
         }
45
 
43
 
46
-        const { timestamp } = messages[messagesLength - 1];
47
-
48
         return (
44
         return (
49
             <div className = { `chat-message-group ${className}` }>
45
             <div className = { `chat-message-group ${className}` }>
50
                 {
46
                 {
52
                         <ChatMessage
48
                         <ChatMessage
53
                             key = { i }
49
                             key = { i }
54
                             message = { message }
50
                             message = { message }
55
-                            showDisplayName = { i === 0 } />
51
+                            showDisplayName = { i === 0 }
52
+                            showTimestamp = { i === messages.length - 1 } />
56
                     ))
53
                     ))
57
                 }
54
                 }
58
-                <div className = 'chat-message-group-footer'>
59
-                    { getLocalizedDateFormatter(
60
-                        new Date(timestamp)).format('H:mm') }
61
-                </div>
62
             </div>
55
             </div>
63
         );
56
         );
64
     }
57
     }

Loading…
Откажи
Сачувај