@@ -43,6 +43,7 @@ import {
4343} from "../utils/beacon" ;
4444import { getCurrentPosition } from "../utils/beacon" ;
4545import { doMaybeLocalRoomAction } from "../utils/local-room" ;
46+ import SettingsStore from "../settings/SettingsStore" ;
4647
4748const isOwnBeacon = ( beacon : Beacon , userId : string ) : boolean => beacon . beaconInfoOwner === userId ;
4849
@@ -119,6 +120,10 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
119120 * when the target is stationary
120121 */
121122 private lastPublishedPositionTimestamp ?: number ;
123+ /**
124+ * Ref returned from watchSetting for the MSC3946 labs flag
125+ */
126+ private dynamicWatcherRef : string | undefined ;
122127
123128 public constructor ( ) {
124129 super ( defaultDispatcher ) ;
@@ -142,7 +147,12 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
142147 this . matrixClient . removeListener ( BeaconEvent . Update , this . onUpdateBeacon ) ;
143148 this . matrixClient . removeListener ( BeaconEvent . Destroy , this . onDestroyBeacon ) ;
144149 this . matrixClient . removeListener ( RoomStateEvent . Members , this . onRoomStateMembers ) ;
150+ SettingsStore . unwatchSetting ( this . dynamicWatcherRef ?? "" ) ;
151+
152+ this . clearBeacons ( ) ;
153+ }
145154
155+ private clearBeacons ( ) : void {
146156 this . beacons . forEach ( ( beacon ) => beacon . destroy ( ) ) ;
147157
148158 this . stopPollingLocation ( ) ;
@@ -159,6 +169,11 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
159169 this . matrixClient . on ( BeaconEvent . Update , this . onUpdateBeacon ) ;
160170 this . matrixClient . on ( BeaconEvent . Destroy , this . onDestroyBeacon ) ;
161171 this . matrixClient . on ( RoomStateEvent . Members , this . onRoomStateMembers ) ;
172+ this . dynamicWatcherRef = SettingsStore . watchSetting (
173+ "feature_dynamic_room_predecessors" ,
174+ null ,
175+ this . reinitialiseBeaconState ,
176+ ) ;
162177
163178 this . initialiseBeaconState ( ) ;
164179 }
@@ -308,9 +323,19 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
308323 ) ;
309324 }
310325
326+ /**
327+ * @internal public for test only
328+ */
329+ public reinitialiseBeaconState = ( ) : void => {
330+ this . clearBeacons ( ) ;
331+ this . initialiseBeaconState ( ) ;
332+ } ;
333+
311334 private initialiseBeaconState = ( ) : void => {
312335 const userId = this . matrixClient . getUserId ( ) ! ;
313- const visibleRooms = this . matrixClient . getVisibleRooms ( ) ;
336+ const visibleRooms = this . matrixClient . getVisibleRooms (
337+ SettingsStore . getValue ( "feature_dynamic_room_predecessors" ) ,
338+ ) ;
314339
315340 visibleRooms . forEach ( ( room ) => {
316341 const roomState = room . currentState ;
0 commit comments