Skip to content

Commit

Permalink
modules/client/sync: Fix conditions to duplicate state in timeline; i…
Browse files Browse the repository at this point in the history
…mprove inconsistencies.
  • Loading branch information
jevolk committed Dec 26, 2020
1 parent a5d3cfb commit eefd59d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
39 changes: 22 additions & 17 deletions modules/client/sync/rooms/state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,28 @@ ircd::m::sync::room_state_linear_events(data &data)
room::events::viewport_size
};

// Figure out whether the event was included in the timeline or whether
// to include it here in the state, which comes before the timeline.
// Since linear-sync is already distinct from polylog-sync, the
// overwhelming majority of state events coming through linear-sync will
// use the timeline. We make an exception for past state events the server
// only recently obtained, to hide them from the timeline.
if(viewport_size >= 0 && data.membership != "invite" && !is_own_join)
{
if(json::get<"depth"_>(*data.event) + viewport_size >= data.room_depth)
return false;

// We also query whether this state cell has been overwritten.
// Unlike the timeline, the state field will not be processed
// sequentially by our client so we can skip outdated events.
if(m::room::state::next(data.event_idx))
return false;
}
const auto sounding
{
data.room_depth - json::get<"depth"_>(*data.event)
};

// Figure out whether the event was included in the timeline
const bool viewport_visible
{
viewport_size <= 0
|| data.membership == "invite"
|| sounding < viewport_size
};

// Query whether this state cell has been overwritten. Unlike the timeline,
// the state field will not be processed sequentially by our client.
const bool stale
{
m::room::state::next(data.event_idx) != 0
};

if(!viewport_visible && stale)
return false;

json::stack::object rooms
{
Expand Down
9 changes: 4 additions & 5 deletions modules/client/sync/rooms/timeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,10 @@ ircd::m::sync::room_timeline_linear(data &data)
};

assert(sounding >= 0);
const bool is_stale
const bool viewport_visible
{
sounding
&& viewport_size >= 0
&& sounding > viewport_size
viewport_size <= 0
|| sounding < viewport_size
};

const bool is_own_membership
Expand Down Expand Up @@ -154,7 +153,7 @@ ircd::m::sync::room_timeline_linear(data &data)
const bool skip
{
false
|| is_stale
|| !viewport_visible
|| (is_own_join && data.reflow_full_state)
};

Expand Down

0 comments on commit eefd59d

Please sign in to comment.