Skip to content

Commit 3120ab5

Browse files
committed
2 parents 59ee0a2 + 7bb10a1 commit 3120ab5

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
"eslint-plugin-jsdoc": "^40.0.0",
111111
"eslint-plugin-matrix-org": "^1.0.0",
112112
"eslint-plugin-tsdoc": "^0.2.17",
113-
"eslint-plugin-unicorn": "^45.0.0",
113+
"eslint-plugin-unicorn": "^46.0.0",
114114
"exorcist": "^2.0.0",
115115
"fake-indexeddb": "^4.0.0",
116116
"fetch-mock-jest": "^1.5.1",

src/models/beacon.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ export const getBeaconInfoIdentifier = (event: MatrixEvent): BeaconIdentifier =>
4848
// https://github.com/matrix-org/matrix-spec-proposals/pull/3672
4949
export class Beacon extends TypedEventEmitter<Exclude<BeaconEvent, BeaconEvent.New>, BeaconEventHandlerMap> {
5050
public readonly roomId: string;
51-
private _beaconInfo?: BeaconInfoState;
51+
// beaconInfo is assigned by setBeaconInfo in the constructor
52+
// ! to make tsc believe it is definitely assigned
53+
private _beaconInfo!: BeaconInfoState;
5254
private _isLive?: boolean;
5355
private livenessWatchTimeout?: ReturnType<typeof setTimeout>;
5456
private _latestLocationEvent?: MatrixEvent;
5557

5658
public constructor(private rootEvent: MatrixEvent) {
5759
super();
58-
this.setBeaconInfo(this.rootEvent);
5960
this.roomId = this.rootEvent.getRoomId()!;
61+
this.setBeaconInfo(this.rootEvent);
6062
}
6163

6264
public get isLive(): boolean {
@@ -79,7 +81,7 @@ export class Beacon extends TypedEventEmitter<Exclude<BeaconEvent, BeaconEvent.N
7981
return this.rootEvent.getType();
8082
}
8183

82-
public get beaconInfo(): BeaconInfoState | undefined {
84+
public get beaconInfo(): BeaconInfoState {
8385
return this._beaconInfo;
8486
}
8587

@@ -158,9 +160,9 @@ export class Beacon extends TypedEventEmitter<Exclude<BeaconEvent, BeaconEvent.N
158160
if (!parsed.uri || !parsed.timestamp) return false; // we won't be able to process these
159161
const { timestamp } = parsed;
160162
return (
161-
this._beaconInfo!.timestamp &&
163+
this._beaconInfo.timestamp &&
162164
// only include positions that were taken inside the beacon's live period
163-
isTimestampInDuration(this._beaconInfo!.timestamp, this._beaconInfo!.timeout, timestamp) &&
165+
isTimestampInDuration(this._beaconInfo.timestamp, this._beaconInfo.timeout, timestamp) &&
164166
// ignore positions older than our current latest location
165167
(!this.latestLocationState || timestamp > this.latestLocationState.timestamp!)
166168
);
@@ -196,9 +198,9 @@ export class Beacon extends TypedEventEmitter<Exclude<BeaconEvent, BeaconEvent.N
196198
? this.beaconInfo.timestamp! - 360000 /* 6min */
197199
: this.beaconInfo.timestamp;
198200
this._isLive =
199-
!!this._beaconInfo?.live &&
201+
!!this._beaconInfo.live &&
200202
!!startTimestamp &&
201-
isTimestampInDuration(startTimestamp, this._beaconInfo?.timeout, Date.now());
203+
isTimestampInDuration(startTimestamp, this._beaconInfo.timeout, Date.now());
202204

203205
if (prevLiveness !== this.isLive) {
204206
this.emit(BeaconEvent.LivenessChange, this.isLive, this);

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -3597,10 +3597,10 @@ eslint-plugin-tsdoc@^0.2.17:
35973597
"@microsoft/tsdoc" "0.14.2"
35983598
"@microsoft/tsdoc-config" "0.16.2"
35993599

3600-
eslint-plugin-unicorn@^45.0.0:
3601-
version "45.0.2"
3602-
resolved "https://registry.yarnpkg.com/eslint-plugin-unicorn/-/eslint-plugin-unicorn-45.0.2.tgz#d6ba704793a6909fe5dfe013900d2b05b715284c"
3603-
integrity sha512-Y0WUDXRyGDMcKLiwgL3zSMpHrXI00xmdyixEGIg90gHnj0PcHY4moNv3Ppje/kDivdAy5vUeUr7z211ImPv2gw==
3600+
eslint-plugin-unicorn@^46.0.0:
3601+
version "46.0.0"
3602+
resolved "https://registry.yarnpkg.com/eslint-plugin-unicorn/-/eslint-plugin-unicorn-46.0.0.tgz#b5cdcc9465fd6e46ab7968b87dd4a43adc8d6031"
3603+
integrity sha512-j07WkC+PFZwk8J33LYp6JMoHa1lXc1u6R45pbSAipjpfpb7KIGr17VE2D685zCxR5VL4cjrl65kTJflziQWMDA==
36043604
dependencies:
36053605
"@babel/helper-validator-identifier" "^7.19.1"
36063606
"@eslint-community/eslint-utils" "^4.1.2"

0 commit comments

Comments
 (0)