@@ -43,6 +43,7 @@ import {
43
43
} from "../utils/beacon" ;
44
44
import { getCurrentPosition } from "../utils/beacon" ;
45
45
import { doMaybeLocalRoomAction } from "../utils/local-room" ;
46
+ import SettingsStore from "../settings/SettingsStore" ;
46
47
47
48
const isOwnBeacon = ( beacon : Beacon , userId : string ) : boolean => beacon . beaconInfoOwner === userId ;
48
49
@@ -119,6 +120,10 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
119
120
* when the target is stationary
120
121
*/
121
122
private lastPublishedPositionTimestamp ?: number ;
123
+ /**
124
+ * Ref returned from watchSetting for the MSC3946 labs flag
125
+ */
126
+ private dynamicWatcherRef : string | undefined ;
122
127
123
128
public constructor ( ) {
124
129
super ( defaultDispatcher ) ;
@@ -142,7 +147,12 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
142
147
this . matrixClient . removeListener ( BeaconEvent . Update , this . onUpdateBeacon ) ;
143
148
this . matrixClient . removeListener ( BeaconEvent . Destroy , this . onDestroyBeacon ) ;
144
149
this . matrixClient . removeListener ( RoomStateEvent . Members , this . onRoomStateMembers ) ;
150
+ SettingsStore . unwatchSetting ( this . dynamicWatcherRef ?? "" ) ;
151
+
152
+ this . clearBeacons ( ) ;
153
+ }
145
154
155
+ private clearBeacons ( ) : void {
146
156
this . beacons . forEach ( ( beacon ) => beacon . destroy ( ) ) ;
147
157
148
158
this . stopPollingLocation ( ) ;
@@ -159,6 +169,11 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
159
169
this . matrixClient . on ( BeaconEvent . Update , this . onUpdateBeacon ) ;
160
170
this . matrixClient . on ( BeaconEvent . Destroy , this . onDestroyBeacon ) ;
161
171
this . matrixClient . on ( RoomStateEvent . Members , this . onRoomStateMembers ) ;
172
+ this . dynamicWatcherRef = SettingsStore . watchSetting (
173
+ "feature_dynamic_room_predecessors" ,
174
+ null ,
175
+ this . reinitialiseBeaconState ,
176
+ ) ;
162
177
163
178
this . initialiseBeaconState ( ) ;
164
179
}
@@ -308,9 +323,19 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
308
323
) ;
309
324
}
310
325
326
+ /**
327
+ * @internal public for test only
328
+ */
329
+ public reinitialiseBeaconState = ( ) : void => {
330
+ this . clearBeacons ( ) ;
331
+ this . initialiseBeaconState ( ) ;
332
+ } ;
333
+
311
334
private initialiseBeaconState = ( ) : void => {
312
335
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
+ ) ;
314
339
315
340
visibleRooms . forEach ( ( room ) => {
316
341
const roomState = room . currentState ;
0 commit comments