mirror of
https://github.com/matrix-construct/construct
synced 2024-09-27 11:18:51 +02:00
ircd:Ⓜ️:user::profile: Add interface for remote profile fetch().
This commit is contained in:
parent
9c62b0f61a
commit
094ae6e997
3 changed files with 67 additions and 0 deletions
|
@ -178,6 +178,7 @@ struct ircd::m::user::profile
|
|||
|
||||
m::user user;
|
||||
|
||||
static void fetch(const m::user &, const net::hostport &, const string_view &key = {});
|
||||
static bool for_each(const m::user &, const closure_bool &);
|
||||
static bool get(std::nothrow_t, const m::user &, const string_view &key, const closure &);
|
||||
static event::id::buf set(const m::user &, const string_view &key, const string_view &value);
|
||||
|
|
15
ircd/m.cc
15
ircd/m.cc
|
@ -3155,6 +3155,21 @@ ircd::m::user::profile::for_each(const m::user &u,
|
|||
return function(u, c);
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::user::profile::fetch(const m::user &u,
|
||||
const net::hostport &remote,
|
||||
const string_view &key)
|
||||
{
|
||||
using prototype = void (const m::user &, const net::hostport &, const string_view &);
|
||||
|
||||
static mods::import<prototype> function
|
||||
{
|
||||
"client_profile", "ircd::m::user::profile::fetch"
|
||||
};
|
||||
|
||||
return function(u, remote, key);
|
||||
}
|
||||
|
||||
//
|
||||
// user::account_data
|
||||
//
|
||||
|
|
|
@ -413,6 +413,57 @@ ircd::m::user::profile::for_each(const m::user &user,
|
|||
}});
|
||||
}
|
||||
|
||||
void
|
||||
IRCD_MODULE_EXPORT
|
||||
ircd::m::user::profile::fetch(const m::user &user,
|
||||
const net::hostport &remote,
|
||||
const string_view &key)
|
||||
{
|
||||
const unique_buffer<mutable_buffer> buf
|
||||
{
|
||||
64_KiB
|
||||
};
|
||||
|
||||
m::v1::query::profile federation_request
|
||||
{
|
||||
user.user_id, key, buf, m::v1::query::opts
|
||||
{
|
||||
.remote = remote? remote : user.user_id.host(),
|
||||
.dynamic = true,
|
||||
}
|
||||
};
|
||||
|
||||
federation_request.wait(remote_request_timeout);
|
||||
const http::code &code{federation_request.get()};
|
||||
const json::object &response
|
||||
{
|
||||
federation_request
|
||||
};
|
||||
|
||||
if(!exists(user))
|
||||
create(user);
|
||||
|
||||
const m::user::profile profile{user};
|
||||
const m::user::room &user_room{user};
|
||||
for(const auto &member : response)
|
||||
{
|
||||
bool exists{false};
|
||||
profile.get(std::nothrow, member.first, [&exists, &member]
|
||||
(const string_view &key, const string_view &val)
|
||||
{
|
||||
exists = member.second == val;
|
||||
});
|
||||
|
||||
if(exists)
|
||||
continue;
|
||||
|
||||
send(user_room, user.user_id, "ircd.profile", member.first,
|
||||
{
|
||||
{ "text", member.second }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
handle_my_profile_changed(const m::event &event,
|
||||
m::vm::eval &eval)
|
||||
|
|
Loading…
Reference in a new issue