Selaa lähdekoodia

fix(participants) sort participants alphabetically (#9741)

master
Avram Tudor 3 vuotta sitten
vanhempi
commit
595df524b0
No account linked to committer's email address

+ 42
- 0
react/features/base/participants/functions.js Näytä tiedosto

@@ -443,3 +443,45 @@ async function _getFirstLoadableAvatarUrl(participant, store) {
443 443
 
444 444
     return undefined;
445 445
 }
446
+
447
+
448
+/**
449
+ * Selector for retrieving sorted participants by display name.
450
+ *
451
+ * @param {(Function|Object)} stateful - The (whole) redux state, or redux's
452
+ * {@code getState} function to be used to retrieve the state
453
+ * features/base/participants.
454
+ * @returns {Array<Object>}
455
+ */
456
+export function getSortedParticipants(stateful: Object | Function) {
457
+    const localParticipant = getLocalParticipant(stateful);
458
+    const remoteParticipants = getRemoteParticipants(stateful);
459
+
460
+    const items = [];
461
+
462
+    remoteParticipants.forEach(p => {
463
+        items.push(p);
464
+    });
465
+
466
+    items.sort((a, b) =>
467
+        getParticipantDisplayName(stateful, a.id).localeCompare(getParticipantDisplayName(stateful, b.id))
468
+    );
469
+
470
+    items.unshift(localParticipant);
471
+
472
+    return items;
473
+}
474
+
475
+/**
476
+ * Selector for retrieving ids of alphabetically sorted participants by name.
477
+ *
478
+ * @param {(Function|Object)} stateful - The (whole) redux state, or redux's
479
+ * {@code getState} function to be used to retrieve the state
480
+ * features/base/participants.
481
+ * @returns {Array<string>}
482
+ */
483
+export function getSortedParticipantIds(stateful: Object | Function): Array<string> {
484
+    const participantIds = getSortedParticipants(stateful).map((p): Object => p.id);
485
+
486
+    return participantIds;
487
+}

+ 0
- 2
react/features/base/participants/reducer.js Näytä tiedosto

@@ -30,8 +30,6 @@ import { isParticipantModerator } from './functions';
30 30
  * @property {string} email - Participant email.
31 31
  */
32 32
 
33
-declare var APP: Object;
34
-
35 33
 /**
36 34
  * The participant properties which cannot be updated through
37 35
  * {@link PARTICIPANT_UPDATED}. They either identify the participant or can only

+ 3
- 2
react/features/lobby/components/AbstractKnockingParticipantList.js Näytä tiedosto

@@ -4,7 +4,7 @@ import { PureComponent } from 'react';
4 4
 
5 5
 import { isLocalParticipantModerator } from '../../base/participants';
6 6
 import { setKnockingParticipantApproval } from '../actions';
7
-import { getLobbyState } from '../functions';
7
+import { getKnockingParticipants, getLobbyEnabled } from '../functions';
8 8
 
9 9
 export type Props = {
10 10
 
@@ -67,7 +67,8 @@ export default class AbstractKnockingParticipantList<P: Props = Props> extends P
67 67
  * @returns {Props}
68 68
  */
69 69
 export function mapStateToProps(state: Object): $Shape<Props> {
70
-    const { knockingParticipants, lobbyEnabled } = getLobbyState(state);
70
+    const lobbyEnabled = getLobbyEnabled(state);
71
+    const knockingParticipants = getKnockingParticipants(state);
71 72
 
72 73
     return {
73 74
         _participants: knockingParticipants,

+ 17
- 10
react/features/lobby/functions.js Näytä tiedosto

@@ -1,15 +1,24 @@
1 1
 // @flow
2 2
 
3 3
 /**
4
- * Selector to return lobby state.
5
- *
6
- * @param {any} state - State object.
7
- * @returns {any}
8
- */
9
-export function getLobbyState(state: any) {
10
-    return state['features/lobby'];
4
+* Selector to return lobby enable state.
5
+*
6
+* @param {any} state - State object.
7
+* @returns {boolean}
8
+*/
9
+export function getLobbyEnabled(state: any) {
10
+    return state['features/lobby'].lobbyEnabled;
11 11
 }
12 12
 
13
+/**
14
+* Selector to return a list of knocking participants.
15
+*
16
+* @param {any} state - State object.
17
+* @returns {Array<Object>}
18
+*/
19
+export function getKnockingParticipants(state: any) {
20
+    return state['features/lobby'].knockingParticipants;
21
+}
13 22
 
14 23
 /**
15 24
  * Selector to return array with knocking participant ids.
@@ -18,7 +27,5 @@ export function getLobbyState(state: any) {
18 27
  * @returns {Array}
19 28
  */
20 29
 export function getKnockingParticipantsById(state: any) {
21
-    const { knockingParticipants } = state['features/lobby'];
22
-
23
-    return knockingParticipants.map(participant => participant.id);
30
+    return getKnockingParticipants(state).map(participant => participant.id);
24 31
 }

+ 4
- 5
react/features/participants-pane/components/native/LobbyParticipantList.js Näytä tiedosto

@@ -7,7 +7,7 @@ import { Button, withTheme } from 'react-native-paper';
7 7
 import { useDispatch, useSelector } from 'react-redux';
8 8
 
9 9
 import { admitMultiple } from '../../../lobby/actions.native';
10
-import { getLobbyState } from '../../../lobby/functions';
10
+import { getKnockingParticipants, getLobbyEnabled } from '../../../lobby/functions';
11 11
 
12 12
 import { LobbyParticipantItem } from './LobbyParticipantItem';
13 13
 import styles from './styles';
@@ -21,10 +21,9 @@ type Props = {
21 21
 };
22 22
 
23 23
 const LobbyParticipantList = ({ theme }: Props) => {
24
-    const {
25
-        lobbyEnabled,
26
-        knockingParticipants: participants
27
-    } = useSelector(getLobbyState);
24
+    const lobbyEnabled = useSelector(getLobbyEnabled);
25
+    const participants = useSelector(getKnockingParticipants);
26
+
28 27
     const dispatch = useDispatch();
29 28
     const admitAll = useCallback(() =>
30 29
         dispatch(admitMultiple(participants)),

+ 3
- 11
react/features/participants-pane/components/native/MeetingParticipantList.js Näytä tiedosto

@@ -11,7 +11,7 @@ import { Icon, IconInviteMore } from '../../../base/icons';
11 11
 import {
12 12
     getLocalParticipant,
13 13
     getParticipantCountWithFake,
14
-    getRemoteParticipants
14
+    getSortedParticipants
15 15
 } from '../../../base/participants';
16 16
 import { connect } from '../../../base/redux';
17 17
 import { doInvitePeople } from '../../../invite/actions.native';
@@ -35,11 +35,9 @@ type Props = {
35 35
 
36 36
 const MeetingParticipantList = ({ _localVideoOwner }: Props) => {
37 37
     const dispatch = useDispatch();
38
-    const items = [];
39
-    const localParticipant = useSelector(getLocalParticipant);
40 38
     const onInvite = useCallback(() => dispatch(doInvitePeople()), [ dispatch ]);
41
-    const participants = useSelector(getRemoteParticipants);
42 39
     const participantsCount = useSelector(getParticipantCountWithFake);
40
+    const sortedParticipants = useSelector(getSortedParticipants);
43 41
     const showInviteButton = useSelector(shouldRenderInviteButton);
44 42
     const { t } = useTranslation();
45 43
 
@@ -73,12 +71,6 @@ const MeetingParticipantList = ({ _localVideoOwner }: Props) => {
73 71
         );
74 72
     };
75 73
 
76
-    items.push(renderParticipant(localParticipant));
77
-
78
-    participants.forEach(p => {
79
-        items.push(renderParticipant(p));
80
-    });
81
-
82 74
     return (
83 75
         <View style = { styles.meetingList }>
84 76
             <Text style = { styles.meetingListDescription }>
@@ -100,7 +92,7 @@ const MeetingParticipantList = ({ _localVideoOwner }: Props) => {
100 92
                     onPress = { onInvite }
101 93
                     style = { styles.inviteButton } />
102 94
             }
103
-            { items }
95
+            { sortedParticipants.map(renderParticipant) }
104 96
         </View>
105 97
     );
106 98
 };

+ 4
- 5
react/features/participants-pane/components/web/LobbyParticipantList.js Näytä tiedosto

@@ -7,7 +7,7 @@ import { useSelector, useDispatch } from 'react-redux';
7 7
 
8 8
 import { withPixelLineHeight } from '../../../base/styles/functions.web';
9 9
 import { admitMultiple } from '../../../lobby/actions.web';
10
-import { getLobbyState } from '../../../lobby/functions';
10
+import { getKnockingParticipants, getLobbyEnabled } from '../../../lobby/functions';
11 11
 
12 12
 import { LobbyParticipantItem } from './LobbyParticipantItem';
13 13
 
@@ -32,10 +32,9 @@ const useStyles = makeStyles(theme => {
32 32
 
33 33
 
34 34
 export const LobbyParticipantList = () => {
35
-    const {
36
-        lobbyEnabled,
37
-        knockingParticipants: participants
38
-    } = useSelector(getLobbyState);
35
+    const lobbyEnabled = useSelector(getLobbyEnabled);
36
+    const participants = useSelector(getKnockingParticipants);
37
+
39 38
     const { t } = useTranslation();
40 39
     const classes = useStyles();
41 40
     const dispatch = useDispatch();

+ 3
- 12
react/features/participants-pane/components/web/MeetingParticipantList.js Näytä tiedosto

@@ -6,9 +6,8 @@ import { useSelector, useDispatch } from 'react-redux';
6 6
 
7 7
 import { openDialog } from '../../../base/dialog';
8 8
 import {
9
-    getLocalParticipant,
10 9
     getParticipantCountWithFake,
11
-    getRemoteParticipants
10
+    getSortedParticipantIds
12 11
 } from '../../../base/participants';
13 12
 import MuteRemoteParticipantDialog from '../../../video-menu/components/web/MuteRemoteParticipantDialog';
14 13
 import { findStyledAncestor, shouldRenderInviteButton } from '../../functions';
@@ -46,8 +45,7 @@ const initialState = Object.freeze(Object.create(null));
46 45
 export function MeetingParticipantList() {
47 46
     const dispatch = useDispatch();
48 47
     const isMouseOverMenu = useRef(false);
49
-    const participants = useSelector(getRemoteParticipants);
50
-    const localParticipant = useSelector(getLocalParticipant);
48
+    const sortedParticipantIds = useSelector(getSortedParticipantIds);
51 49
 
52 50
     // This is very important as getRemoteParticipants is not changing its reference object
53 51
     // and we will not re-render on change, but if count changes we will do
@@ -130,19 +128,12 @@ export function MeetingParticipantList() {
130 128
             youText = { youText } />
131 129
     );
132 130
 
133
-    const items = [];
134
-
135
-    localParticipant && items.push(renderParticipant(localParticipant?.id));
136
-    participants.forEach(p => {
137
-        items.push(renderParticipant(p?.id));
138
-    });
139
-
140 131
     return (
141 132
     <>
142 133
         <Heading>{t('participantsPane.headings.participantsList', { count: participantsCount })}</Heading>
143 134
         {showInviteButton && <InviteButton />}
144 135
         <div>
145
-            { items }
136
+            {sortedParticipantIds.map(renderParticipant)}
146 137
         </div>
147 138
         <MeetingParticipantContextMenu
148 139
             muteAudio = { muteAudio }

Loading…
Peruuta
Tallenna