From d960a31143f3b06b7a3663e4c3079aaa3bd32c6b Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 18 Feb 2019 16:48:52 -0800 Subject: [PATCH] modules/client/register: Set device data on registration w/ login. --- include/ircd/m/register.h | 3 ++- modules/client/register.cc | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/include/ircd/m/register.h b/include/ircd/m/register.h index 984d55230..10c868b90 100644 --- a/include/ircd/m/register.h +++ b/include/ircd/m/register.h @@ -24,7 +24,8 @@ struct ircd::m::registar json::property, json::property, json::property, - json::property + json::property, + json::property > { using super_type::tuple; diff --git a/modules/client/register.cc b/modules/client/register.cc index a06b8068f..67258d948 100644 --- a/modules/client/register.cc +++ b/modules/client/register.cc @@ -251,6 +251,11 @@ register_user(const m::registar &request, m::id::device::buf{} }; + const auto &initial_device_display_name + { + json::get<"initial_device_display_name"_>(request) + }; + // 3.3.1 If true, the server binds the email used for authentication to the // Matrix ID with the ID Server. Defaults to false. const auto &bind_email @@ -303,17 +308,24 @@ register_user(const m::registar &request, string_view{} }; + // Log the user in by issuing an event in the tokens room containing + // the generated token. When this call completes without throwing the + // access_token will be committed and the user will be logged in. if(gen_token) - { - // Log the user in by issuing an event in the tokens room containing - // the generated token. When this call completes without throwing the - // access_token will be committed and the user will be logged in. m::send(m::user::tokens, user_id, "ircd.access_token", access_token, { { "ip", client? string(remote(*client)) : std::string{} }, { "device", device_id }, }); - } + + if(gen_token && !user_room.has("ircd.device", device_id)) + m::send(user_room, user_id, "ircd.device", device_id, json::members + { + { "device_id", device_id }, + { "display_name", initial_device_display_name }, + { "last_seen_ts", ircd::time() }, + { "last_seen_ip", string(remote(*client)) }, + }); // Send response to user return json::strung