From 84bd8ab81faf90983690801a54020eb31be24844 Mon Sep 17 00:00:00 2001 From: Timo <16718859+toger5@users.noreply.github.com> Date: Mon, 6 Nov 2023 18:12:24 +0100 Subject: [PATCH] Better fallback for unavailable event age (#3854) * Age fallback using origin_server_ts instead of 0 Signed-off-by: Timo K * use getMsUntilExpiry for isExpired Signed-off-by: Timo K * fix tests tests now also rely on localTimestamp. So this need to be mocked as well Signed-off-by: Timo K * better fallback for unavailable unsigned Signed-off-by: Timo K --------- Signed-off-by: Timo K --- spec/unit/matrixrtc/CallMembership.spec.ts | 4 +++- spec/unit/matrixrtc/mocks.ts | 2 +- src/matrixrtc/CallMembership.ts | 2 +- src/models/event.ts | 19 +++++++++++++++++-- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/spec/unit/matrixrtc/CallMembership.spec.ts b/spec/unit/matrixrtc/CallMembership.spec.ts index 4bc5492e06d..eb4b1232a18 100644 --- a/spec/unit/matrixrtc/CallMembership.spec.ts +++ b/spec/unit/matrixrtc/CallMembership.spec.ts @@ -85,7 +85,9 @@ describe("CallMembership", () => { it("considers memberships expired when local age large", () => { const fakeEvent = makeMockEvent(1000); - fakeEvent.getLocalAge = jest.fn().mockReturnValue(6000); + const evAge = 6000; + fakeEvent.getLocalAge = jest.fn().mockReturnValue(evAge); + fakeEvent.localTimestamp = Date.now() - evAge; const membership = new CallMembership(fakeEvent, membershipTemplate); expect(membership.isExpired()).toEqual(true); }); diff --git a/spec/unit/matrixrtc/mocks.ts b/spec/unit/matrixrtc/mocks.ts index f710c49ab7f..c373cdf9dc4 100644 --- a/spec/unit/matrixrtc/mocks.ts +++ b/spec/unit/matrixrtc/mocks.ts @@ -61,7 +61,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(), getRoomId: jest.fn().mockReturnValue(roomId), sender: { userId: "@mock:user.example", diff --git a/src/matrixrtc/CallMembership.ts b/src/matrixrtc/CallMembership.ts index d304c9df4d9..d24b32adda8 100644 --- a/src/matrixrtc/CallMembership.ts +++ b/src/matrixrtc/CallMembership.ts @@ -91,7 +91,7 @@ export class CallMembership { } public isExpired(): boolean { - return this.getAbsoluteExpiry() < this.parentEvent.getTs() + this.parentEvent.getLocalAge(); + return this.getMsUntilExpiry() <= 0; } public getActiveFoci(): Focus[] { diff --git a/src/models/event.ts b/src/models/event.ts index d2044eec970..8768c0cd906 100644 --- a/src/models/event.ts +++ b/src/models/event.ts @@ -392,7 +392,7 @@ export class MatrixEvent extends TypedEventEmitter