Skip to content

Commit

Permalink
Merge pull request #393 from matrix-org/kegan/sync-accumulator-limited
Browse files Browse the repository at this point in the history
Handle 'limited' timeline responses in the SyncAccumulator
  • Loading branch information
kegsay authored Mar 16, 2017
2 parents 9d8e81d + c306700 commit dec4e67
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
35 changes: 35 additions & 0 deletions spec/unit/sync-accumulator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,41 @@ describe("SyncAccumulator", function() {
expect(output.timeline.prev_batch).toEqual("pinned_to_8");
});

it("should remove the stored timeline on limited syncs", () => {
sa.accumulate(syncSkeleton({
state: { events: [member("alice", "join")] },
timeline: {
events: [
msg("alice", "1"),
msg("alice", "2"),
msg("alice", "3"),
],
prev_batch: "pinned_to_1",
},
}));
// some time passes and now we get a limited sync
sa.accumulate(syncSkeleton({
state: { events: [] },
timeline: {
limited: true,
events: [
msg("alice", "51"),
msg("alice", "52"),
msg("alice", "53"),
],
prev_batch: "pinned_to_51",
},
}));

const output = sa.getJSON().roomsData.join["!foo:bar"];

expect(output.timeline.events.length).toEqual(3);
output.timeline.events.forEach((e, i) => {
expect(e.content.body).toEqual(""+(i+51));
});
expect(output.timeline.prev_batch).toEqual("pinned_to_51");
});

it("should drop typing notifications", () => {
const res = syncSkeleton({
ephemeral: {
Expand Down
6 changes: 6 additions & 0 deletions src/sync-accumulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ class SyncAccumulator {
});
}

// if we got a limited sync, we need to remove all timeline entries or else
// we will have gaps in the timeline.
if (data.timeline && data.timeline.limited) {
currentData._timeline = [];
}

// Work out the current state. The deltas need to be applied in the order:
// - existing state which didn't come down /sync.
// - State events under the 'state' key.
Expand Down

0 comments on commit dec4e67

Please sign in to comment.