mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 02:02:38 +01:00
modules/client/keys/changes: Implement c2s r0.6.1 13.11.5.2.4 keys/changes (changed half).
This commit is contained in:
parent
a5ddaf0a41
commit
68fc738a3c
1 changed files with 71 additions and 1 deletions
|
@ -60,8 +60,78 @@ m::resource::response
|
|||
get__keys_changes(client &client,
|
||||
const m::resource::request &request)
|
||||
{
|
||||
return m::resource::response
|
||||
char buf[2][128];
|
||||
const string_view range[2]
|
||||
{
|
||||
url::decode(buf[0], request.query["from"]),
|
||||
url::decode(buf[1], request.query["to"])
|
||||
};
|
||||
|
||||
const auto from
|
||||
{
|
||||
m::sync::sequence(m::sync::make_since(range[0]))
|
||||
};
|
||||
|
||||
const auto to
|
||||
{
|
||||
m::sync::sequence(m::sync::make_since(range[1]))
|
||||
};
|
||||
|
||||
const m::user::mitsein mitsein
|
||||
{
|
||||
request.user_id
|
||||
};
|
||||
|
||||
m::resource::response::chunked::json response
|
||||
{
|
||||
client, http::OK
|
||||
};
|
||||
|
||||
if(likely(request.query.get("changed", true)))
|
||||
{
|
||||
json::stack::array out
|
||||
{
|
||||
response, "changed"
|
||||
};
|
||||
|
||||
m::events::type::for_each_in("ircd.device.keys", [&from, &to, &out, &mitsein]
|
||||
(const string_view &type, const m::event::idx &event_idx)
|
||||
{
|
||||
if(event_idx < from || event_idx >= to)
|
||||
return true;
|
||||
|
||||
const bool room_id_prefetched
|
||||
{
|
||||
m::prefetch(event_idx, "room_id")
|
||||
};
|
||||
|
||||
m::get(std::nothrow, event_idx, "sender", [&out, &mitsein, &event_idx]
|
||||
(const m::user::id &user_id)
|
||||
{
|
||||
m::get(std::nothrow, event_idx, "room_id", [&out, &mitsein, &user_id]
|
||||
(const m::room::id &room_id)
|
||||
{
|
||||
if(!m::user::room::is(room_id, user_id))
|
||||
return;
|
||||
|
||||
if(!mitsein.has(user_id))
|
||||
return;
|
||||
|
||||
out.append(user_id);
|
||||
});
|
||||
});
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
if(likely(request.query.get("left", true)))
|
||||
{
|
||||
json::stack::array out
|
||||
{
|
||||
response, "left"
|
||||
};
|
||||
}
|
||||
|
||||
return std::move(response);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue