Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Deduplicate string compare utility (#9579)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored and Amy Walker committed Nov 28, 2022
1 parent 75efdd0 commit d78ff4a
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/components/views/rooms/WhoIsTypingTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import React from 'react';
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
import { RoomMember, RoomMemberEvent } from "matrix-js-sdk/src/models/room-member";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { compare } from "matrix-js-sdk/src/utils";

import * as WhoIsTyping from '../../../WhoIsTyping';
import Timer from '../../../utils/Timer';
import { MatrixClientPeg } from '../../../MatrixClientPeg';
import MemberAvatar from '../avatars/MemberAvatar';
import { compare } from "../../../utils/strings";

interface IProps {
// the room this statusbar is representing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { logger } from "matrix-js-sdk/src/logger";
import { throttle } from "lodash";
import { compare } from "matrix-js-sdk/src/utils";

import { _t, _td } from "../../../../../languageHandler";
import { MatrixClientPeg } from "../../../../../MatrixClientPeg";
import AccessibleButton from "../../../elements/AccessibleButton";
import Modal from "../../../../../Modal";
import { compare } from "../../../../../utils/strings";
import ErrorDialog from '../../../dialogs/ErrorDialog';
import PowerSelector from "../../../elements/PowerSelector";
import SettingsFieldset from '../../SettingsFieldset';
Expand Down
2 changes: 1 addition & 1 deletion src/integrations/IntegrationManagers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
import url from 'url';
import { logger } from "matrix-js-sdk/src/logger";
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 SdkConfig from '../SdkConfig';
Expand All @@ -26,7 +27,6 @@ import IntegrationsImpossibleDialog from "../components/views/dialogs/Integratio
import IntegrationsDisabledDialog from "../components/views/dialogs/IntegrationsDisabledDialog";
import WidgetUtils from "../utils/WidgetUtils";
import { MatrixClientPeg } from "../MatrixClientPeg";
import { compare } from "../utils/strings";

const KIND_PREFERENCE = [
// Ordered: first is most preferred, last is least preferred.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ limitations under the License.
*/

import { Room } from "matrix-js-sdk/src/models/room";
import { compare } from "matrix-js-sdk/src/utils";

import { TagID } from "../../models";
import { IAlgorithm } from "./IAlgorithm";
import { compare } from "../../../../utils/strings";

/**
* Sorts rooms according to the browser's determination of alphabetic.
Expand Down
2 changes: 1 addition & 1 deletion src/stores/widgets/WidgetLayoutStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Room } from "matrix-js-sdk/src/models/room";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { Optional } from "matrix-events-sdk";
import { compare } from "matrix-js-sdk/src/utils";

import SettingsStore from "../../settings/SettingsStore";
import WidgetStore, { IApp } from "../WidgetStore";
Expand All @@ -28,7 +29,6 @@ import { ReadyWatchingStore } from "../ReadyWatchingStore";
import { SettingLevel } from "../../settings/SettingLevel";
import { arrayFastClone } from "../../utils/arrays";
import { UPDATE_EVENT } from "../AsyncStore";
import { compare } from "../../utils/strings";

export const WIDGET_LAYOUT_EVENT_TYPE = "io.element.widgets.layout";

Expand Down
3 changes: 2 additions & 1 deletion src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { compare } from "matrix-js-sdk/src/utils";

import { _t } from "./languageHandler";
import SettingsStore from "./settings/SettingsStore";
import ThemeWatcher from "./settings/watchers/ThemeWatcher";
import { compare } from "./utils/strings";

export const DEFAULT_THEME = "light";
const HIGH_CONTRAST_THEMES = {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/SortMembers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ limitations under the License.

import { groupBy, mapValues, maxBy, minBy, sumBy, takeRight } from "lodash";
import { MatrixClient, Room, RoomMember } from "matrix-js-sdk/src/matrix";
import { compare } from "matrix-js-sdk/src/utils";

import { Member } from "./direct-messages";
import DMRoomMap from "./DMRoomMap";
import { compare } from "./strings";

export const compareMembers = (
activityScores: Record<string, IActivityScore>,
Expand Down
10 changes: 0 additions & 10 deletions src/utils/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,6 @@ export function copyNode(ref: Element): boolean {
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 the selected text
Expand Down
2 changes: 1 addition & 1 deletion test/components/views/rooms/MemberList-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import ReactDOM from 'react-dom';
import { Room } from 'matrix-js-sdk/src/models/room';
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
import { User } from "matrix-js-sdk/src/models/user";
import { compare } from "matrix-js-sdk/src/utils";

import { MatrixClientPeg } from '../../../../src/MatrixClientPeg';
import * as TestUtils from '../../../test-utils';
import { compare } from "../../../../src/utils/strings";
import MemberList from "../../../../src/components/views/rooms/MemberList";
import MemberTile from '../../../../src/components/views/rooms/MemberTile';
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
Expand Down

0 comments on commit d78ff4a

Please sign in to comment.