Support dynamic room predecessors in OwnBeaconStore (#10339)
* Support dynamic room predecessors in OwnBeaconStore * Fix type of dynamicWatcherRef * Mock a function missing from client
This commit is contained in:
parent
50229abf1e
commit
b646250c90
3 changed files with 66 additions and 1 deletions
|
@ -43,6 +43,7 @@ import {
|
|||
} from "../utils/beacon";
|
||||
import { getCurrentPosition } from "../utils/beacon";
|
||||
import { doMaybeLocalRoomAction } from "../utils/local-room";
|
||||
import SettingsStore from "../settings/SettingsStore";
|
||||
|
||||
const isOwnBeacon = (beacon: Beacon, userId: string): boolean => beacon.beaconInfoOwner === userId;
|
||||
|
||||
|
@ -119,6 +120,10 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
|
|||
* when the target is stationary
|
||||
*/
|
||||
private lastPublishedPositionTimestamp?: number;
|
||||
/**
|
||||
* Ref returned from watchSetting for the MSC3946 labs flag
|
||||
*/
|
||||
private dynamicWatcherRef: string | undefined;
|
||||
|
||||
public constructor() {
|
||||
super(defaultDispatcher);
|
||||
|
@ -142,7 +147,12 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
|
|||
this.matrixClient.removeListener(BeaconEvent.Update, this.onUpdateBeacon);
|
||||
this.matrixClient.removeListener(BeaconEvent.Destroy, this.onDestroyBeacon);
|
||||
this.matrixClient.removeListener(RoomStateEvent.Members, this.onRoomStateMembers);
|
||||
SettingsStore.unwatchSetting(this.dynamicWatcherRef ?? "");
|
||||
|
||||
this.clearBeacons();
|
||||
}
|
||||
|
||||
private clearBeacons(): void {
|
||||
this.beacons.forEach((beacon) => beacon.destroy());
|
||||
|
||||
this.stopPollingLocation();
|
||||
|
@ -159,6 +169,11 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
|
|||
this.matrixClient.on(BeaconEvent.Update, this.onUpdateBeacon);
|
||||
this.matrixClient.on(BeaconEvent.Destroy, this.onDestroyBeacon);
|
||||
this.matrixClient.on(RoomStateEvent.Members, this.onRoomStateMembers);
|
||||
this.dynamicWatcherRef = SettingsStore.watchSetting(
|
||||
"feature_dynamic_room_predecessors",
|
||||
null,
|
||||
this.reinitialiseBeaconState,
|
||||
);
|
||||
|
||||
this.initialiseBeaconState();
|
||||
}
|
||||
|
@ -308,9 +323,19 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal public for test only
|
||||
*/
|
||||
public reinitialiseBeaconState = (): void => {
|
||||
this.clearBeacons();
|
||||
this.initialiseBeaconState();
|
||||
};
|
||||
|
||||
private initialiseBeaconState = (): void => {
|
||||
const userId = this.matrixClient.getUserId()!;
|
||||
const visibleRooms = this.matrixClient.getVisibleRooms();
|
||||
const visibleRooms = this.matrixClient.getVisibleRooms(
|
||||
SettingsStore.getValue("feature_dynamic_room_predecessors"),
|
||||
);
|
||||
|
||||
visibleRooms.forEach((room) => {
|
||||
const roomState = room.currentState;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue