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

modules/client: Implement Client r0.6.0-13.13.1 Pushers.

This commit is contained in:
Jason Volk 2020-03-21 11:33:42 -07:00
parent 925d15f7c0
commit 1a0d617803

View file

@ -8,39 +8,150 @@
// 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;
namespace ircd::m::push
{
static resource::response handle_pushers_set(client &, const resource::request &);
extern resource::method pushers_set_post;
extern resource pushers_set_resource;
mapi::header
static resource::response handle_pushers_get(client &, const resource::request &);
extern resource::method pushers_get;
extern resource pushers_resource;
}
ircd::mapi::header
IRCD_MODULE
{
"Client 11.12 :Pushers"
"Client r0.6.0-13.13.1 :Pushers"
};
ircd::resource
pushers_resource
//
// pushers/set
//
decltype(ircd::m::push::pushers_set_resource)
ircd::m::push::pushers_set_resource
{
"/_matrix/client/r0/pushers/",
"/_matrix/client/r0/pushers/set",
{
"(11.12.1) Pushers",
resource::DIRECTORY,
"(r0.6.0-13.13.1.2) Pushers set",
}
};
resource::response
get__pushers(client &client,
const resource::request &request)
decltype(ircd::m::push::pushers_set_post)
ircd::m::push::pushers_set_post
{
pushers_set_resource, "POST", handle_pushers_set,
{
pushers_set_post.REQUIRES_AUTH
}
};
ircd::m::resource::response
ircd::m::push::handle_pushers_set(client &client,
const resource::request &request)
{
const json::object &pusher
{
request.content
};
const json::string &kind
{
pusher.at("kind")
};
const m::user::pushers user_pushers
{
request.user_id
};
if(kind == "null")
{
const json::string &key
{
pusher.at("pushkey")
};
const bool res
{
user_pushers.del(key)
};
return resource::response
{
client, http::OK
};
}
const bool res
{
user_pushers.set(pusher)
};
return resource::response
{
client, http::OK
};
}
resource::method
method_get
//
// pushers
//
decltype(ircd::m::push::pushers_resource)
ircd::m::push::pushers_resource
{
pushers_resource, "GET", get__pushers,
"/_matrix/client/r0/pushers",
{
method_get.REQUIRES_AUTH
"(r0.6.0-13.13.1.1) Pushers",
}
};
decltype(ircd::m::push::pushers_get)
ircd::m::push::pushers_get
{
pushers_resource, "GET", handle_pushers_get,
{
pushers_get.REQUIRES_AUTH
}
};
ircd::m::resource::response
ircd::m::push::handle_pushers_get(client &client,
const resource::request &request)
{
const m::user::pushers user_pushers
{
request.user_id
};
resource::response::chunked response
{
client, http::OK
};
json::stack out
{
response.buf, response.flusher()
};
json::stack::object top
{
out
};
json::stack::array pushers
{
top, "pushers"
};
user_pushers.for_each([&pushers]
(const string_view &pushkey, const json::object &pusher)
{
pushers.append(pusher);
return true;
});
return std::move(response);
}