fix: sorting order for group depending on statuses

pull/3281/head
Audric Ackermann 4 months ago
parent 2ca2dd4790
commit 82abfedad5
No known key found for this signature in database

@ -174,7 +174,7 @@ function localisedStatusFromMemberStatus(memberStatus: MemberStateGroupV2) {
case 'REMOVED_UNKNOWN': // fallback, hopefully won't happen in production
case 'REMOVED_MEMBER': // we want pending removal members at the end of the "invite" states
case 'REMOVED_MEMBER_AND_MESSAGES':
return null; // no text for those 3 pending removal states
return window.i18n('groupPendingRemoval'); // no text for those 3 pending removal states
case 'PROMOTION_FAILED':
return window.i18n('adminPromotionFailed');
case 'PROMOTION_NOT_SENT':

@ -423,6 +423,10 @@ const refreshGroupDetailsFromWrapper = createAsyncThunk(
const infos = await MetaGroupWrapperActions.infoGet(groupPk);
const members = await MetaGroupWrapperActions.memberGetAll(groupPk);
if (window.sessionFeatureFlags.debug.debugLibsessionDumps) {
window.log.info(`groupInfo after refreshGroupDetailsFromWrapper: ${stringify(infos)}`);
window.log.info(`groupMembers after refreshGroupDetailsFromWrapper: ${stringify(members)}`);
}
return { groupPk, infos, members };
} catch (e) {
window.log.warn('refreshGroupDetailsFromWrapper failed with ', e.message);
@ -748,6 +752,7 @@ async function handleMemberRemovedFromUI({
// We don't revoke the member's token right away. Instead we schedule a `GroupPendingRemovals`
// which will deal with the revokes of all of them together.
await GroupPendingRemovals.addJob({ groupPk });
window.inboxStore?.dispatch(refreshGroupDetailsFromWrapper({ groupPk }) as any);
// Build a GroupUpdateMessage to be sent if that member was kicked by us.
const createAtNetworkTimestamp = NetworkTime.now();

@ -272,19 +272,27 @@ export function useStateOf03GroupMembers(convoId?: string) {
);
const sorted = useMemo(() => {
// needing an index like this outside of lodash is not pretty,
// but sortBy doesn't provide the index in the callback
let index = 0;
return sortBy(unsortedMembers, item => {
const stateSortingOrder = getSortingOrderForStatus(item.memberStatus);
const sortingOrder = [
stateSortingOrder,
// per section, we want "us" first, then "nickname || displayName || pubkey"
item.pubkeyHex === us ? -1 : names[index],
];
index++;
// damn this is overkill
return sortBy(
unsortedMembers,
item => {
const sortingOrder = getSortingOrderForStatus(item.memberStatus);
return sortingOrder;
});
},
item => {
// per section, we want "us" first, then "nickname || displayName || pubkey"
if (item.pubkeyHex === us) {
return -1;
}
const index = unsortedMembers.findIndex(p => p.pubkeyHex === item.pubkeyHex);
if (index < 0 || index >= names.length) {
throw new Error('this should never happen');
}
return names[index].toLowerCase();
}
);
}, [unsortedMembers, us, names]);
return sorted;
}

Loading…
Cancel
Save