Преглед на файлове

ref(chat): on native, show messages as grouped by sender

master
Leonard Kim преди 6 години
родител
ревизия
7187e540a8

+ 15
- 1
react/features/chat/components/AbstractChatMessage.js Целия файл

19
      */
19
      */
20
     message: Object,
20
     message: Object,
21
 
21
 
22
+    /**
23
+     * Whether or not the avatar image of the participant which sent the message
24
+     * should be displayed.
25
+     */
26
+    showAvatar: boolean,
27
+
22
     /**
28
     /**
23
      * Whether or not the name of the participant which sent the message should
29
      * Whether or not the name of the participant which sent the message should
24
      * be displayed.
30
      * be displayed.
25
      */
31
      */
26
     showDisplayName: boolean,
32
     showDisplayName: boolean,
27
 
33
 
34
+    /**
35
+     * Whether or not the time at which the message was sent should be
36
+     * displayed.
37
+     */
38
+    showTimestamp: boolean,
39
+
28
     /**
40
     /**
29
      * Invoked to receive translated strings.
41
      * Invoked to receive translated strings.
30
      */
42
      */
36
  */
48
  */
37
 export default class AbstractChatMessage<P: Props> extends PureComponent<P> {
49
 export default class AbstractChatMessage<P: Props> extends PureComponent<P> {
38
     static defaultProps = {
50
     static defaultProps = {
39
-        showDisplayName: true
51
+        showAvatar: false,
52
+        showDisplayName: false,
53
+        showTimestamp: false
40
     };
54
     };
41
 }
55
 }
42
 
56
 

+ 1
- 1
react/features/chat/components/AbstractMessageContainer.js Целия файл

39
             if (message.id === currentGroupParticipantId) {
39
             if (message.id === currentGroupParticipantId) {
40
                 currentGrouping.push(message);
40
                 currentGrouping.push(message);
41
             } else {
41
             } else {
42
-                groups.push(currentGrouping);
42
+                currentGrouping.length && groups.push(currentGrouping);
43
 
43
 
44
                 currentGrouping = [ message ];
44
                 currentGrouping = [ message ];
45
                 currentGroupParticipantId = message.id;
45
                 currentGroupParticipantId = message.id;

+ 26
- 27
react/features/chat/components/native/ChatMessage.js Целия файл

13
 } from '../AbstractChatMessage';
13
 } from '../AbstractChatMessage';
14
 import styles from './styles';
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
  * Formatter string to display the message timestamp.
17
  * Formatter string to display the message timestamp.
23
  */
18
  */
34
      */
29
      */
35
     render() {
30
     render() {
36
         const { message } = this.props;
31
         const { message } = this.props;
37
-        const timeStamp = getLocalizedDateFormatter(
38
-            new Date(message.timestamp)).format(TIMESTAMP_FORMAT);
39
         const localMessage = message.messageType === 'local';
32
         const localMessage = message.messageType === 'local';
40
 
33
 
41
         // Style arrays that need to be updated in various scenarios, such as
34
         // Style arrays that need to be updated in various scenarios, such as
60
 
53
 
61
         return (
54
         return (
62
             <View style = { styles.messageWrapper } >
55
             <View style = { styles.messageWrapper } >
63
-                {
64
-
65
-                    // Avatar is only rendered for remote messages.
66
-                    !localMessage && this._renderAvatar()
67
-                }
56
+                { this._renderAvatar() }
68
                 <View style = { detailsWrapperStyle }>
57
                 <View style = { detailsWrapperStyle }>
69
                     <View style = { textWrapperStyle } >
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
                         <Text style = { styles.messageText }>
63
                         <Text style = { styles.messageText }>
77
                             { message.messageType === 'error'
64
                             { message.messageType === 'error'
82
                                 : message.message }
69
                                 : message.message }
83
                         </Text>
70
                         </Text>
84
                     </View>
71
                     </View>
85
-                    <Text style = { styles.timeText }>
86
-                        { timeStamp }
87
-                    </Text>
72
+                    { this.props.showTimestamp && this._renderTimestamp() }
88
                 </View>
73
                 </View>
89
             </View>
74
             </View>
90
         );
75
         );
96
      * @returns {React$Element<*>}
81
      * @returns {React$Element<*>}
97
      */
82
      */
98
     _renderAvatar() {
83
     _renderAvatar() {
99
-        const { _avatarURL } = this.props;
100
-
101
         return (
84
         return (
102
             <View style = { styles.avatarWrapper }>
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
             </View>
90
             </View>
107
         );
91
         );
108
     }
92
     }
113
      * @returns {React$Element<*>}
97
      * @returns {React$Element<*>}
114
      */
98
      */
115
     _renderDisplayName() {
99
     _renderDisplayName() {
116
-        const { message } = this.props;
117
-
118
         return (
100
         return (
119
             <Text style = { styles.displayName }>
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
             </Text>
120
             </Text>
122
         );
121
         );
123
     }
122
     }

+ 12
- 2
react/features/chat/components/native/ChatMessageGroup.js Целия файл

68
      * @param {Object} message - The chat message to render.
68
      * @param {Object} message - The chat message to render.
69
      * @returns {React$Element<*>}
69
      * @returns {React$Element<*>}
70
      */
70
      */
71
-    _renderMessage({ item: message }) {
71
+    _renderMessage({ index, item: message }) {
72
         return (
72
         return (
73
-            <ChatMessage message = { message } />
73
+            <ChatMessage
74
+                message = { message }
75
+                showAvatar = {
76
+                    this.props.messages[0].messageType !== 'local'
77
+                        && index === this.props.messages.length - 1
78
+                }
79
+                showDisplayName = {
80
+                    this.props.messages[0].messageType === 'remote'
81
+                        && index === this.props.messages.length - 1
82
+                }
83
+                showTimestamp = { index === 0 } />
74
         );
84
         );
75
     }
85
     }
76
 }
86
 }

+ 2
- 1
react/features/chat/components/native/styles.js Целия файл

16
      * Wrapper View for the avatar.
16
      * Wrapper View for the avatar.
17
      */
17
      */
18
     avatarWrapper: {
18
     avatarWrapper: {
19
-        marginRight: 8
19
+        marginRight: 8,
20
+        width: 32
20
     },
21
     },
21
 
22
 
22
     /**
23
     /**

Loading…
Отказ
Запис