2018-02-12 23:45:48 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
using namespace ircd;
|
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
static void _rejoin_room(const m::room &room, const m::user &user);
|
|
|
|
static void _rejoin_rooms(const m::user::id &user_id);
|
|
|
|
static void handle_my_profile_changed__displayname(const m::event &event);
|
|
|
|
static void handle_my_profile_changed__avatar_url(const m::event &event);
|
|
|
|
static void handle_my_profile_changed(const m::event &, m::vm::eval &);
|
2019-03-06 06:15:16 +01:00
|
|
|
static void rethrow(const std::exception_ptr &, const m::user &, const string_view &);
|
|
|
|
static std::exception_ptr fetch_profile_remote(const m::user &, const string_view &);
|
2019-02-21 19:45:37 +01:00
|
|
|
static resource::response get__profile(client &, const resource::request &);
|
|
|
|
static resource::response put__profile(client &, const resource::request &);
|
|
|
|
|
2018-02-14 23:04:26 +01:00
|
|
|
mapi::header
|
|
|
|
IRCD_MODULE
|
2018-02-12 23:45:48 +01:00
|
|
|
{
|
2018-02-15 22:06:49 +01:00
|
|
|
"Client 8.2 :Profiles"
|
2018-02-12 23:45:48 +01:00
|
|
|
};
|
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
const size_t
|
|
|
|
PARAM_MAX_SIZE
|
|
|
|
{
|
|
|
|
128
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::hookfn<m::vm::eval &>
|
|
|
|
my_profile_changed
|
|
|
|
{
|
|
|
|
handle_my_profile_changed,
|
|
|
|
{
|
|
|
|
{ "_site", "vm.effect" },
|
|
|
|
{ "type", "ircd.profile" },
|
2019-03-06 06:15:16 +01:00
|
|
|
{ "origin", my_host() },
|
2019-02-21 19:45:37 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-02-14 23:04:26 +01:00
|
|
|
ircd::resource
|
|
|
|
profile_resource
|
2018-02-12 23:45:48 +01:00
|
|
|
{
|
2018-02-14 23:04:26 +01:00
|
|
|
"/_matrix/client/r0/profile/",
|
2018-02-12 23:45:48 +01:00
|
|
|
{
|
2018-02-14 23:04:26 +01:00
|
|
|
"(8.2) Profiles",
|
2018-02-12 23:45:48 +01:00
|
|
|
resource::DIRECTORY,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
resource::method
|
|
|
|
method_get
|
|
|
|
{
|
|
|
|
profile_resource, "GET", get__profile
|
|
|
|
};
|
|
|
|
|
|
|
|
resource::method
|
|
|
|
method_put
|
|
|
|
{
|
|
|
|
profile_resource, "PUT", put__profile,
|
|
|
|
{
|
|
|
|
method_put.REQUIRES_AUTH
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
resource::response
|
|
|
|
put__profile(client &client,
|
|
|
|
const resource::request &request)
|
|
|
|
{
|
|
|
|
if(request.parv.size() < 1)
|
|
|
|
throw m::NEED_MORE_PARAMS
|
|
|
|
{
|
|
|
|
"user_id path parameter required"
|
|
|
|
};
|
|
|
|
|
|
|
|
if(request.parv.size() < 2)
|
|
|
|
throw m::NEED_MORE_PARAMS
|
|
|
|
{
|
|
|
|
"profile property path parameter required"
|
|
|
|
};
|
|
|
|
|
|
|
|
m::user::id::buf user_id
|
|
|
|
{
|
|
|
|
url::decode(user_id, request.parv[0])
|
|
|
|
};
|
|
|
|
|
|
|
|
if(user_id != request.user_id)
|
|
|
|
throw m::FORBIDDEN
|
|
|
|
{
|
|
|
|
"Trying to set profile for '%s' but you are '%s'",
|
|
|
|
user_id,
|
|
|
|
request.user_id
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::user user
|
|
|
|
{
|
|
|
|
user_id
|
|
|
|
};
|
|
|
|
|
|
|
|
char parambuf[PARAM_MAX_SIZE];
|
|
|
|
const string_view ¶m
|
|
|
|
{
|
|
|
|
url::decode(parambuf, request.parv[1])
|
|
|
|
};
|
|
|
|
|
|
|
|
const string_view &value
|
|
|
|
{
|
2019-03-07 03:17:46 +01:00
|
|
|
request.at(param)
|
2019-02-21 19:45:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const m::user::profile profile
|
|
|
|
{
|
|
|
|
user
|
|
|
|
};
|
|
|
|
|
|
|
|
bool modified{true};
|
|
|
|
profile.get(std::nothrow, param, [&value, &modified]
|
|
|
|
(const string_view ¶m, const string_view &existing)
|
|
|
|
{
|
|
|
|
modified = existing != value;
|
|
|
|
});
|
2018-03-23 00:25:45 +01:00
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
if(!modified)
|
|
|
|
return resource::response
|
|
|
|
{
|
|
|
|
client, http::OK
|
|
|
|
};
|
2018-03-23 00:25:45 +01:00
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
const auto eid
|
|
|
|
{
|
|
|
|
profile.set(param, value)
|
|
|
|
};
|
2018-02-14 23:04:26 +01:00
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
return resource::response
|
|
|
|
{
|
|
|
|
client, http::OK
|
|
|
|
};
|
|
|
|
}
|
2018-02-14 23:04:26 +01:00
|
|
|
|
2018-02-12 23:45:48 +01:00
|
|
|
resource::response
|
2018-02-14 23:04:26 +01:00
|
|
|
get__profile(client &client,
|
2018-02-12 23:45:48 +01:00
|
|
|
const resource::request &request)
|
|
|
|
{
|
2018-02-14 23:04:26 +01:00
|
|
|
if(request.parv.size() < 1)
|
2018-02-15 06:52:19 +01:00
|
|
|
throw m::NEED_MORE_PARAMS
|
2018-02-14 23:04:26 +01:00
|
|
|
{
|
|
|
|
"user_id path parameter required"
|
|
|
|
};
|
|
|
|
|
|
|
|
m::user::id::buf user_id
|
|
|
|
{
|
2018-12-07 01:41:47 +01:00
|
|
|
url::decode(user_id, request.parv[0])
|
2018-02-14 23:04:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const m::user user
|
|
|
|
{
|
|
|
|
user_id
|
|
|
|
};
|
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
char parambuf[PARAM_MAX_SIZE];
|
2018-02-14 23:04:26 +01:00
|
|
|
const string_view ¶m
|
|
|
|
{
|
2019-03-06 06:15:16 +01:00
|
|
|
request.parv.size() > 1?
|
|
|
|
url::decode(parambuf, request.parv[1]):
|
|
|
|
string_view{}
|
2018-02-14 23:04:26 +01:00
|
|
|
};
|
|
|
|
|
2019-03-06 06:15:16 +01:00
|
|
|
// For remote users, we try to get the latest profile data
|
|
|
|
// from the remote server and cache it locally. When there's
|
|
|
|
// a problem, we store that problem in this eptr for later.
|
|
|
|
const std::exception_ptr eptr
|
|
|
|
{
|
|
|
|
!my(user)?
|
|
|
|
fetch_profile_remote(user, param):
|
|
|
|
std::exception_ptr{}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Now we treat the profile as local data in any case
|
2019-02-21 19:45:37 +01:00
|
|
|
const m::user::profile profile
|
|
|
|
{
|
|
|
|
user
|
|
|
|
};
|
|
|
|
|
2019-03-06 06:15:16 +01:00
|
|
|
if(param) try
|
2018-02-14 23:04:26 +01:00
|
|
|
{
|
2019-03-06 06:15:16 +01:00
|
|
|
// throws if param not found
|
|
|
|
profile.get(param, [&client]
|
|
|
|
(const string_view ¶m, const string_view &value)
|
2018-02-14 23:04:26 +01:00
|
|
|
{
|
2019-03-06 06:15:16 +01:00
|
|
|
resource::response
|
2018-02-14 23:04:26 +01:00
|
|
|
{
|
2019-03-06 06:15:16 +01:00
|
|
|
client, json::members
|
|
|
|
{
|
|
|
|
{ param, value }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2018-02-14 23:04:26 +01:00
|
|
|
|
2019-03-06 06:15:16 +01:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
2019-03-04 00:54:05 +01:00
|
|
|
{
|
2019-03-06 06:15:16 +01:00
|
|
|
// If there was a problem querying locally for this param and the
|
|
|
|
// user is remote, eptr will have a better error for the client.
|
|
|
|
if(!my(user))
|
|
|
|
rethrow(eptr, user, param);
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
2019-03-04 00:54:05 +01:00
|
|
|
|
|
|
|
// Have to return a 404 if the profile is empty rather than a {},
|
|
|
|
// so we iterate for at least one element first to check that.
|
|
|
|
bool empty{true};
|
|
|
|
profile.for_each([&empty]
|
|
|
|
(const string_view &, const string_view &)
|
|
|
|
{
|
|
|
|
empty = false;
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2019-03-06 06:15:16 +01:00
|
|
|
// If we have no profile data and the user is not ours, eptr might have
|
|
|
|
// a better error for our client.
|
|
|
|
if(empty && !my(user))
|
|
|
|
rethrow(eptr, user, param);
|
|
|
|
|
|
|
|
// Otherwise if there's no profile data we 404 our client.
|
2019-03-04 00:54:05 +01:00
|
|
|
if(empty)
|
|
|
|
throw m::NOT_FOUND
|
|
|
|
{
|
|
|
|
"Profile for %s is empty.",
|
|
|
|
string_view{user.user_id}
|
|
|
|
};
|
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
resource::response::chunked response
|
2018-02-25 09:29:44 +01:00
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
client, http::OK
|
|
|
|
};
|
2018-02-25 09:29:44 +01:00
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
json::stack out
|
|
|
|
{
|
|
|
|
response.buf, response.flusher()
|
|
|
|
};
|
2018-02-25 09:29:44 +01:00
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
json::stack::object top
|
|
|
|
{
|
|
|
|
out
|
|
|
|
};
|
2018-02-25 09:29:44 +01:00
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
profile.for_each([&top]
|
|
|
|
(const string_view ¶m, const string_view &value)
|
2018-02-25 09:29:44 +01:00
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
json::stack::member
|
2018-02-25 09:29:44 +01:00
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
top, param, value
|
|
|
|
};
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
return {};
|
2018-02-25 09:29:44 +01:00
|
|
|
}
|
|
|
|
|
2019-03-01 23:00:26 +01:00
|
|
|
conf::item<seconds>
|
|
|
|
remote_request_timeout
|
|
|
|
{
|
|
|
|
{ "name", "ircd.client.profile.remote_request.timeout" },
|
|
|
|
{ "default", 10L }
|
|
|
|
};
|
|
|
|
|
2019-03-06 06:15:16 +01:00
|
|
|
std::exception_ptr
|
|
|
|
fetch_profile_remote(const m::user &user,
|
|
|
|
const string_view &key)
|
2019-03-01 22:49:19 +01:00
|
|
|
try
|
2018-02-25 09:29:44 +01:00
|
|
|
{
|
2019-03-06 06:15:16 +01:00
|
|
|
m::user::profile::fetch(user, user.user_id.host(), key);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return std::current_exception();
|
|
|
|
}
|
2018-02-25 09:29:44 +01:00
|
|
|
|
2019-03-06 06:15:16 +01:00
|
|
|
void
|
|
|
|
rethrow(const std::exception_ptr &eptr,
|
|
|
|
const m::user &user,
|
|
|
|
const string_view &key)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
std::rethrow_exception(eptr);
|
2018-02-25 09:29:44 +01:00
|
|
|
}
|
2019-03-01 22:49:19 +01:00
|
|
|
catch(const http::error &)
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
2019-03-06 06:15:16 +01:00
|
|
|
catch(const ctx::timeout &)
|
|
|
|
{
|
|
|
|
throw m::error
|
|
|
|
{
|
|
|
|
http::GATEWAY_TIMEOUT, "M_PROFILE_TIMEOUT",
|
|
|
|
"Server '%s' did not respond with profile for %s in time.",
|
|
|
|
user.user_id.host(),
|
|
|
|
string_view{user.user_id}
|
|
|
|
};
|
|
|
|
}
|
2019-03-01 22:49:19 +01:00
|
|
|
catch(const server::unavailable &e)
|
|
|
|
{
|
|
|
|
throw m::error
|
|
|
|
{
|
|
|
|
http::SERVICE_UNAVAILABLE, "M_PROFILE_UNAVAILABLE",
|
|
|
|
"Server '%s' cannot be contacted for profile of %s :%s",
|
|
|
|
user.user_id.host(),
|
|
|
|
string_view{user.user_id},
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
catch(const server::error &e)
|
|
|
|
{
|
|
|
|
throw m::error
|
|
|
|
{
|
|
|
|
http::BAD_GATEWAY, "M_PROFILE_UNAVAILABLE",
|
|
|
|
"Error when contacting '%s' for profile of %s :%s",
|
|
|
|
user.user_id.host(),
|
|
|
|
string_view{user.user_id},
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
2018-02-25 09:29:44 +01:00
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
m::event::id::buf
|
|
|
|
IRCD_MODULE_EXPORT
|
|
|
|
ircd::m::user::profile::set(const m::user &user,
|
|
|
|
const string_view &key,
|
|
|
|
const string_view &val)
|
2018-02-14 23:04:26 +01:00
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
const m::user::room user_room
|
2018-02-14 23:04:26 +01:00
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
user
|
2018-02-14 23:04:26 +01:00
|
|
|
};
|
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
return m::send(user_room, user, "ircd.profile", key,
|
2018-02-14 23:04:26 +01:00
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
{ "text", val }
|
|
|
|
});
|
|
|
|
}
|
2018-02-14 23:04:26 +01:00
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
bool
|
|
|
|
IRCD_MODULE_EXPORT
|
|
|
|
ircd::m::user::profile::get(std::nothrow_t,
|
|
|
|
const m::user &user,
|
|
|
|
const string_view &key,
|
|
|
|
const closure &closure)
|
|
|
|
{
|
|
|
|
const user::room user_room{user};
|
|
|
|
const room::state state{user_room};
|
|
|
|
const event::idx event_idx
|
2018-02-14 23:04:26 +01:00
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
state.get(std::nothrow, "ircd.profile", key)
|
2018-02-14 23:04:26 +01:00
|
|
|
};
|
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
return event_idx && m::get(std::nothrow, event_idx, "content", [&closure, &key]
|
|
|
|
(const json::object &content)
|
2018-04-22 02:28:48 +02:00
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
const string_view &value
|
2018-04-26 12:35:38 +02:00
|
|
|
{
|
2019-03-07 03:17:46 +01:00
|
|
|
content.get("text")
|
2018-04-26 12:35:38 +02:00
|
|
|
};
|
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
closure(key, value);
|
|
|
|
});
|
2018-02-12 23:45:48 +01:00
|
|
|
}
|
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
bool
|
|
|
|
IRCD_MODULE_EXPORT
|
|
|
|
ircd::m::user::profile::for_each(const m::user &user,
|
|
|
|
const closure_bool &closure)
|
2018-02-12 23:45:48 +01:00
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
static const event::fetch::opts fopts
|
2018-02-12 23:45:48 +01:00
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
event::keys::include {"content", "state_key"}
|
|
|
|
};
|
2018-03-23 00:25:45 +01:00
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
const user::room user_room{user};
|
|
|
|
const room::state state
|
2018-03-23 00:25:45 +01:00
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
user_room, &fopts
|
2018-03-23 00:25:45 +01:00
|
|
|
};
|
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
return state.for_each("ircd.profile", event::closure_bool{[&closure]
|
|
|
|
(const event &event)
|
2018-03-23 00:25:45 +01:00
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
const string_view &key
|
|
|
|
{
|
|
|
|
at<"state_key"_>(event)
|
|
|
|
};
|
|
|
|
|
2018-03-23 00:25:45 +01:00
|
|
|
const string_view &value
|
|
|
|
{
|
2019-03-07 03:17:46 +01:00
|
|
|
json::get<"content"_>(event).get("text")
|
2018-03-23 00:25:45 +01:00
|
|
|
};
|
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
return closure(key, value);
|
|
|
|
}});
|
2018-04-03 07:12:25 +02:00
|
|
|
}
|
2018-03-23 00:25:45 +01:00
|
|
|
|
2019-03-06 05:50:32 +01:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2019-03-06 19:50:42 +01:00
|
|
|
m::v1::query::opts opts;
|
|
|
|
opts.remote = remote?: user.user_id.host();
|
|
|
|
opts.dynamic = true;
|
2019-03-06 05:50:32 +01:00
|
|
|
m::v1::query::profile federation_request
|
|
|
|
{
|
2019-03-06 19:50:42 +01:00
|
|
|
user.user_id, key, buf, std::move(opts)
|
2019-03-06 05:50:32 +01:00
|
|
|
};
|
|
|
|
|
2019-03-06 06:15:16 +01:00
|
|
|
federation_request.wait(seconds(remote_request_timeout));
|
2019-03-06 05:50:32 +01:00
|
|
|
const http::code &code{federation_request.get()};
|
|
|
|
const json::object &response
|
|
|
|
{
|
|
|
|
federation_request
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!exists(user))
|
|
|
|
create(user);
|
|
|
|
|
|
|
|
const m::user::profile profile{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;
|
|
|
|
});
|
|
|
|
|
2019-03-07 21:13:44 +01:00
|
|
|
if(!exists)
|
|
|
|
profile.set(user, member.first, member.second);
|
2019-03-06 05:50:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
void
|
|
|
|
handle_my_profile_changed(const m::event &event,
|
|
|
|
m::vm::eval &eval)
|
2018-03-23 00:25:45 +01:00
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
const m::user::id &user_id
|
2018-03-23 00:25:45 +01:00
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
json::get<"sender"_>(event)
|
2018-03-23 00:25:45 +01:00
|
|
|
};
|
|
|
|
|
2019-03-06 06:15:16 +01:00
|
|
|
if(!my(event) || !my(user_id))
|
|
|
|
return;
|
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
// The event has to be an ircd.profile in the user's room, not just a
|
|
|
|
// random ircd.profile typed event in some other room...
|
|
|
|
const m::user::room user_room{user_id};
|
|
|
|
if(json::get<"room_id"_>(event) != user_room.room_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(json::get<"state_key"_>(event) == "displayname")
|
|
|
|
return handle_my_profile_changed__displayname(event);
|
|
|
|
|
|
|
|
if(json::get<"state_key"_>(event) == "avatar_url")
|
|
|
|
return handle_my_profile_changed__avatar_url(event);
|
2018-03-23 00:25:45 +01:00
|
|
|
}
|
2018-04-22 00:21:50 +02:00
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
void
|
|
|
|
handle_my_profile_changed__avatar_url(const m::event &event)
|
2018-04-22 00:21:50 +02:00
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
_rejoin_rooms(at<"sender"_>(event));
|
2018-04-22 00:21:50 +02:00
|
|
|
}
|
2019-02-21 19:45:37 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
handle_my_profile_changed__displayname(const m::event &event)
|
2018-04-22 00:21:50 +02:00
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
_rejoin_rooms(at<"sender"_>(event));
|
2018-04-22 00:21:50 +02:00
|
|
|
}
|
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
void
|
2018-04-22 00:21:50 +02:00
|
|
|
_rejoin_rooms(const m::user::id &user_id)
|
|
|
|
{
|
|
|
|
assert(my(user_id));
|
|
|
|
const m::user::rooms &rooms
|
|
|
|
{
|
|
|
|
user_id
|
|
|
|
};
|
|
|
|
|
|
|
|
rooms.for_each("join", [&user_id]
|
|
|
|
(const m::room &room, const string_view &)
|
|
|
|
{
|
|
|
|
_rejoin_room(room, user_id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
void
|
|
|
|
_rejoin_room(const m::room &room,
|
|
|
|
const m::user &user)
|
|
|
|
try
|
2018-04-22 00:21:50 +02:00
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
m::join(room, user);
|
2018-04-22 00:21:50 +02:00
|
|
|
}
|
2019-02-21 19:45:37 +01:00
|
|
|
catch(const std::exception &e)
|
2018-04-22 00:21:50 +02:00
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
log::error
|
2018-04-22 00:21:50 +02:00
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
"Failed to rejoin '%s' to room '%s' to update profile",
|
|
|
|
string_view{user.user_id},
|
|
|
|
string_view{room.room_id}
|
2018-04-22 00:21:50 +02:00
|
|
|
};
|
|
|
|
}
|