Ver código fonte

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

master
Leonard Kim 6 anos atrás
pai
commit
7187e540a8

+ 15
- 1
react/features/chat/components/AbstractChatMessage.js Ver arquivo

@@ -19,12 +19,24 @@ export type Props = {
19 19
      */
20 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 29
      * Whether or not the name of the participant which sent the message should
24 30
      * be displayed.
25 31
      */
26 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 41
      * Invoked to receive translated strings.
30 42
      */
@@ -36,7 +48,9 @@ export type Props = {
36 48
  */
37 49
 export default class AbstractChatMessage<P: Props> extends PureComponent<P> {
38 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 Ver arquivo

@@ -39,7 +39,7 @@ export default class AbstractMessageContainer<P: Props> extends PureComponent<P>
39 39
             if (message.id === currentGroupParticipantId) {
40 40
                 currentGrouping.push(message);
41 41
             } else {
42
-                groups.push(currentGrouping);
42
+                currentGrouping.length && groups.push(currentGrouping);
43 43
 
44 44
                 currentGrouping = [ message ];
45 45
                 currentGroupParticipantId = message.id;

+ 26
- 27
react/features/chat/components/native/ChatMessage.js Ver arquivo

@@ -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
     }

+ 12
- 2
react/features/chat/components/native/ChatMessageGroup.js Ver arquivo

@@ -68,9 +68,19 @@ export default class ChatMessageGroup extends Component<Props> {
68 68
      * @param {Object} message - The chat message to render.
69 69
      * @returns {React$Element<*>}
70 70
      */
71
-    _renderMessage({ item: message }) {
71
+    _renderMessage({ index, item: message }) {
72 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 Ver arquivo

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

Carregando…
Cancelar
Salvar