Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better fallback for the event localTimestamp calculation. #3900

Merged
merged 9 commits into from
Nov 20, 2023
2 changes: 1 addition & 1 deletion spec/unit/matrixrtc/CallMembership.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe("CallMembership", () => {

it("considers memberships expired when local age large", () => {
const fakeEvent = makeMockEvent(1000);
fakeEvent.getLocalAge = jest.fn().mockReturnValue(6000);
fakeEvent.localTimestamp = Date.now() - 6000;
const membership = new CallMembership(fakeEvent, membershipTemplate);
expect(membership.isExpired()).toEqual(true);
});
Expand Down
3 changes: 1 addition & 2 deletions spec/unit/matrixrtc/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ export function mockRTCEvent(
}),
getSender: jest.fn().mockReturnValue("@mock:user.example"),
getTs: jest.fn().mockReturnValue(1000),
getLocalAge: getLocalAgeFn,
localTimestamp: Date.now(),
localTimestamp: Date.now() - getLocalAgeFn(),
toger5 marked this conversation as resolved.
Show resolved Hide resolved
getRoomId: jest.fn().mockReturnValue(roomId),
sender: {
userId: "@mock:user.example",
Expand Down
2 changes: 1 addition & 1 deletion src/matrixrtc/CallMembership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class CallMembership {
}

public isExpired(): boolean {
return this.getAbsoluteExpiry() < this.parentEvent.getTs() + this.parentEvent.getLocalAge();
return this.getMsUntilExpiry() <= 0;
toger5 marked this conversation as resolved.
Show resolved Hide resolved
}

public getActiveFoci(): Focus[] {
Expand Down
3 changes: 2 additions & 1 deletion src/models/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
});

this.txnId = event.txn_id;
this.localTimestamp = Date.now() - (this.getAge() ?? 0);
const age = this.getAge();
this.localTimestamp = age ? Date.now() - age : this.getTs() ?? 0;
toger5 marked this conversation as resolved.
Show resolved Hide resolved
this.reEmitter = new TypedReEmitter(this);
}

Expand Down
Loading