Browse Source

fix: Speaker stats search fix #9751 (#10019)

* Optimization of speaker stats display names #9751

* Fix speaker stats search for empty string #9751
master
dimitardelchev93 4 years ago
parent
commit
c3348bf38e
No account linked to committer's email address

+ 2
- 2
react/features/speaker-stats/actions.js View File

@@ -10,10 +10,10 @@ import {
10 10
 /**
11 11
  * Starts a search by criteria.
12 12
  *
13
- * @param {string} criteria - The search criteria.
13
+ * @param {string | null} criteria - The search criteria.
14 14
  * @returns {Object}
15 15
  */
16
-export function initSearch(criteria: string) {
16
+export function initSearch(criteria: string | null) {
17 17
     return {
18 18
         type: INIT_SEARCH,
19 19
         criteria

+ 39
- 23
react/features/speaker-stats/components/SpeakerStats.js View File

@@ -10,7 +10,7 @@ import { connect } from '../../base/redux';
10 10
 import { escapeRegexp } from '../../base/util';
11 11
 import { initUpdateStats, initSearch } from '../actions';
12 12
 import { SPEAKER_STATS_RELOAD_INTERVAL } from '../constants';
13
-import { getSpeakerStats, getSearchCriteria } from '../functions';
13
+import { getSpeakerStats } from '../functions';
14 14
 
15 15
 import SpeakerStatsItem from './SpeakerStatsItem';
16 16
 import SpeakerStatsLabels from './SpeakerStatsLabels';
@@ -36,7 +36,7 @@ type Props = {
36 36
     /**
37 37
      * The search criteria.
38 38
      */
39
-    _criteria: string,
39
+    _criteria: string | null,
40 40
 
41 41
     /**
42 42
      * The JitsiConference from which stats will be pulled.
@@ -140,24 +140,9 @@ class SpeakerStats extends Component<Props> {
140 140
         const dominantSpeakerTime = statsModel.getTotalDominantSpeakerTime();
141 141
         const hasLeft = statsModel.hasLeft();
142 142
 
143
-        let displayName;
144
-
145
-        if (statsModel.isLocalStats()) {
146
-            const { t } = this.props;
147
-            const meString = t('me');
148
-
149
-            displayName = this.props._localDisplayName;
150
-            displayName
151
-                = displayName ? `${displayName} (${meString})` : meString;
152
-        } else {
153
-            displayName
154
-                = this.props._stats[userId].getDisplayName()
155
-                    || interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME;
156
-        }
157
-
158 143
         return (
159 144
             <SpeakerStatsItem
160
-                displayName = { displayName }
145
+                displayName = { statsModel.getDisplayName() }
161 146
                 dominantSpeakerTime = { dominantSpeakerTime }
162 147
                 hasLeft = { hasLeft }
163 148
                 isDominantSpeaker = { isDominantSpeaker }
@@ -187,7 +172,40 @@ class SpeakerStats extends Component<Props> {
187 172
      * @private
188 173
      */
189 174
     _updateStats() {
190
-        this.props.dispatch(initUpdateStats(() => this.props.conference.getSpeakerStats()));
175
+        this.props.dispatch(initUpdateStats(() => this._getSpeakerStats()));
176
+    }
177
+
178
+    /**
179
+     * Update the internal state with the latest speaker stats.
180
+     *
181
+     * @returns {Object}
182
+     * @private
183
+     */
184
+    _getSpeakerStats() {
185
+        const stats = { ...this.props.conference.getSpeakerStats() };
186
+
187
+        for (const userId in stats) {
188
+            if (stats[userId]) {
189
+                if (stats[userId].isLocalStats()) {
190
+                    const { t } = this.props;
191
+                    const meString = t('me');
192
+
193
+                    stats[userId].setDisplayName(
194
+                        this.props._localDisplayName
195
+                            ? `${this.props._localDisplayName} (${meString})`
196
+                            : meString
197
+                    );
198
+                }
199
+
200
+                if (!stats[userId].getDisplayName()) {
201
+                    stats[userId].setDisplayName(
202
+                        interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME
203
+                    );
204
+                }
205
+            }
206
+        }
207
+
208
+        return stats;
191 209
     }
192 210
 }
193 211
 
@@ -198,8 +216,7 @@ class SpeakerStats extends Component<Props> {
198 216
  * @private
199 217
  * @returns {{
200 218
  *     _localDisplayName: ?string,
201
- *     _stats: Object,
202
- *     _criteria: string,
219
+ *     _stats: Object
203 220
  * }}
204 221
  */
205 222
 function _mapStateToProps(state) {
@@ -213,8 +230,7 @@ function _mapStateToProps(state) {
213 230
          * @type {string|undefined}
214 231
          */
215 232
         _localDisplayName: localParticipant && localParticipant.name,
216
-        _stats: getSpeakerStats(state),
217
-        _criteria: getSearchCriteria(state)
233
+        _stats: getSpeakerStats(state)
218 234
     };
219 235
 }
220 236
 

+ 4
- 6
react/features/speaker-stats/functions.js View File

@@ -43,10 +43,10 @@ export function getSpeakerStats(state: Object) {
43 43
  * Gets speaker stats search criteria.
44 44
  *
45 45
  * @param {*} state - The redux state.
46
- * @returns {string} - The search criteria.
46
+ * @returns {string | null} - The search criteria.
47 47
  */
48 48
 export function getSearchCriteria(state: Object) {
49
-    return state['features/speaker-stats']?.criteria ?? '';
49
+    return state['features/speaker-stats']?.criteria;
50 50
 }
51 51
 
52 52
 /**
@@ -161,16 +161,14 @@ export function filterBySearchCriteria(state: Object, stats: ?Object) {
161 161
     const filteredStats = _.cloneDeep(stats ?? getSpeakerStats(state));
162 162
     const criteria = getSearchCriteria(state);
163 163
 
164
-    if (criteria) {
164
+    if (criteria !== null) {
165 165
         const searchRegex = new RegExp(criteria, 'gi');
166 166
 
167 167
         for (const id in filteredStats) {
168 168
             if (filteredStats[id].hasOwnProperty('_isLocalStats')) {
169 169
                 const name = filteredStats[id].getDisplayName();
170 170
 
171
-                if (!name || !name.match(searchRegex)) {
172
-                    filteredStats[id].hidden = true;
173
-                }
171
+                filteredStats[id].hidden = !name || !name.match(searchRegex);
174 172
             }
175 173
         }
176 174
     }

+ 1
- 1
react/features/speaker-stats/reducer.js View File

@@ -18,7 +18,7 @@ import {
18 18
 const INITIAL_STATE = {
19 19
     stats: {},
20 20
     pendingReorder: true,
21
-    criteria: ''
21
+    criteria: null
22 22
 };
23 23
 
24 24
 ReducerRegistry.register('features/speaker-stats', (state = _getInitialState(), action) => {

Loading…
Cancel
Save