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:
parent
925d15f7c0
commit
1a0d617803
1 changed files with 126 additions and 15 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue