2019-02-21 03:34:22 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2019 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
using namespace ircd;
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
static m::resource::response
|
2019-03-11 18:41:28 +01:00
|
|
|
get__keys_changes(client &client,
|
2019-09-29 01:12:07 +02:00
|
|
|
const m::resource::request &request);
|
2019-03-11 18:41:28 +01:00
|
|
|
|
2019-02-21 03:34:22 +01:00
|
|
|
mapi::header
|
|
|
|
IRCD_MODULE
|
|
|
|
{
|
|
|
|
"Client 14.11.5.2 :Key management API"
|
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
ircd::m::resource
|
2019-02-21 03:34:22 +01:00
|
|
|
changes_resource
|
|
|
|
{
|
|
|
|
"/_matrix/client/r0/keys/changes",
|
|
|
|
{
|
|
|
|
"(14.11.5.2.4) Keys changes",
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::method
|
2019-03-11 18:41:28 +01:00
|
|
|
method_get
|
2019-02-21 03:34:22 +01:00
|
|
|
{
|
2019-03-11 18:41:28 +01:00
|
|
|
changes_resource, "GET", get__keys_changes,
|
2019-02-21 03:34:22 +01:00
|
|
|
{
|
2019-03-11 18:41:28 +01:00
|
|
|
method_get.REQUIRES_AUTH
|
|
|
|
}
|
|
|
|
};
|
2019-02-21 03:34:22 +01:00
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::response
|
2019-03-11 18:41:28 +01:00
|
|
|
get__keys_changes(client &client,
|
2019-09-29 01:12:07 +02:00
|
|
|
const m::resource::request &request)
|
2019-03-11 18:41:28 +01:00
|
|
|
{
|
2021-01-04 12:52:37 +01:00
|
|
|
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
|
2019-03-11 18:41:28 +01:00
|
|
|
{
|
|
|
|
client, http::OK
|
|
|
|
};
|
2021-01-04 12:52:37 +01:00
|
|
|
|
|
|
|
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"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-06-25 22:47:43 +02:00
|
|
|
return response;
|
2019-03-11 18:41:28 +01:00
|
|
|
}
|