Skip to content

Commit

Permalink
correctly accumulate sync summaries. (#3366)
Browse files Browse the repository at this point in the history
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 element-hq/element-web#23345
  • Loading branch information
ara4n authored May 16, 2023
1 parent 5119934 commit d459a91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
17 changes: 17 additions & 0 deletions spec/unit/sync-accumulator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/sync-accumulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d459a91

Please sign in to comment.