From a99a7e250117ab7f1e304bd589697a4189dc3805 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 5 Jun 2019 16:57:27 -0700 Subject: [PATCH] modules/client/sync/rooms/timeline: Add exposure depth condition to not sync irrelevant events. --- modules/client/sync/rooms/timeline.cc | 44 ++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/modules/client/sync/rooms/timeline.cc b/modules/client/sync/rooms/timeline.cc index cdad14025..b004e083b 100644 --- a/modules/client/sync/rooms/timeline.cc +++ b/modules/client/sync/rooms/timeline.cc @@ -23,6 +23,8 @@ namespace ircd::m::sync static bool _room_timeline_linear_command(data &); static bool room_timeline_linear(data &); + extern const string_view exposure_depth_description; + extern conf::item exposure_depth; extern conf::item limit_default; extern const event::keys::include default_keys; extern item room_timeline; @@ -58,6 +60,23 @@ ircd::m::sync::limit_default { "default", 10L }, }; +decltype(ircd::m::sync::exposure_depth) +ircd::m::sync::exposure_depth +{ + { "name", "ircd.client.sync.rooms.timeline.exposure.depth" }, + { "default", 20L }, + { "description", exposure_depth_description }, +}; + +decltype(ircd::m::sync::exposure_depth_description) +ircd::m::sync::exposure_depth_description +{R"( + Does not linear-sync timeline events whose distance from the room head + is greater than this value. This prevents past events from appearing at + the bottom of the timeline in clients which do not sort their timeline to + prevent an incoherent conversation when the server obtains past events. +)"}; + bool ircd::m::sync::room_timeline_linear(data &data) { @@ -70,11 +89,6 @@ ircd::m::sync::room_timeline_linear(data &data) if(!data.membership && *data.room != data.user_room) return false; - json::stack::object rooms - { - *data.out, "rooms" - }; - assert(data.event); const bool command { @@ -84,9 +98,29 @@ ircd::m::sync::room_timeline_linear(data &data) json::get<"sender"_>(*data.event) == data.user.user_id) }; + json::stack::object rooms + { + *data.out, "rooms" + }; + if(command) return _room_timeline_linear_command(data); + if(int64_t(exposure_depth) > -1) + { + const bool belated + { + // Don't apply this condition to state events for now + !defined(json::get<"state_key"_>(*data.event)) && + + // Check if the depth is too far in the past relative to the room head + json::get<"depth"_>(*data.event) + int64_t(exposure_depth) < data.room_depth + }; + + if(belated) + return false; + } + json::stack::object membership_ { *data.out, data.membership