From cdb0ed443d48c14f9e359078b4c849d8b769969d Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 22 Feb 2019 14:45:07 -0800 Subject: [PATCH] modules/client/sync/to_device: Implement to_device event polylog sync. --- modules/client/sync/to_device.cc | 62 ++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/modules/client/sync/to_device.cc b/modules/client/sync/to_device.cc index f175a6fb3..315e2c0ce 100644 --- a/modules/client/sync/to_device.cc +++ b/modules/client/sync/to_device.cc @@ -49,8 +49,66 @@ ircd::m::sync::to_device_polylog(data &data) data.out, "events" }; - const m::room::state &state + const m::room &user_room { - data.user_state + data.user_room }; + + m::room::messages it + { + user_room + }; + + for(; it; ++it) + { + const auto &event_idx(it.event_idx()); + if(!apropos(data, event_idx)) + break; + + bool relevant(false); + m::get(std::nothrow, event_idx, "type", [&relevant] + (const string_view &type) + { + relevant = type == "ircd.to_device"; + }); + + if(!relevant) + continue; + + m::get(std::nothrow, event_idx, "content", [&data, &array] + (const json::object &content) + { + data.commit(); + json::stack::object event + { + array + }; + + json::stack::member + { + event, "sender", unquote(content.at("sender")) + }; + + json::stack::member + { + event, "type", unquote(content.at("type")) + }; + + json::stack::object content_ + { + event, "content" + }; + + json::stack::member + { + content_, "device_id", unquote(content.at("device_id")) + }; + + for(const auto &[property, value] : json::object(content.at("content"))) + json::stack::member + { + content_, property, value + }; + }); + } }