diff --git a/src/Searching.ts b/src/Searching.ts index ce3ea96c72e..f868942b523 100644 --- a/src/Searching.ts +++ b/src/Searching.ts @@ -681,3 +681,49 @@ export default function eventSearch( return eventIndexSearch(client, term, roomId, abortSignal); } } + +/** + * The scope for a message search, either in the current room or across all rooms. + */ +export enum SearchScope { + Room = "Room", + All = "All", +} + +/** + * Information about a message search in progress. + */ +export interface SearchInfo { + /** + * Opaque ID for this search. + */ + searchId: number; + /** + * The room ID being searched, or undefined if searching all rooms. + */ + roomId?: string; + /** + * The search term. + */ + term: string; + /** + * The scope of the search. + */ + scope: SearchScope; + /** + * The promise for the search results. + */ + promise: Promise; + /** + * Controller for aborting the search. + */ + abortController?: AbortController; + /** + * Whether the search is currently awaiting data from the backend. + */ + inProgress?: boolean; + /** + * The total count of matching results as returned by the backend. + */ + count?: number; +} diff --git a/src/components/structures/RoomSearchView.tsx b/src/components/structures/RoomSearchView.tsx index aedf2cea396..7e080572117 100644 --- a/src/components/structures/RoomSearchView.tsx +++ b/src/components/structures/RoomSearchView.tsx @@ -24,12 +24,11 @@ import { import { logger } from "matrix-js-sdk/src/logger"; import ScrollPanel from "./ScrollPanel"; -import { SearchScope } from "../views/rooms/SearchBar"; import Spinner from "../views/elements/Spinner"; import { _t } from "../../languageHandler"; import { haveRendererForEvent } from "../../events/EventTileFactory"; import SearchResultTile from "../views/rooms/SearchResultTile"; -import { searchPagination } from "../../Searching"; +import { searchPagination, SearchScope } from "../../Searching"; import Modal from "../../Modal"; import ErrorDialog from "../views/dialogs/ErrorDialog"; import ResizeNotifier from "../../utils/ResizeNotifier"; diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index 25686c53c60..3ed1c52e891 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -70,10 +70,10 @@ import TimelinePanel from "./TimelinePanel"; import ErrorBoundary from "../views/elements/ErrorBoundary"; import RoomPreviewBar from "../views/rooms/RoomPreviewBar"; import RoomPreviewCard from "../views/rooms/RoomPreviewCard"; -import SearchBar, { SearchScope } from "../views/rooms/SearchBar"; +import SearchBar from "../views/rooms/SearchBar"; import RoomUpgradeWarningBar from "../views/rooms/RoomUpgradeWarningBar"; import AuxPanel from "../views/rooms/AuxPanel"; -import LegacyRoomHeader, { ISearchInfo } from "../views/rooms/LegacyRoomHeader"; +import LegacyRoomHeader from "../views/rooms/LegacyRoomHeader"; import RoomHeader from "../views/rooms/RoomHeader"; import { IOOBData, IThreepidInvite } from "../../stores/ThreepidInviteStore"; import EffectsOverlay from "../views/elements/EffectsOverlay"; @@ -121,7 +121,7 @@ import { SDKContext } from "../../contexts/SDKContext"; import { CallStore, CallStoreEvent } from "../../stores/CallStore"; import { Call } from "../../models/Call"; import { RoomSearchView } from "./RoomSearchView"; -import eventSearch from "../../Searching"; +import eventSearch, { SearchInfo, SearchScope } from "../../Searching"; import VoipUserMapper from "../../VoipUserMapper"; import { isCallEvent } from "./LegacyCallEventGrouper"; import { WidgetType } from "../../widgets/WidgetType"; @@ -190,7 +190,7 @@ export interface IRoomState { /** * The state of an ongoing search if there is one. */ - search?: ISearchInfo; + search?: SearchInfo; callState?: CallState; activeCall: Call | null; canPeek: boolean; diff --git a/src/components/views/rooms/LegacyRoomHeader.tsx b/src/components/views/rooms/LegacyRoomHeader.tsx index 82080fbd07a..c6fa28fc7ca 100644 --- a/src/components/views/rooms/LegacyRoomHeader.tsx +++ b/src/components/views/rooms/LegacyRoomHeader.tsx @@ -18,7 +18,7 @@ limitations under the License. import React, { FC, useState, useMemo, useCallback } from "react"; import classNames from "classnames"; import { throttle } from "lodash"; -import { RoomStateEvent, ISearchResults } from "matrix-js-sdk/src/matrix"; +import { RoomStateEvent } from "matrix-js-sdk/src/matrix"; import { CallType } from "matrix-js-sdk/src/webrtc/call"; import { IconButton, Tooltip } from "@vector-im/compound-web"; import { ViewRoomOpts } from "@matrix-org/react-sdk-module-api/lib/lifecycles/RoomViewLifecycle"; @@ -38,7 +38,6 @@ import RoomName from "../elements/RoomName"; import { E2EStatus } from "../../../utils/ShieldUtils"; import { IOOBData } from "../../../stores/ThreepidInviteStore"; import { RoomKnocksBar } from "./RoomKnocksBar"; -import { SearchScope } from "./SearchBar"; import { aboveLeftOf, ContextMenuTooltipButton, useContextMenu } from "../../structures/ContextMenu"; import RoomContextMenu from "../context_menus/RoomContextMenu"; import { contextMenuBelow } from "./RoomTile"; @@ -70,6 +69,7 @@ import { SessionDuration } from "../voip/CallDuration"; import RoomCallBanner from "../beacon/RoomCallBanner"; import { shouldShowComponent } from "../../../customisations/helpers/UIComponents"; import { UIComponent } from "../../../settings/UIFeature"; +import { SearchInfo } from "../../../Searching"; class DisabledWithReason { public constructor(public readonly reason: string) {} @@ -456,18 +456,6 @@ const CallLayoutSelector: FC = ({ call }) => { ); }; -export interface ISearchInfo { - searchId: number; - roomId?: string; - term: string; - scope: SearchScope; - promise: Promise; - abortController?: AbortController; - - inProgress?: boolean; - count?: number; -} - export interface IProps { room: Room; oobData?: IOOBData; @@ -478,7 +466,7 @@ export interface IProps { onAppsClick: (() => void) | null; e2eStatus: E2EStatus; appsShown: boolean; - searchInfo?: ISearchInfo; + searchInfo?: SearchInfo; excludedRightPanelPhaseButtons?: Array; showButtons?: boolean; enableRoomOptionsMenu?: boolean; diff --git a/src/components/views/rooms/SearchBar.tsx b/src/components/views/rooms/SearchBar.tsx index aa67bc16cf4..19b076f11d2 100644 --- a/src/components/views/rooms/SearchBar.tsx +++ b/src/components/views/rooms/SearchBar.tsx @@ -24,6 +24,7 @@ import { PosthogScreenTracker } from "../../../PosthogTrackers"; import { getKeyBindingsManager } from "../../../KeyBindingsManager"; import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts"; import SearchWarning, { WarningKind } from "../elements/SearchWarning"; +import { SearchScope } from "../../../Searching"; interface IProps { onCancelClick: () => void; @@ -36,11 +37,6 @@ interface IState { scope: SearchScope; } -export enum SearchScope { - Room = "Room", - All = "All", -} - export default class SearchBar extends React.Component { private searchTerm: RefObject = createRef(); diff --git a/test/components/structures/RoomSearchView-test.tsx b/test/components/structures/RoomSearchView-test.tsx index 5d69f6595a3..7ba39283b65 100644 --- a/test/components/structures/RoomSearchView-test.tsx +++ b/test/components/structures/RoomSearchView-test.tsx @@ -29,15 +29,15 @@ import { import { defer } from "matrix-js-sdk/src/utils"; import { RoomSearchView } from "../../../src/components/structures/RoomSearchView"; -import { SearchScope } from "../../../src/components/views/rooms/SearchBar"; import ResizeNotifier from "../../../src/utils/ResizeNotifier"; import { stubClient } from "../../test-utils"; import MatrixClientContext from "../../../src/contexts/MatrixClientContext"; import { MatrixClientPeg } from "../../../src/MatrixClientPeg"; -import { searchPagination } from "../../../src/Searching"; +import { searchPagination, SearchScope } from "../../../src/Searching"; jest.mock("../../../src/Searching", () => ({ searchPagination: jest.fn(), + SearchScope: jest.requireActual("../../../src/Searching").SearchScope, })); describe("", () => { diff --git a/test/components/structures/RoomView-test.tsx b/test/components/structures/RoomView-test.tsx index 8624e562468..37351cc4e5d 100644 --- a/test/components/structures/RoomView-test.tsx +++ b/test/components/structures/RoomView-test.tsx @@ -70,7 +70,7 @@ import WidgetUtils from "../../../src/utils/WidgetUtils"; import { WidgetType } from "../../../src/widgets/WidgetType"; import WidgetStore from "../../../src/stores/WidgetStore"; import { ViewRoomErrorPayload } from "../../../src/dispatcher/payloads/ViewRoomErrorPayload"; -import { SearchScope } from "../../../src/components/views/rooms/SearchBar"; +import { SearchScope } from "../../../src/Searching"; const RoomView = wrapInMatrixClientContext(_RoomView); diff --git a/test/components/views/rooms/LegacyRoomHeader-test.tsx b/test/components/views/rooms/LegacyRoomHeader-test.tsx index c01d749eeab..f13c9fce9a7 100644 --- a/test/components/views/rooms/LegacyRoomHeader-test.tsx +++ b/test/components/views/rooms/LegacyRoomHeader-test.tsx @@ -51,7 +51,6 @@ import { import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; import DMRoomMap from "../../../../src/utils/DMRoomMap"; import RoomHeader, { IProps as RoomHeaderProps } from "../../../../src/components/views/rooms/LegacyRoomHeader"; -import { SearchScope } from "../../../../src/components/views/rooms/SearchBar"; import { E2EStatus } from "../../../../src/utils/ShieldUtils"; import { IRoomState } from "../../../../src/components/structures/RoomView"; import RoomContext from "../../../../src/contexts/RoomContext"; @@ -69,6 +68,7 @@ import { shouldShowComponent } from "../../../../src/customisations/helpers/UICo import { UIComponent } from "../../../../src/settings/UIFeature"; import WidgetUtils from "../../../../src/utils/WidgetUtils"; import { ElementWidgetActions } from "../../../../src/stores/widgets/ElementWidgetActions"; +import { SearchScope } from "../../../../src/Searching"; jest.mock("../../../../src/customisations/helpers/UIComponents", () => ({ shouldShowComponent: jest.fn(), diff --git a/test/components/views/rooms/SearchBar-test.tsx b/test/components/views/rooms/SearchBar-test.tsx index 2dc44c1cb52..830b66e3bef 100644 --- a/test/components/views/rooms/SearchBar-test.tsx +++ b/test/components/views/rooms/SearchBar-test.tsx @@ -17,8 +17,9 @@ limitations under the License. import React from "react"; import { fireEvent, render } from "@testing-library/react"; -import SearchBar, { SearchScope } from "../../../../src/components/views/rooms/SearchBar"; +import SearchBar from "../../../../src/components/views/rooms/SearchBar"; import { KeyBindingAction } from "../../../../src/accessibility/KeyboardShortcuts"; +import { SearchScope } from "../../../../src/Searching"; let mockCurrentEvent = KeyBindingAction.Enter;