mirror of
https://github.com/matrix-construct/construct
synced 2024-12-28 00:14:07 +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
|
// copyright notice and this permission notice is present in all copies. The
|
||||||
// full license for this software is available in the LICENSE file.
|
// 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
|
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",
|
"(r0.6.0-13.13.1.2) Pushers set",
|
||||||
resource::DIRECTORY,
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
resource::response
|
decltype(ircd::m::push::pushers_set_post)
|
||||||
get__pushers(client &client,
|
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 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
|
return resource::response
|
||||||
{
|
{
|
||||||
client, http::OK
|
client, http::OK
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
resource::method
|
const bool res
|
||||||
method_get
|
|
||||||
{
|
{
|
||||||
pushers_resource, "GET", get__pushers,
|
user_pushers.set(pusher)
|
||||||
|
};
|
||||||
|
|
||||||
|
return resource::response
|
||||||
{
|
{
|
||||||
method_get.REQUIRES_AUTH
|
client, http::OK
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// pushers
|
||||||
|
//
|
||||||
|
|
||||||
|
decltype(ircd::m::push::pushers_resource)
|
||||||
|
ircd::m::push::pushers_resource
|
||||||
|
{
|
||||||
|
"/_matrix/client/r0/pushers",
|
||||||
|
{
|
||||||
|
"(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