2020-03-20 14:38:20 -06:00
|
|
|
/*
|
|
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import SettingsStore from "../../settings/SettingsStore";
|
|
|
|
|
import RoomListStore from "./RoomListStore2";
|
|
|
|
|
import OldRoomListStore from "../RoomListStore";
|
2020-04-27 15:25:04 -06:00
|
|
|
import { UPDATE_EVENT } from "../AsyncStore";
|
2020-05-11 16:12:45 -06:00
|
|
|
import { ITagMap } from "./algorithms/models";
|
2020-03-20 14:38:20 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Temporary RoomListStore proxy. Should be replaced with RoomListStore2 when
|
|
|
|
|
* it is available to everyone.
|
|
|
|
|
*
|
2020-06-28 20:03:04 -06:00
|
|
|
* TODO: Delete this: https://github.com/vector-im/riot-web/issues/14231
|
2020-03-20 14:38:20 -06:00
|
|
|
*/
|
|
|
|
|
export class RoomListStoreTempProxy {
|
|
|
|
|
public static isUsingNewStore(): boolean {
|
2020-07-07 13:56:46 -06:00
|
|
|
return SettingsStore.getValue("feature_new_room_list");
|
2020-03-20 14:38:20 -06:00
|
|
|
}
|
|
|
|
|
|
2020-06-09 15:26:13 -06:00
|
|
|
public static addListener(handler: () => void): RoomListStoreTempToken {
|
2020-03-20 14:38:20 -06:00
|
|
|
if (RoomListStoreTempProxy.isUsingNewStore()) {
|
2020-06-09 15:26:13 -06:00
|
|
|
const offFn = () => RoomListStore.instance.off(UPDATE_EVENT, handler);
|
|
|
|
|
RoomListStore.instance.on(UPDATE_EVENT, handler);
|
|
|
|
|
return new RoomListStoreTempToken(offFn);
|
2020-03-20 14:38:20 -06:00
|
|
|
} else {
|
2020-06-09 15:26:13 -06:00
|
|
|
const token = OldRoomListStore.addListener(handler);
|
|
|
|
|
return new RoomListStoreTempToken(() => token.remove());
|
2020-03-20 14:38:20 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-27 15:25:04 -06:00
|
|
|
public static getRoomLists(): ITagMap {
|
2020-03-20 14:38:20 -06:00
|
|
|
if (RoomListStoreTempProxy.isUsingNewStore()) {
|
|
|
|
|
return RoomListStore.instance.orderedLists;
|
|
|
|
|
} else {
|
|
|
|
|
return OldRoomListStore.getRoomLists();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-09 15:26:13 -06:00
|
|
|
|
|
|
|
|
export class RoomListStoreTempToken {
|
|
|
|
|
constructor(private offFn: () => void) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public remove(): void {
|
|
|
|
|
this.offFn();
|
|
|
|
|
}
|
|
|
|
|
}
|