0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-10-02 13:48:53 +02:00

ircd:Ⓜ️ Add linkage for user::presence;

modules/client/presence: reorg for linkage; minor cleanup.
This commit is contained in:
Jason Volk 2018-03-02 07:25:37 -08:00
parent e8fd7eebe0
commit 150543ae91
3 changed files with 111 additions and 57 deletions

View file

@ -39,6 +39,8 @@ struct ircd::m::user
bool is_active() const;
bool is_password(const string_view &password) const noexcept;
event::id::buf presence(const string_view &, const string_view &status = {});
void password(const string_view &password);
void activate(const json::members &contents = {});
void deactivate(const json::members &contents = {});

View file

@ -266,6 +266,25 @@ ircd::m::leave_ircd_room()
leave(my_room, me.user_id);
}
///////////////////////////////////////////////////////////////////////////////
//
// m/user.h
//
ircd::m::event::id::buf
ircd::m::user::presence(const string_view &presence,
const string_view &status_msg)
{
using prototype = event::id::buf (const id &, const string_view &, const string_view &);
static import<prototype> function
{
"client_presence", "set__user_presence_status"
};
return function(user_id, presence, status_msg);
}
///////////////////////////////////////////////////////////////////////////////
//
// m/room.h

View file

@ -26,6 +26,10 @@ presence_resource
}
};
//
// put
//
const string_view
valid_states[]
{
@ -33,64 +37,31 @@ valid_states[]
};
static bool
valid_state(const string_view &state)
{
return std::any_of(begin(valid_states), end(valid_states), [&state]
(const string_view &valid)
{
return state == valid;
});
}
valid_state(const string_view &state);
extern "C" m::event::id::buf
set__user_presence_status(const m::user::id &user_id,
const string_view &presence,
const string_view &status_msg);
static resource::response
put__presence_status(client &client,
const resource::request &request,
const m::user::id &user_id)
{
const string_view &presence
{
unquote(request.at("presence"))
};
const m::user::id &user_id);
if(!valid_state(presence))
throw m::UNSUPPORTED
{
"That presence state is not supported"
};
static resource::response
put__presence(client &client,
const resource::request &request);
const string_view &status_msg
resource::method
method_put
{
trunc(unquote(request["status_msg"]), 390)
};
json::iov content;
const json::iov::push _presence[]
presence_resource, "PUT", put__presence,
{
{ content, { "presence", presence } },
{ content, { "user_id", user_id } },
};
const json::iov::set_if _status_msg
{
content, !empty(status_msg),
{
"status_msg", status_msg
method_put.REQUIRES_AUTH
}
};
const m::user::room user_room
{
user_id
};
send(user_room, user_id, "m.presence", content);
return resource::response
{
client, http::OK
};
}
resource::response
put__presence(client &client,
const resource::request &request)
@ -134,15 +105,77 @@ put__presence(client &client,
};
}
resource::method
method_put
resource::response
put__presence_status(client &client,
const resource::request &request,
const m::user::id &user_id)
{
presence_resource, "PUT", put__presence,
const string_view &presence
{
method_put.REQUIRES_AUTH
unquote(request.at("presence"))
};
const string_view &status_msg
{
trunc(unquote(request["status_msg"]), 390)
};
set__user_presence_status(request.user_id, presence, status_msg);
return resource::response
{
client, http::OK
};
}
m::event::id::buf
set__user_presence_status(const m::user::id &user_id,
const string_view &presence,
const string_view &status_msg)
{
if(!valid_state(presence))
throw m::UNSUPPORTED
{
"That presence state is not supported"
};
json::iov content;
const json::iov::push _presence[]
{
{ content, { "presence", presence } },
{ content, { "user_id", user_id } },
};
const json::iov::set_if _status_msg
{
content, !empty(status_msg),
{
"status_msg", status_msg
}
};
const m::user::room user_room
{
user_id
};
return send(user_room, user_id, "m.presence", content);
}
bool
valid_state(const string_view &state)
{
return std::any_of(begin(valid_states), end(valid_states), [&state]
(const string_view &valid)
{
return state == valid;
});
}
//
// get
//
static resource::response
get__presence_status(client &client,
const resource::request &request,