2025-03-03 16:42:00 +05:30
|
|
|
/*
|
|
|
|
|
Copyright 2025 New Vector Ltd.
|
|
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-03-11 18:59:55 +05:30
|
|
|
import { useCallback } from "react";
|
2025-03-05 14:24:04 +05:30
|
|
|
|
2025-03-03 16:42:00 +05:30
|
|
|
import type { Room } from "matrix-js-sdk/src/matrix";
|
2025-03-05 14:24:04 +05:30
|
|
|
import type { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload";
|
|
|
|
|
import dispatcher from "../../../dispatcher/dispatcher";
|
|
|
|
|
import { Action } from "../../../dispatcher/actions";
|
2025-03-11 18:59:55 +05:30
|
|
|
import { type PrimaryFilter, type SecondaryFilters, useFilteredRooms } from "./useFilteredRooms";
|
2025-03-03 16:42:00 +05:30
|
|
|
|
|
|
|
|
export interface RoomListViewState {
|
|
|
|
|
/**
|
|
|
|
|
* A list of rooms to be displayed in the left panel.
|
|
|
|
|
*/
|
|
|
|
|
rooms: Room[];
|
2025-03-05 14:24:04 +05:30
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Open the room having given roomId.
|
|
|
|
|
*/
|
|
|
|
|
openRoom: (roomId: string) => void;
|
2025-03-10 18:53:38 +05:30
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A list of objects that provide the view enough information
|
|
|
|
|
* to render primary room filters.
|
|
|
|
|
*/
|
|
|
|
|
primaryFilters: PrimaryFilter[];
|
2025-03-11 18:59:55 +05:30
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A function to activate a given secondary filter.
|
|
|
|
|
*/
|
|
|
|
|
activateSecondaryFilter: (filter: SecondaryFilters) => void;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The currently active secondary filter.
|
|
|
|
|
*/
|
|
|
|
|
activeSecondaryFilter: SecondaryFilters;
|
2025-03-03 16:42:00 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* View model for the new room list
|
|
|
|
|
* @see {@link RoomListViewState} for more information about what this view model returns.
|
|
|
|
|
*/
|
|
|
|
|
export function useRoomListViewModel(): RoomListViewState {
|
2025-03-11 18:59:55 +05:30
|
|
|
const { primaryFilters, rooms, activateSecondaryFilter, activeSecondaryFilter } = useFilteredRooms();
|
2025-03-05 14:24:04 +05:30
|
|
|
|
|
|
|
|
const openRoom = useCallback((roomId: string): void => {
|
|
|
|
|
dispatcher.dispatch<ViewRoomPayload>({
|
|
|
|
|
action: Action.ViewRoom,
|
|
|
|
|
room_id: roomId,
|
|
|
|
|
metricsTrigger: "RoomList",
|
|
|
|
|
});
|
|
|
|
|
}, []);
|
|
|
|
|
|
2025-03-10 18:53:38 +05:30
|
|
|
return {
|
|
|
|
|
rooms,
|
|
|
|
|
openRoom,
|
|
|
|
|
primaryFilters,
|
2025-03-11 18:59:55 +05:30
|
|
|
activateSecondaryFilter,
|
|
|
|
|
activeSecondaryFilter,
|
2025-03-10 18:53:38 +05:30
|
|
|
};
|
|
|
|
|
}
|