Quellcode durchsuchen

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

master
Leonard Kim vor 6 Jahren
Ursprung
Commit
504fadaf71

+ 7
- 3
css/_chat.scss Datei anzeigen

@@ -287,13 +287,17 @@
287 287
     &.local {
288 288
         align-items: flex-end;
289 289
 
290
+        .chatmessage {
291
+            background-color: $chatLocalMessageBackgroundColor;
292
+            border-radius: 6px 0px 6px 6px;
293
+        }
294
+
290 295
         .display-name {
291 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 Datei anzeigen

@@ -2,8 +2,14 @@
2 2
 
3 3
 import { PureComponent } from 'react';
4 4
 
5
+import { getLocalizedDateFormatter } from '../../base/i18n';
5 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 14
  * The type of the React {@code Component} props of {@code AbstractChatMessage}.
9 15
  */
@@ -47,11 +53,15 @@ export type Props = {
47 53
  * Abstract component to display a chat message.
48 54
  */
49 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 Datei anzeigen

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

+ 35
- 6
react/features/chat/components/web/ChatMessage.js Datei anzeigen

@@ -56,13 +56,42 @@ class ChatMessage extends AbstractChatMessage<Props> {
56 56
         });
57 57
 
58 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 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 95
             </div>
67 96
         );
68 97
     }

+ 2
- 9
react/features/chat/components/web/ChatMessageGroup.js Datei anzeigen

@@ -3,8 +3,6 @@
3 3
 import React, { Component } from 'react';
4 4
 import ChatMessage from './ChatMessage';
5 5
 
6
-import { getLocalizedDateFormatter } from '../../../base/i18n';
7
-
8 6
 type Props = {
9 7
 
10 8
     /**
@@ -43,8 +41,6 @@ class ChatMessageGroup extends Component<Props> {
43 41
             return null;
44 42
         }
45 43
 
46
-        const { timestamp } = messages[messagesLength - 1];
47
-
48 44
         return (
49 45
             <div className = { `chat-message-group ${className}` }>
50 46
                 {
@@ -52,13 +48,10 @@ class ChatMessageGroup extends Component<Props> {
52 48
                         <ChatMessage
53 49
                             key = { i }
54 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 55
             </div>
63 56
         );
64 57
     }

Laden…
Abbrechen
Speichern