Merge pull request #16127 from ramonlsouza/fix-sortname

fix: incorrect userlist order if name starts with a space
This commit is contained in:
Anton Georgiev 2022-12-22 12:46:05 -05:00 committed by GitHub
commit 2cc37ff375
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 5 deletions

View File

@ -2,6 +2,7 @@ import Breakouts from '/imports/api/breakouts';
import updateUserBreakoutRoom from '/imports/api/users-persistent-data/server/modifiers/updateUserBreakoutRoom';
import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
import { lowercaseTrim } from '/imports/utils/string-utils';
export default function joinedUsersChanged({ body }) {
check(body, Object);
@ -21,7 +22,7 @@ export default function joinedUsersChanged({ body }) {
breakoutId,
};
const usersMapped = users.map(user => ({ userId: user.id, name: user.name }));
const usersMapped = users.map(user => ({ userId: user.id, name: user.name, sortName: lowercaseTrim(user.name) }));
const modifier = {
$set: {
joinedUsers: usersMapped,

View File

@ -6,6 +6,7 @@ import VoiceUsers from '/imports/api/voice-users/';
import addUserPsersistentData from '/imports/api/users-persistent-data/server/modifiers/addUserPersistentData';
import stringHash from 'string-hash';
import flat from 'flat';
import { lowercaseTrim } from '/imports/utils/string-utils';
import addVoiceUser from '/imports/api/voice-users/server/modifiers/addVoiceUser';
@ -51,7 +52,7 @@ export default function addUser(meetingId, userData) {
const userInfos = {
meetingId,
sortName: user.name.trim().toLowerCase(),
sortName: lowercaseTrim(user.name),
color,
speechLocale: '',
mobile: false,

View File

@ -7,6 +7,7 @@ import {
} from '/imports/api/video-streams/server/helpers';
import VoiceUsers from '/imports/api/voice-users/';
import Users from '/imports/api/users/';
import { lowercaseTrim } from '/imports/utils/string-utils';
const BASE_FLOOR_TIME = "0";
@ -40,6 +41,7 @@ export default function sharedWebcam(meetingId, userId, stream) {
$set: {
stream,
name,
sortName: lowercaseTrim(name),
lastFloorTime,
floor,
pin,

View File

@ -60,8 +60,8 @@ const sortUsersByUserId = (a, b) => {
};
const sortUsersByName = (a, b) => {
const aName = a.name ? a.name.toLowerCase() : '';
const bName = b.name ? b.name.toLowerCase() : '';
const aName = a.sortName || '';
const bName = b.sortName || '';
// Extending for sorting strings with non-ASCII characters
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#sorting_non-ascii_characters

View File

@ -86,7 +86,7 @@ export const sortLocalPresenterAlphabetical = (s1, s2) => mandatorySorting(s1, s
// 2 - add an entry to SORTING_METHODS, the key being the name to be used
// in settings.yml and the value object like the aforementioned
const MANDATORY_DATA_TYPES = {
userId: 1, stream: 1, name: 1, deviceId: 1, floor: 1, pin: 1,
userId: 1, stream: 1, name: 1, sortName: 1, deviceId: 1, floor: 1, pin: 1,
};
const SORTING_METHODS = Object.freeze({
// Default
@ -132,6 +132,7 @@ export const sortVideoStreams = (streams, mode) => {
stream: videoStream.stream,
userId: videoStream.userId,
name: videoStream.name,
sortName: videoStream.sortName,
floor: videoStream.floor,
pin: videoStream.pin,
}));

View File

@ -47,6 +47,10 @@ export const safeMatch = (regex, content, defaultValue) => {
return content.match(regex) || defaultValue;
};
export const lowercaseTrim = (text) => {
return text.trim().toLowerCase();
}
export default {
capitalizeFirstLetter,
getDateString,
@ -55,4 +59,5 @@ export default {
unescapeHtml,
formatLocaleCode,
safeMatch,
lowercaseTrim,
};