Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit b27b2c9

Browse files
author
Kerry Archibald
committed
fix OwnBeaconStore more...
Signed-off-by: Kerry Archibald <[email protected]>
1 parent cd224b5 commit b27b2c9

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/stores/OwnBeaconStore.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ limitations under the License.
1515
*/
1616

1717
import {
18+
Beacon,
1819
BeaconEvent,
20+
MatrixEvent,
1921
Room,
20-
Beacon,
2122
} from "matrix-js-sdk/src/matrix";
2223

2324
import defaultDispatcher from "../dispatcher/dispatcher";
@@ -61,8 +62,8 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
6162
}
6263

6364
protected async onReady(): Promise<void> {
64-
this.matrixClient.on(BeaconEvent.LivenessChange, this.onBeaconLiveness.bind(this));
65-
this.matrixClient.on(BeaconEvent.New, this.onNewBeacon.bind(this));
65+
this.matrixClient.on(BeaconEvent.LivenessChange, this.onBeaconLiveness);
66+
this.matrixClient.on(BeaconEvent.New, this.onNewBeacon);
6667

6768
this.initialiseBeaconState();
6869
}
@@ -82,15 +83,15 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
8283
return this.liveBeaconIds.filter(beaconId => this.beaconsByRoomId.get(roomId)?.has(beaconId));
8384
}
8485

85-
private onNewBeacon(beacon: Beacon): void {
86+
private onNewBeacon = (_event: MatrixEvent, beacon: Beacon): void => {
8687
if (!isOwnBeacon(beacon, this.matrixClient.getUserId())) {
8788
return;
8889
}
8990
this.addBeacon(beacon);
9091
this.checkLiveness();
91-
}
92+
};
9293

93-
private onBeaconLiveness(isLive: boolean, beacon: Beacon): void {
94+
private onBeaconLiveness = (isLive: boolean, beacon: Beacon): void => {
9495
// check if we care about this beacon
9596
if (!this.beacons.has(beacon.beaconInfoId)) {
9697
return;
@@ -108,9 +109,9 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
108109
this.emit(OwnBeaconStoreEvent.LivenessChange, this.hasLiveBeacons());
109110
// TODO stop or start polling here
110111
// if not content is live but beacon is not, update state event with live: false
111-
}
112+
};
112113

113-
private initialiseBeaconState() {
114+
private initialiseBeaconState = () => {
114115
const userId = this.matrixClient.getUserId();
115116
const visibleRooms = this.matrixClient.getVisibleRooms();
116117

@@ -123,9 +124,9 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
123124
});
124125

125126
this.checkLiveness();
126-
}
127+
};
127128

128-
private addBeacon(beacon: Beacon): void {
129+
private addBeacon = (beacon: Beacon): void => {
129130
this.beacons.set(beacon.beaconInfoId, beacon);
130131

131132
if (!this.beaconsByRoomId.has(beacon.roomId)) {
@@ -134,9 +135,9 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
134135

135136
this.beaconsByRoomId.get(beacon.roomId).add(beacon.beaconInfoId);
136137
beacon.monitorLiveness();
137-
}
138+
};
138139

139-
private checkLiveness(): void {
140+
private checkLiveness = (): void => {
140141
const prevLiveness = this.hasLiveBeacons();
141142
this.liveBeaconIds = [...this.beacons.values()]
142143
.filter(beacon => beacon.isLive)
@@ -147,5 +148,5 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
147148
if (prevLiveness !== newLiveness) {
148149
this.emit(OwnBeaconStoreEvent.LivenessChange, newLiveness);
149150
}
150-
}
151+
};
151152
}

test/stores/OwnBeaconStore-test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ describe('OwnBeaconStore', () => {
7171

7272
const makeOwnBeaconStore = async () => {
7373
const store = OwnBeaconStore.instance;
74-
// await resetAsyncStoreWithClient(store)
7574

7675
await setupAsyncStoreWithClient(store, mockClient);
7776
return store;
@@ -272,7 +271,7 @@ describe('OwnBeaconStore', () => {
272271
const bobsLiveBeacon = new Beacon(bobsRoom1BeaconInfo);
273272
const monitorSpy = jest.spyOn(bobsLiveBeacon, 'monitorLiveness');
274273

275-
mockClient.emit(BeaconEvent.New, bobsLiveBeacon);
274+
mockClient.emit(BeaconEvent.New, bobsRoom1BeaconInfo, bobsLiveBeacon);
276275

277276
// we dont care about bob
278277
expect(monitorSpy).not.toHaveBeenCalled();
@@ -285,7 +284,7 @@ describe('OwnBeaconStore', () => {
285284
const alicesLiveBeacon = new Beacon(alicesRoom1BeaconInfo);
286285
const monitorSpy = jest.spyOn(alicesLiveBeacon, 'monitorLiveness');
287286

288-
mockClient.emit(BeaconEvent.New, alicesLiveBeacon);
287+
mockClient.emit(BeaconEvent.New, alicesRoom1BeaconInfo, alicesLiveBeacon);
289288

290289
expect(monitorSpy).toHaveBeenCalled();
291290
expect(store.hasLiveBeacons()).toBe(true);
@@ -298,7 +297,7 @@ describe('OwnBeaconStore', () => {
298297
const emitSpy = jest.spyOn(store, 'emit');
299298
const alicesLiveBeacon = new Beacon(alicesRoom1BeaconInfo);
300299

301-
mockClient.emit(BeaconEvent.New, alicesLiveBeacon);
300+
mockClient.emit(BeaconEvent.New, alicesRoom1BeaconInfo, alicesLiveBeacon);
302301

303302
expect(emitSpy).toHaveBeenCalledWith(OwnBeaconStoreEvent.LivenessChange, true);
304303
});
@@ -313,7 +312,7 @@ describe('OwnBeaconStore', () => {
313312
const emitSpy = jest.spyOn(store, 'emit');
314313
const alicesLiveBeacon = new Beacon(alicesRoom1BeaconInfo);
315314

316-
mockClient.emit(BeaconEvent.New, alicesLiveBeacon);
315+
mockClient.emit(BeaconEvent.New, alicesRoom1BeaconInfo, alicesLiveBeacon);
317316

318317
expect(emitSpy).not.toHaveBeenCalled();
319318
});

0 commit comments

Comments
 (0)