瀏覽代碼

Fix accidental overwrite of localParticipant with empty values

master
zbettenbuk 7 年之前
父節點
當前提交
cc7e15ab8f
共有 1 個檔案被更改,包括 33 行新增15 行删除
  1. 33
    15
      react/features/base/settings/middleware.js

+ 33
- 15
react/features/base/settings/middleware.js 查看文件

2
 
2
 
3
 import { setAudioOnly } from '../conference';
3
 import { setAudioOnly } from '../conference';
4
 import { getLocalParticipant, participantUpdated } from '../participants';
4
 import { getLocalParticipant, participantUpdated } from '../participants';
5
-import { MiddlewareRegistry, toState } from '../redux';
5
+import { MiddlewareRegistry } from '../redux';
6
 
6
 
7
 import { SETTINGS_UPDATED } from './actionTypes';
7
 import { SETTINGS_UPDATED } from './actionTypes';
8
-import { getSettings } from './functions';
9
 
8
 
10
 /**
9
 /**
11
  * The middleware of the feature base/settings. Distributes changes to the state
10
  * The middleware of the feature base/settings. Distributes changes to the state
21
     switch (action.type) {
20
     switch (action.type) {
22
     case SETTINGS_UPDATED:
21
     case SETTINGS_UPDATED:
23
         _maybeSetAudioOnly(store, action);
22
         _maybeSetAudioOnly(store, action);
24
-        _updateLocalParticipant(store);
23
+        _updateLocalParticipant(store, action);
25
     }
24
     }
26
 
25
 
27
     return result;
26
     return result;
28
 });
27
 });
29
 
28
 
29
+/**
30
+ * Maps the settings field names to participant names where they don't match.
31
+ * Currently there is only one such field, but may be extended in the future.
32
+ *
33
+ * @private
34
+ * @param {string} settingsField - The name of the settings field to map.
35
+ * @returns {string}
36
+ */
37
+function _mapSettingsFieldToParticipant(settingsField) {
38
+    switch (settingsField) {
39
+    case 'displayName':
40
+        return 'name';
41
+    }
42
+
43
+    return settingsField;
44
+}
45
+
30
 /**
46
 /**
31
  * Updates {@code startAudioOnly} flag if it's updated in the settings.
47
  * Updates {@code startAudioOnly} flag if it's updated in the settings.
32
  *
48
  *
47
  * Updates the local participant according to settings changes.
63
  * Updates the local participant according to settings changes.
48
  *
64
  *
49
  * @param {Store} store - The redux store.
65
  * @param {Store} store - The redux store.
66
+ * @param {Object} action - The dispatched action.
50
  * @private
67
  * @private
51
  * @returns {void}
68
  * @returns {void}
52
  */
69
  */
53
-function _updateLocalParticipant(store) {
54
-    const state = toState(store);
55
-    const localParticipant = getLocalParticipant(state);
56
-    const settings = getSettings(state);
70
+function _updateLocalParticipant({ dispatch, getState }, action) {
71
+    const { settings } = action;
72
+    const localParticipant = getLocalParticipant(getState());
73
+    const newLocalParticipant = {
74
+        ...localParticipant
75
+    };
57
 
76
 
58
-    store.dispatch(participantUpdated({
59
-        // Identify that the participant to update i.e. the local participant:
60
-        id: localParticipant && localParticipant.id,
61
-        local: true,
77
+    for (const key in settings) {
78
+        if (settings.hasOwnProperty(key)) {
79
+            newLocalParticipant[_mapSettingsFieldToParticipant(key)]
80
+                = settings[key];
81
+        }
82
+    }
62
 
83
 
63
-        // Specify the updates to be applied to the identified participant:
64
-        email: settings.email,
65
-        name: settings.displayName
66
-    }));
84
+    dispatch(participantUpdated(newLocalParticipant));
67
 }
85
 }

Loading…
取消
儲存