Deduplicate string compare utility (#9579)
This commit is contained in:
parent
436146105e
commit
e66027cd0c
9 changed files with 9 additions and 18 deletions
|
@ -19,12 +19,12 @@ import React from 'react';
|
||||||
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
|
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
|
||||||
import { RoomMember, RoomMemberEvent } from "matrix-js-sdk/src/models/room-member";
|
import { RoomMember, RoomMemberEvent } from "matrix-js-sdk/src/models/room-member";
|
||||||
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||||
|
import { compare } from "matrix-js-sdk/src/utils";
|
||||||
|
|
||||||
import * as WhoIsTyping from '../../../WhoIsTyping';
|
import * as WhoIsTyping from '../../../WhoIsTyping';
|
||||||
import Timer from '../../../utils/Timer';
|
import Timer from '../../../utils/Timer';
|
||||||
import { MatrixClientPeg } from '../../../MatrixClientPeg';
|
import { MatrixClientPeg } from '../../../MatrixClientPeg';
|
||||||
import MemberAvatar from '../avatars/MemberAvatar';
|
import MemberAvatar from '../avatars/MemberAvatar';
|
||||||
import { compare } from "../../../utils/strings";
|
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
// the room this statusbar is representing.
|
// the room this statusbar is representing.
|
||||||
|
|
|
@ -20,12 +20,12 @@ import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
||||||
import { RoomState, RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
|
import { RoomState, RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
import { throttle } from "lodash";
|
import { throttle } from "lodash";
|
||||||
|
import { compare } from "matrix-js-sdk/src/utils";
|
||||||
|
|
||||||
import { _t, _td } from "../../../../../languageHandler";
|
import { _t, _td } from "../../../../../languageHandler";
|
||||||
import { MatrixClientPeg } from "../../../../../MatrixClientPeg";
|
import { MatrixClientPeg } from "../../../../../MatrixClientPeg";
|
||||||
import AccessibleButton from "../../../elements/AccessibleButton";
|
import AccessibleButton from "../../../elements/AccessibleButton";
|
||||||
import Modal from "../../../../../Modal";
|
import Modal from "../../../../../Modal";
|
||||||
import { compare } from "../../../../../utils/strings";
|
|
||||||
import ErrorDialog from '../../../dialogs/ErrorDialog';
|
import ErrorDialog from '../../../dialogs/ErrorDialog';
|
||||||
import PowerSelector from "../../../elements/PowerSelector";
|
import PowerSelector from "../../../elements/PowerSelector";
|
||||||
import SettingsFieldset from '../../SettingsFieldset';
|
import SettingsFieldset from '../../SettingsFieldset';
|
||||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||||
import url from 'url';
|
import url from 'url';
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/client";
|
import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/client";
|
||||||
|
import { compare } from "matrix-js-sdk/src/utils";
|
||||||
|
|
||||||
import type { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
import type { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||||
import SdkConfig from '../SdkConfig';
|
import SdkConfig from '../SdkConfig';
|
||||||
|
@ -26,7 +27,6 @@ import IntegrationsImpossibleDialog from "../components/views/dialogs/Integratio
|
||||||
import IntegrationsDisabledDialog from "../components/views/dialogs/IntegrationsDisabledDialog";
|
import IntegrationsDisabledDialog from "../components/views/dialogs/IntegrationsDisabledDialog";
|
||||||
import WidgetUtils from "../utils/WidgetUtils";
|
import WidgetUtils from "../utils/WidgetUtils";
|
||||||
import { MatrixClientPeg } from "../MatrixClientPeg";
|
import { MatrixClientPeg } from "../MatrixClientPeg";
|
||||||
import { compare } from "../utils/strings";
|
|
||||||
|
|
||||||
const KIND_PREFERENCE = [
|
const KIND_PREFERENCE = [
|
||||||
// Ordered: first is most preferred, last is least preferred.
|
// Ordered: first is most preferred, last is least preferred.
|
||||||
|
|
|
@ -15,10 +15,10 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Room } from "matrix-js-sdk/src/models/room";
|
import { Room } from "matrix-js-sdk/src/models/room";
|
||||||
|
import { compare } from "matrix-js-sdk/src/utils";
|
||||||
|
|
||||||
import { TagID } from "../../models";
|
import { TagID } from "../../models";
|
||||||
import { IAlgorithm } from "./IAlgorithm";
|
import { IAlgorithm } from "./IAlgorithm";
|
||||||
import { compare } from "../../../../utils/strings";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts rooms according to the browser's determination of alphabetic.
|
* Sorts rooms according to the browser's determination of alphabetic.
|
||||||
|
|
|
@ -18,6 +18,7 @@ import { Room } from "matrix-js-sdk/src/models/room";
|
||||||
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||||
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
|
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
|
||||||
import { Optional } from "matrix-events-sdk";
|
import { Optional } from "matrix-events-sdk";
|
||||||
|
import { compare } from "matrix-js-sdk/src/utils";
|
||||||
|
|
||||||
import SettingsStore from "../../settings/SettingsStore";
|
import SettingsStore from "../../settings/SettingsStore";
|
||||||
import WidgetStore, { IApp } from "../WidgetStore";
|
import WidgetStore, { IApp } from "../WidgetStore";
|
||||||
|
@ -28,7 +29,6 @@ import { ReadyWatchingStore } from "../ReadyWatchingStore";
|
||||||
import { SettingLevel } from "../../settings/SettingLevel";
|
import { SettingLevel } from "../../settings/SettingLevel";
|
||||||
import { arrayFastClone } from "../../utils/arrays";
|
import { arrayFastClone } from "../../utils/arrays";
|
||||||
import { UPDATE_EVENT } from "../AsyncStore";
|
import { UPDATE_EVENT } from "../AsyncStore";
|
||||||
import { compare } from "../../utils/strings";
|
|
||||||
|
|
||||||
export const WIDGET_LAYOUT_EVENT_TYPE = "io.element.widgets.layout";
|
export const WIDGET_LAYOUT_EVENT_TYPE = "io.element.widgets.layout";
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,11 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { compare } from "matrix-js-sdk/src/utils";
|
||||||
|
|
||||||
import { _t } from "./languageHandler";
|
import { _t } from "./languageHandler";
|
||||||
import SettingsStore from "./settings/SettingsStore";
|
import SettingsStore from "./settings/SettingsStore";
|
||||||
import ThemeWatcher from "./settings/watchers/ThemeWatcher";
|
import ThemeWatcher from "./settings/watchers/ThemeWatcher";
|
||||||
import { compare } from "./utils/strings";
|
|
||||||
|
|
||||||
export const DEFAULT_THEME = "light";
|
export const DEFAULT_THEME = "light";
|
||||||
const HIGH_CONTRAST_THEMES = {
|
const HIGH_CONTRAST_THEMES = {
|
||||||
|
|
|
@ -16,10 +16,10 @@ limitations under the License.
|
||||||
|
|
||||||
import { groupBy, mapValues, maxBy, minBy, sumBy, takeRight } from "lodash";
|
import { groupBy, mapValues, maxBy, minBy, sumBy, takeRight } from "lodash";
|
||||||
import { MatrixClient, Room, RoomMember } from "matrix-js-sdk/src/matrix";
|
import { MatrixClient, Room, RoomMember } from "matrix-js-sdk/src/matrix";
|
||||||
|
import { compare } from "matrix-js-sdk/src/utils";
|
||||||
|
|
||||||
import { Member } from "./direct-messages";
|
import { Member } from "./direct-messages";
|
||||||
import DMRoomMap from "./DMRoomMap";
|
import DMRoomMap from "./DMRoomMap";
|
||||||
import { compare } from "./strings";
|
|
||||||
|
|
||||||
export const compareMembers = (
|
export const compareMembers = (
|
||||||
activityScores: Record<string, IActivityScore>,
|
activityScores: Record<string, IActivityScore>,
|
||||||
|
|
|
@ -75,16 +75,6 @@ export function copyNode(ref: Element): boolean {
|
||||||
return document.execCommand('copy');
|
return document.execCommand('copy');
|
||||||
}
|
}
|
||||||
|
|
||||||
const collator = new Intl.Collator();
|
|
||||||
/**
|
|
||||||
* Performant language-sensitive string comparison
|
|
||||||
* @param a the first string to compare
|
|
||||||
* @param b the second string to compare
|
|
||||||
*/
|
|
||||||
export function compare(a: string, b: string): number {
|
|
||||||
return collator.compare(a, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns text which has been selected by the user
|
* Returns text which has been selected by the user
|
||||||
* @returns the selected text
|
* @returns the selected text
|
||||||
|
|
|
@ -20,10 +20,10 @@ import ReactDOM from 'react-dom';
|
||||||
import { Room } from 'matrix-js-sdk/src/models/room';
|
import { Room } from 'matrix-js-sdk/src/models/room';
|
||||||
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
|
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
|
||||||
import { User } from "matrix-js-sdk/src/models/user";
|
import { User } from "matrix-js-sdk/src/models/user";
|
||||||
|
import { compare } from "matrix-js-sdk/src/utils";
|
||||||
|
|
||||||
import { MatrixClientPeg } from '../../../../src/MatrixClientPeg';
|
import { MatrixClientPeg } from '../../../../src/MatrixClientPeg';
|
||||||
import * as TestUtils from '../../../test-utils';
|
import * as TestUtils from '../../../test-utils';
|
||||||
import { compare } from "../../../../src/utils/strings";
|
|
||||||
import MemberList from "../../../../src/components/views/rooms/MemberList";
|
import MemberList from "../../../../src/components/views/rooms/MemberList";
|
||||||
import MemberTile from '../../../../src/components/views/rooms/MemberTile';
|
import MemberTile from '../../../../src/components/views/rooms/MemberTile';
|
||||||
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
|
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue