@@ -9,7 +9,10 @@ import { type GroupMemberGetRedux } from '../ducks/types/groupReduxTypes';
9
9
import { StateType } from '../reducer' ;
10
10
import { assertUnreachable } from '../../types/sqlSharedTypes' ;
11
11
import { UserUtils } from '../../session/utils' ;
12
- import { useConversationsNicknameRealNameOrShortenPubkey } from '../../hooks/useParamSelector' ;
12
+ import {
13
+ useConversationsNicknameRealNameOrShortenPubkey ,
14
+ useWeAreAdmin ,
15
+ } from '../../hooks/useParamSelector' ;
13
16
14
17
const selectLibGroupsState = ( state : StateType ) : GroupState => state . groups ;
15
18
@@ -266,7 +269,22 @@ export function useGroupAvatarChangeFromUIPending() {
266
269
return useSelector ( selectGroupAvatarChangeFromUIPending ) ;
267
270
}
268
271
269
- function getSortingOrderForStatus ( memberStatus : MemberStateGroupV2 ) {
272
+ function getSortingOrderForStatus ( memberStatus : MemberStateGroupV2 , weAreAdmin : boolean ) {
273
+ // Non-admins don't need to see the details as they cannot do anything to change their state.
274
+ // so we only group members by You, Members,
275
+ if ( ! weAreAdmin ) {
276
+ switch ( memberStatus ) {
277
+ case 'PROMOTION_FAILED' :
278
+ case 'PROMOTION_NOT_SENT' :
279
+ case 'PROMOTION_SENDING' :
280
+ case 'PROMOTION_SENT' :
281
+ case 'PROMOTION_UNKNOWN' :
282
+ case 'PROMOTION_ACCEPTED' :
283
+ return 0 ;
284
+ default :
285
+ return 10 ;
286
+ }
287
+ }
270
288
switch ( memberStatus ) {
271
289
case 'INVITE_FAILED' :
272
290
return 0 ;
@@ -305,23 +323,35 @@ function getSortingOrderForStatus(memberStatus: MemberStateGroupV2) {
305
323
export function useStateOf03GroupMembers ( convoId ?: string ) {
306
324
const us = UserUtils . getOurPubKeyStrFromCache ( ) ;
307
325
const unsortedMembers = useSelector ( ( state : StateType ) => selectMembersOfGroup ( state , convoId ) ) ;
326
+ const weAreAdmin = useWeAreAdmin ( convoId ) ;
308
327
309
328
const names = useConversationsNicknameRealNameOrShortenPubkey (
310
329
unsortedMembers . map ( m => m . pubkeyHex )
311
330
) ;
312
331
332
+ // Damn this sorting logic is overkill x2.
333
+ // The sorting logic is as follows:
334
+ // - when we are an admin, we want to sort by the following order:
335
+ // - Each states of invite/promotion/etc separate, but You always at the top **per section**
336
+ // - when we are **not** an admin, we want to sort by the following order:
337
+ // - You
338
+ // - Admins (without You as it is already at the top)
339
+ // - Others (same as above)
313
340
const sorted = useMemo ( ( ) => {
314
- // damn this is overkill
315
341
return sortBy (
316
342
unsortedMembers ,
317
343
item => {
318
- const sortingOrder = getSortingOrderForStatus ( item . memberStatus ) ;
344
+ // when we are not an admin, we want the current user (You) to be always be at the top
345
+ if ( ! weAreAdmin && item . pubkeyHex === us ) {
346
+ return - 1 ;
347
+ }
348
+
349
+ const sortingOrder = getSortingOrderForStatus ( item . memberStatus , weAreAdmin ) ;
319
350
return sortingOrder ;
320
351
} ,
321
352
item => {
322
- // per section, we want "us" first, then "nickname || displayName || pubkey"
323
-
324
- if ( item . pubkeyHex === us ) {
353
+ // when we are an admin, we want to sort "You" at the top per sections
354
+ if ( weAreAdmin && item . pubkeyHex === us ) {
325
355
return - 1 ;
326
356
}
327
357
const index = unsortedMembers . findIndex ( p => p . pubkeyHex === item . pubkeyHex ) ;
@@ -332,6 +362,7 @@ export function useStateOf03GroupMembers(convoId?: string) {
332
362
return names [ index ] . toLowerCase ( ) ;
333
363
}
334
364
) ;
335
- } , [ unsortedMembers , us , names ] ) ;
365
+ } , [ unsortedMembers , us , names , weAreAdmin ] ) ;
366
+
336
367
return sorted ;
337
368
}
0 commit comments