0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

modules/client/sync/to_device: Add linear handler.

modules/client/sync/to_device: Reduce event append between handlers.
This commit is contained in:
Jason Volk 2020-03-30 22:04:55 -07:00
parent 44218e9d86
commit 5d685e6b40

View file

@ -10,6 +10,7 @@
namespace ircd::m::sync
{
static void _to_device_append(data &, const json::object &, json::stack::array &);
static bool to_device_polylog(data &);
static bool to_device_linear(data &);
@ -33,7 +34,37 @@ ircd::m::sync::to_device
bool
ircd::m::sync::to_device_linear(data &data)
{
return false;
if(!data.event_idx)
return false;
assert(data.event);
const m::event &event{*data.event};
if(json::get<"room_id"_>(event) != data.user_room.room_id)
return false;
if(json::get<"type"_>(event) != "ircd.to_device")
return false;
const json::object &content
{
json::get<"content"_>(event)
};
const json::string &device_id
{
content.at("device_id")
};
if(device_id != data.device_id)
return false;
json::stack::array array
{
*data.out, "events"
};
_to_device_append(data, content, array);
return true;
}
bool
@ -67,47 +98,7 @@ ircd::m::sync::to_device_polylog(data &data)
if(device_id != data.device_id)
return;
const json::string &sender
{
content.at("sender")
};
const json::string &type
{
content.at("type")
};
json::stack::object event
{
array
};
json::stack::member
{
event, "sender", sender
};
json::stack::member
{
event, "type", type
};
json::stack::object content_
{
event, "content"
};
json::stack::member
{
content_, "device_id", device_id
};
for(const auto &[property, value] : json::object(content.at("content")))
json::stack::member
{
content_, property, value
};
_to_device_append(data, content, array);
ret = true;
});
@ -116,3 +107,49 @@ ircd::m::sync::to_device_polylog(data &data)
return ret;
}
void
ircd::m::sync::_to_device_append(data &data,
const json::object &content,
json::stack::array &array)
{
json::stack::object event
{
array
};
json::stack::member
{
event, "sender", json::string
{
content.at("sender")
}
};
json::stack::member
{
event, "type", json::string
{
content.at("type")
}
};
json::stack::object _content
{
event, "content"
};
json::stack::member
{
_content, "device_id", json::string
{
content.at("device_id")
}
};
for(const auto &[key, val] : json::object(content.at("content")))
json::stack::member
{
_content, key, val
};
}