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

Move display name handling into redux

master
Bettenbuk Zoltan пре 6 година
родитељ
комит
82f714b608

+ 0
- 1
conference.js Прегледај датотеку

@@ -2660,7 +2660,6 @@ export default {
2660 2660
         });
2661 2661
 
2662 2662
         if (room) {
2663
-            room.setDisplayName(formattedNickname);
2664 2663
             APP.UI.changeDisplayName(id, formattedNickname);
2665 2664
         }
2666 2665
     },

+ 28
- 0
react/features/base/conference/middleware.js Прегледај датотеку

@@ -15,6 +15,7 @@ import {
15 15
     getLocalParticipant,
16 16
     getParticipantById,
17 17
     getPinnedParticipant,
18
+    PARTICIPANT_UPDATED,
18 19
     PIN_PARTICIPANT
19 20
 } from '../participants';
20 21
 import { MiddlewareRegistry, StateListenerRegistry } from '../redux';
@@ -80,6 +81,9 @@ MiddlewareRegistry.register(store => next => action => {
80 81
     case DATA_CHANNEL_OPENED:
81 82
         return _syncReceiveVideoQuality(store, next, action);
82 83
 
84
+    case PARTICIPANT_UPDATED:
85
+        return _updateLocalParticipantInConference(store, next, action);
86
+
83 87
     case PIN_PARTICIPANT:
84 88
         return _pinParticipant(store, next, action);
85 89
 
@@ -651,3 +655,27 @@ function _trackAddedOrRemoved(store, next, action) {
651 655
 
652 656
     return next(action);
653 657
 }
658
+
659
+/**
660
+ * Updates the conference object when the local participant is updated.
661
+ *
662
+ * @param {Store} store - The redux store in which the specified {@code action}
663
+ * is being dispatched.
664
+ * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
665
+ * specified {@code action} to the specified {@code store}.
666
+ * @param {Action} action - The redux action which is being dispatched in the
667
+ * specified {@code store}.
668
+ * @private
669
+ * @returns {Object} The value returned by {@code next(action)}.
670
+ */
671
+function _updateLocalParticipantInConference({ getState }, next, action) {
672
+    const { conference } = getState()['features/base/conference'];
673
+    const { participant } = action;
674
+    const result = next(action);
675
+
676
+    if (conference && participant.local) {
677
+        conference.setDisplayName(participant.name);
678
+    }
679
+
680
+    return result;
681
+}

+ 4
- 24
react/features/base/participants/actions.js Прегледај датотеку

@@ -11,7 +11,6 @@ import {
11 11
     HIDDEN_PARTICIPANT_LEFT,
12 12
     KICK_PARTICIPANT,
13 13
     MUTE_REMOTE_PARTICIPANT,
14
-    PARTICIPANT_DISPLAY_NAME_CHANGED,
15 14
     PARTICIPANT_ID_CHANGED,
16 15
     PARTICIPANT_JOINED,
17 16
     PARTICIPANT_LEFT,
@@ -208,29 +207,6 @@ export function participantConnectionStatusChanged(id, connectionStatus) {
208 207
     };
209 208
 }
210 209
 
211
-/**
212
- * Action to signal that a participant's display name has changed.
213
- *
214
- * @param {string} id - The id of the participant being changed.
215
- * @param {string} displayName - The new display name.
216
- * @returns {{
217
- *     type: PARTICIPANT_DISPLAY_NAME_CHANGED,
218
- *     id: string,
219
- *     name: string
220
- * }}
221
- */
222
-export function participantDisplayNameChanged(id, displayName = '') {
223
-    // FIXME Do not use this action over participantUpdated. This action exists
224
-    // as a a bridge for local name updates. Once other components responsible
225
-    // for updating the local user's display name are in react/redux, this
226
-    // action should be replaceable with the participantUpdated action.
227
-    return {
228
-        type: PARTICIPANT_DISPLAY_NAME_CHANGED,
229
-        id,
230
-        name: displayName.substr(0, MAX_DISPLAY_NAME_LENGTH)
231
-    };
232
-}
233
-
234 210
 /**
235 211
  * Action to signal that a participant has joined.
236 212
  *
@@ -393,6 +369,10 @@ export function participantRoleChanged(id, role) {
393 369
  * }}
394 370
  */
395 371
 export function participantUpdated(participant = {}) {
372
+    if (participant.name) {
373
+        participant.name = participant.name.substr(0, MAX_DISPLAY_NAME_LENGTH);
374
+    }
375
+
396 376
     return {
397 377
         type: PARTICIPANT_UPDATED,
398 378
         participant

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

@@ -5,21 +5,13 @@ import React, { Component } from 'react';
5 5
 import { connect } from 'react-redux';
6 6
 
7 7
 import { translate } from '../../base/i18n';
8
-import {
9
-    getLocalParticipant,
10
-    participantDisplayNameChanged
11
-} from '../../base/participants';
8
+import { updateSettings } from '../../base/settings';
12 9
 
13 10
 /**
14 11
  * The type of the React {@code Component} props of {@DisplayNameForm}.
15 12
  */
16 13
 type Props = {
17 14
 
18
-    /**
19
-     * The ID of the local participant.
20
-     */
21
-    _localParticipantId: string,
22
-
23 15
     /**
24 16
      * Invoked to set the local participant display name.
25 17
      */
@@ -117,26 +109,11 @@ class DisplayNameForm extends Component<Props, State> {
117 109
     _onSubmit(event: Object) {
118 110
         event.preventDefault();
119 111
 
120
-        this.props.dispatch(participantDisplayNameChanged(
121
-            this.props._localParticipantId,
122
-            this.state.displayName));
112
+        // Store display name in settings
113
+        this.props.dispatch(updateSettings({
114
+            displayName: this.state.displayName
115
+        }));
123 116
     }
124 117
 }
125 118
 
126
-/**
127
- * Maps (parts of) the Redux state to the associated props for the
128
- * {@code DisplayNameForm} component.
129
- *
130
- * @param {Object} state - The Redux state.
131
- * @private
132
- * @returns {{
133
- *     _localParticipantId: string
134
- * }}
135
- */
136
-function _mapStateToProps(state) {
137
-    return {
138
-        _localParticipantId: getLocalParticipant(state).id
139
-    };
140
-}
141
-
142
-export default translate(connect(_mapStateToProps)(DisplayNameForm));
119
+export default translate(connect()(DisplayNameForm));

+ 8
- 2
react/features/display-name/actions.js Прегледај датотеку

@@ -1,3 +1,5 @@
1
+// @flow
2
+
1 3
 import { openDialog } from '../../features/base/dialog';
2 4
 
3 5
 import { DisplayNamePrompt } from './components';
@@ -5,8 +7,12 @@ import { DisplayNamePrompt } from './components';
5 7
 /**
6 8
  * Signals to open a dialog with the {@code DisplayNamePrompt} component.
7 9
  *
10
+ * @param {?Function} onPostSubmit - The function to invoke after a successful
11
+ * submit of the dialog.
8 12
  * @returns {Object}
9 13
  */
10
-export function openDisplayNamePrompt() {
11
-    return openDialog(DisplayNamePrompt);
14
+export function openDisplayNamePrompt(onPostSubmit: ?Function = undefined) {
15
+    return openDialog(DisplayNamePrompt, {
16
+        onPostSubmit
17
+    });
12 18
 }

+ 74
- 0
react/features/display-name/components/AbstractDisplayNamePrompt.js Прегледај датотеку

@@ -0,0 +1,74 @@
1
+// @flow
2
+
3
+import { Component } from 'react';
4
+
5
+import { updateSettings } from '../../base/settings';
6
+
7
+/**
8
+ * The type of the React {@code Component} props of
9
+ * {@link AbstractDisplayNamePrompt}.
10
+ */
11
+export type Props = {
12
+
13
+    /**
14
+     * Invoked to update the local participant's display name.
15
+     */
16
+    dispatch: Dispatch<*>,
17
+
18
+    /**
19
+     * Function to be invoked after a successful display name change.
20
+     */
21
+    onPostSubmit: ?Function,
22
+
23
+    /**
24
+     * Invoked to obtain translated strings.
25
+     */
26
+    t: Function
27
+};
28
+
29
+/**
30
+ * Implements an abstract class for {@code DisplayNamePrompt}.
31
+ */
32
+export default class AbstractDisplayNamePrompt<S: *>
33
+    extends Component<Props, S> {
34
+    /**
35
+     * Instantiates a new component.
36
+     *
37
+     * @inheritdoc
38
+     */
39
+    constructor(props: Props) {
40
+        super(props);
41
+
42
+        this._onSetDisplayName = this._onSetDisplayName.bind(this);
43
+    }
44
+
45
+    _onSetDisplayName: string => boolean;
46
+
47
+    /**
48
+     * Dispatches an action to update the local participant's display name. A
49
+     * name must be entered for the action to dispatch.
50
+     *
51
+     * It returns a boolean to comply the Dialog behaviour:
52
+     *     {@code true} - the dialog should be closed.
53
+     *     {@code false} - the dialog should be left open.
54
+     *
55
+     * @param {string} displayName - The display name to save.
56
+     * @returns {boolean}
57
+     */
58
+    _onSetDisplayName(displayName) {
59
+        if (!displayName || !displayName.trim()) {
60
+            return false;
61
+        }
62
+
63
+        const { dispatch, onPostSubmit } = this.props;
64
+
65
+        // Store display name in settings
66
+        dispatch(updateSettings({
67
+            displayName
68
+        }));
69
+
70
+        onPostSubmit && onPostSubmit();
71
+
72
+        return true;
73
+    }
74
+}

+ 37
- 13
react/features/display-name/components/DisplayName.web.js Прегледај датотеку

@@ -6,13 +6,21 @@ import { connect } from 'react-redux';
6 6
 import { appendSuffix } from '../functions';
7 7
 
8 8
 import { translate } from '../../base/i18n';
9
-import { participantDisplayNameChanged } from '../../base/participants';
9
+import {
10
+    getParticipantDisplayName
11
+} from '../../base/participants';
12
+import { updateSettings } from '../../base/settings';
10 13
 
11 14
 /**
12 15
  * The type of the React {@code Component} props of {@link DisplayName}.
13 16
  */
14 17
 type Props = {
15 18
 
19
+    /**
20
+     * The participant's current display name.
21
+     */
22
+    _displayName: string,
23
+
16 24
     /**
17 25
      * Whether or not the display name should be editable on click.
18 26
      */
@@ -23,11 +31,6 @@ type Props = {
23 31
      */
24 32
     dispatch: Dispatch<*>,
25 33
 
26
-    /**
27
-     * The participant's current display name.
28
-     */
29
-    displayName: string,
30
-
31 34
     /**
32 35
      * A string to append to the displayName, if provided.
33 36
      */
@@ -130,8 +133,8 @@ class DisplayName extends Component<Props, State> {
130 133
      */
131 134
     render() {
132 135
         const {
136
+            _displayName,
133 137
             allowEditing,
134
-            displayName,
135 138
             displayNameSuffix,
136 139
             elementID,
137 140
             t
@@ -159,7 +162,7 @@ class DisplayName extends Component<Props, State> {
159 162
                 className = 'displayname'
160 163
                 id = { elementID }
161 164
                 onClick = { this._onStartEditing }>
162
-                { appendSuffix(displayName, displayNameSuffix) }
165
+                { appendSuffix(_displayName, displayNameSuffix) }
163 166
             </span>
164 167
         );
165 168
     }
@@ -208,7 +211,7 @@ class DisplayName extends Component<Props, State> {
208 211
         if (this.props.allowEditing) {
209 212
             this.setState({
210 213
                 isEditing: true,
211
-                editDisplayNameValue: this.props.displayName || ''
214
+                editDisplayNameValue: this.props._displayName || ''
212 215
             });
213 216
         }
214 217
     }
@@ -226,10 +229,12 @@ class DisplayName extends Component<Props, State> {
226 229
      */
227 230
     _onSubmit() {
228 231
         const { editDisplayNameValue } = this.state;
229
-        const { dispatch, participantID } = this.props;
232
+        const { dispatch } = this.props;
230 233
 
231
-        dispatch(participantDisplayNameChanged(
232
-            participantID, editDisplayNameValue));
234
+        // Store display name in settings
235
+        dispatch(updateSettings({
236
+            displayName: editDisplayNameValue
237
+        }));
233 238
 
234 239
         this.setState({
235 240
             isEditing: false,
@@ -255,4 +260,23 @@ class DisplayName extends Component<Props, State> {
255 260
     }
256 261
 }
257 262
 
258
-export default translate(connect()(DisplayName));
263
+/**
264
+ * Maps (parts of) the redux state to the props of this component.
265
+ *
266
+ * @param {Object} state - The redux store/state.
267
+ * @param {Props} ownProps - The own props of the component.
268
+ * @private
269
+ * @returns {{
270
+ *     _displayName: string
271
+ * }}
272
+ */
273
+function _mapStateToProps(state, ownProps) {
274
+    const { participantID } = ownProps;
275
+
276
+    return {
277
+        _displayName: getParticipantDisplayName(
278
+            state, participantID)
279
+    };
280
+}
281
+
282
+export default translate(connect(_mapStateToProps)(DisplayName));

+ 9
- 63
react/features/display-name/components/DisplayNamePrompt.web.js Прегледај датотеку

@@ -1,37 +1,15 @@
1 1
 /* @flow */
2 2
 
3
-import React, { Component } from 'react';
3
+import React from 'react';
4 4
 import { connect } from 'react-redux';
5 5
 import { FieldTextStateless as TextField } from '@atlaskit/field-text';
6 6
 
7 7
 import { Dialog } from '../../base/dialog';
8 8
 import { translate } from '../../base/i18n';
9
-import {
10
-    getLocalParticipant,
11
-    participantDisplayNameChanged
12
-} from '../../base/participants';
13 9
 
14
-/**
15
- * The type of the React {@code Component} props of {@link DisplayNamePrompt}.
16
- */
17
-type Props = {
18
-
19
-    /**
20
-     * The current ID for the local participant. Used for setting the display
21
-     * name on the associated participant.
22
-     */
23
-    _localParticipantID: string,
24
-
25
-    /**
26
-     * Invoked to update the local participant's display name.
27
-     */
28
-    dispatch: Dispatch<*>,
29
-
30
-    /**
31
-     * Invoked to obtain translated strings.
32
-     */
33
-    t: Function
34
-};
10
+import AbstractDisplayNamePrompt, {
11
+    type Props
12
+} from './AbstractDisplayNamePrompt';
35 13
 
36 14
 /**
37 15
  * The type of the React {@code Component} props of {@link DisplayNamePrompt}.
@@ -50,7 +28,7 @@ type State = {
50 28
  *
51 29
  * @extends Component
52 30
  */
53
-class DisplayNamePrompt extends Component<Props, State> {
31
+class DisplayNamePrompt extends AbstractDisplayNamePrompt<State> {
54 32
     /**
55 33
      * Initializes a new {@code DisplayNamePrompt} instance.
56 34
      *
@@ -110,6 +88,8 @@ class DisplayNamePrompt extends Component<Props, State> {
110 88
         });
111 89
     }
112 90
 
91
+    _onSetDisplayName: string => boolean;
92
+
113 93
     _onSubmit: () => boolean;
114 94
 
115 95
     /**
@@ -120,42 +100,8 @@ class DisplayNamePrompt extends Component<Props, State> {
120 100
      * @returns {boolean}
121 101
      */
122 102
     _onSubmit() {
123
-        const { displayName } = this.state;
124
-
125
-        if (!displayName.trim()) {
126
-            return false;
127
-        }
128
-
129
-        const { dispatch, _localParticipantID } = this.props;
130
-
131
-        dispatch(
132
-            participantDisplayNameChanged(_localParticipantID, displayName));
133
-
134
-        return true;
103
+        return this._onSetDisplayName(this.state.displayName);
135 104
     }
136 105
 }
137 106
 
138
-/**
139
- * Maps (parts of) the Redux state to the associated {@code DisplayNamePrompt}'s
140
- * props.
141
- *
142
- * @param {Object} state - The Redux state.
143
- * @private
144
- * @returns {{
145
- *     _localParticipantID: string
146
- * }}
147
- */
148
-function _mapStateToProps(state) {
149
-    const { id } = getLocalParticipant(state);
150
-
151
-    return {
152
-        /**
153
-         * The current ID for the local participant.
154
-         *
155
-         * @type {string}
156
-         */
157
-        _localParticipantID: id
158
-    };
159
-}
160
-
161
-export default translate(connect(_mapStateToProps)(DisplayNamePrompt));
107
+export default translate(connect()(DisplayNamePrompt));

+ 1
- 1
react/features/display-name/functions.js Прегледај датотеку

@@ -7,5 +7,5 @@
7 7
  */
8 8
 export function appendSuffix(displayName, suffix) {
9 9
     return `${displayName || suffix || ''}${
10
-        displayName && suffix ? ` (${suffix})` : ''}`;
10
+        displayName && suffix && displayName !== suffix ? ` (${suffix})` : ''}`;
11 11
 }

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