mirror of
https://github.com/matrix-construct/construct
synced 2025-01-14 00:34:18 +01:00
ircd:Ⓜ️ More complete presence interface getter interface stack.
This commit is contained in:
parent
75fdf2f518
commit
82ef048d3f
3 changed files with 43 additions and 14 deletions
|
@ -36,7 +36,11 @@ struct ircd::m::edu::m_presence
|
|||
struct ircd::m::presence
|
||||
:edu::m_presence
|
||||
{
|
||||
using closure = std::function<void (const json::object &)>;
|
||||
|
||||
static bool valid_state(const string_view &state);
|
||||
static void get(const user &, const closure &);
|
||||
static bool get(std::nothrow_t, const user &, const closure &);
|
||||
static json::object get(const user &, const mutable_buffer &);
|
||||
static event::id::buf set(const presence &);
|
||||
static event::id::buf set(const user &, const string_view &, const string_view &status = {});
|
||||
|
|
30
ircd/m/m.cc
30
ircd/m/m.cc
|
@ -767,14 +767,40 @@ ircd::json::object
|
|||
ircd::m::presence::get(const user &user,
|
||||
const mutable_buffer &buffer)
|
||||
{
|
||||
using prototype = json::object (const m::user &, const mutable_buffer &);
|
||||
json::object ret;
|
||||
get(std::nothrow, user, [&ret, &buffer]
|
||||
(const json::object &object)
|
||||
{
|
||||
ret = { data(buffer), copy(buffer, object) };
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::presence::get(const user &user,
|
||||
const closure &closure)
|
||||
{
|
||||
if(!get(std::nothrow, user, closure))
|
||||
throw m::NOT_FOUND
|
||||
{
|
||||
"No presence found for %s", user.user_id
|
||||
};
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::presence::get(std::nothrow_t,
|
||||
const user &user,
|
||||
const closure &lambda)
|
||||
{
|
||||
using prototype = bool (std::nothrow_t, const m::user &, const closure &);
|
||||
|
||||
static import<prototype> function
|
||||
{
|
||||
"client_presence", "m_presence_get"
|
||||
};
|
||||
|
||||
return function(user, buffer);
|
||||
return function(std::nothrow, user, lambda);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -148,9 +148,10 @@ commit__m_presence(const m::presence &content)
|
|||
// get
|
||||
//
|
||||
|
||||
extern "C" json::object
|
||||
m_presence_get(const m::user &user,
|
||||
const mutable_buffer &buffer);
|
||||
extern "C" bool
|
||||
m_presence_get(const std::nothrow_t,
|
||||
const m::user &,
|
||||
const m::presence::closure &);
|
||||
|
||||
static resource::response
|
||||
get__presence_status(client &client,
|
||||
|
@ -290,28 +291,26 @@ method_get
|
|||
presence_resource, "GET", get__presence
|
||||
};
|
||||
|
||||
json::object
|
||||
m_presence_get(const m::user &user,
|
||||
const mutable_buffer &buffer)
|
||||
bool
|
||||
m_presence_get(const std::nothrow_t,
|
||||
const m::user &user,
|
||||
const m::presence::closure &closure)
|
||||
{
|
||||
const m::user::room user_room
|
||||
{
|
||||
user
|
||||
};
|
||||
|
||||
json::object ret;
|
||||
user_room.get(std::nothrow, "m.presence", [&ret, &buffer]
|
||||
return user_room.get(std::nothrow, "m.presence", [&closure]
|
||||
(const m::event &event)
|
||||
{
|
||||
const string_view &content
|
||||
const auto &content
|
||||
{
|
||||
at<"content"_>(event)
|
||||
};
|
||||
|
||||
ret = { data(buffer), copy(buffer, content) };
|
||||
closure(content);
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue