From d459a91af3932c9c3326f2d555c0d36421776868 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Tue, 16 May 2023 11:41:35 +0100 Subject: [PATCH] correctly accumulate sync summaries. (#3366) if a sync summary for (say) invited_member_count goes from 1 to 0, it should be accumluated as 0, rather than 1. Should fix https://github.com/vector-im/element-web/issues/23345 --- spec/unit/sync-accumulator.spec.ts | 17 +++++++++++++++++ src/sync-accumulator.ts | 6 +++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/spec/unit/sync-accumulator.spec.ts b/spec/unit/sync-accumulator.spec.ts index d434e0145ac..cad31d7a325 100644 --- a/spec/unit/sync-accumulator.spec.ts +++ b/spec/unit/sync-accumulator.spec.ts @@ -545,6 +545,23 @@ describe("SyncAccumulator", function () { expect(summary["m.heroes"]).toEqual(["@bob:bar"]); }); + it("should reset summary properties", function () { + sa.accumulate( + createSyncResponseWithSummary({ + "m.heroes": ["@alice:bar"], + "m.invited_member_count": 2, + }), + ); + sa.accumulate( + createSyncResponseWithSummary({ + "m.heroes": ["@alice:bar"], + "m.invited_member_count": 0, + }), + ); + const summary = sa.getJSON().roomsData.join["!foo:bar"].summary; + expect(summary["m.invited_member_count"]).toEqual(0); + }); + it("should return correctly adjusted age attributes", () => { const delta = 1000; const startingTs = 1000; diff --git a/src/sync-accumulator.ts b/src/sync-accumulator.ts index ae6ef13b79b..e25ace53039 100644 --- a/src/sync-accumulator.ts +++ b/src/sync-accumulator.ts @@ -399,9 +399,9 @@ export class SyncAccumulator { const acc = currentData._summary; const sum = data.summary; - acc[HEROES_KEY] = sum[HEROES_KEY] || acc[HEROES_KEY]; - acc[JOINED_COUNT_KEY] = sum[JOINED_COUNT_KEY] || acc[JOINED_COUNT_KEY]; - acc[INVITED_COUNT_KEY] = sum[INVITED_COUNT_KEY] || acc[INVITED_COUNT_KEY]; + acc[HEROES_KEY] = sum[HEROES_KEY] ?? acc[HEROES_KEY]; + acc[JOINED_COUNT_KEY] = sum[JOINED_COUNT_KEY] ?? acc[JOINED_COUNT_KEY]; + acc[INVITED_COUNT_KEY] = sum[INVITED_COUNT_KEY] ?? acc[INVITED_COUNT_KEY]; } // We purposefully do not persist m.typing events.