@@ -15,9 +15,10 @@ limitations under the License.
15
15
*/
16
16
17
17
import {
18
+ Beacon ,
18
19
BeaconEvent ,
20
+ MatrixEvent ,
19
21
Room ,
20
- Beacon ,
21
22
} from "matrix-js-sdk/src/matrix" ;
22
23
23
24
import defaultDispatcher from "../dispatcher/dispatcher" ;
@@ -61,8 +62,8 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
61
62
}
62
63
63
64
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 ) ;
66
67
67
68
this . initialiseBeaconState ( ) ;
68
69
}
@@ -82,15 +83,15 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
82
83
return this . liveBeaconIds . filter ( beaconId => this . beaconsByRoomId . get ( roomId ) ?. has ( beaconId ) ) ;
83
84
}
84
85
85
- private onNewBeacon ( beacon : Beacon ) : void {
86
+ private onNewBeacon = ( _event : MatrixEvent , beacon : Beacon ) : void => {
86
87
if ( ! isOwnBeacon ( beacon , this . matrixClient . getUserId ( ) ) ) {
87
88
return ;
88
89
}
89
90
this . addBeacon ( beacon ) ;
90
91
this . checkLiveness ( ) ;
91
- }
92
+ } ;
92
93
93
- private onBeaconLiveness ( isLive : boolean , beacon : Beacon ) : void {
94
+ private onBeaconLiveness = ( isLive : boolean , beacon : Beacon ) : void => {
94
95
// check if we care about this beacon
95
96
if ( ! this . beacons . has ( beacon . beaconInfoId ) ) {
96
97
return ;
@@ -108,9 +109,9 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
108
109
this . emit ( OwnBeaconStoreEvent . LivenessChange , this . hasLiveBeacons ( ) ) ;
109
110
// TODO stop or start polling here
110
111
// if not content is live but beacon is not, update state event with live: false
111
- }
112
+ } ;
112
113
113
- private initialiseBeaconState ( ) {
114
+ private initialiseBeaconState = ( ) => {
114
115
const userId = this . matrixClient . getUserId ( ) ;
115
116
const visibleRooms = this . matrixClient . getVisibleRooms ( ) ;
116
117
@@ -123,9 +124,9 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
123
124
} ) ;
124
125
125
126
this . checkLiveness ( ) ;
126
- }
127
+ } ;
127
128
128
- private addBeacon ( beacon : Beacon ) : void {
129
+ private addBeacon = ( beacon : Beacon ) : void => {
129
130
this . beacons . set ( beacon . beaconInfoId , beacon ) ;
130
131
131
132
if ( ! this . beaconsByRoomId . has ( beacon . roomId ) ) {
@@ -134,9 +135,9 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
134
135
135
136
this . beaconsByRoomId . get ( beacon . roomId ) . add ( beacon . beaconInfoId ) ;
136
137
beacon . monitorLiveness ( ) ;
137
- }
138
+ } ;
138
139
139
- private checkLiveness ( ) : void {
140
+ private checkLiveness = ( ) : void => {
140
141
const prevLiveness = this . hasLiveBeacons ( ) ;
141
142
this . liveBeaconIds = [ ...this . beacons . values ( ) ]
142
143
. filter ( beacon => beacon . isLive )
@@ -147,5 +148,5 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
147
148
if ( prevLiveness !== newLiveness ) {
148
149
this . emit ( OwnBeaconStoreEvent . LivenessChange , newLiveness ) ;
149
150
}
150
- }
151
+ } ;
151
152
}
0 commit comments