mirror of
https://github.com/matrix-construct/construct
synced 2024-10-31 19:08:59 +01:00
modules/m_direct_to_device: Tweak logic for local message handling; handle exception per msg.
This commit is contained in:
parent
cdb0ed443d
commit
08c38b2251
1 changed files with 25 additions and 16 deletions
|
@ -42,9 +42,6 @@ handle_edu_m_direct_to_device(const m::event &event,
|
|||
m::vm::eval &eval)
|
||||
try
|
||||
{
|
||||
if(m::my_host(at<"origin"_>(event)))
|
||||
return;
|
||||
|
||||
const json::object &content
|
||||
{
|
||||
at<"content"_>(event)
|
||||
|
@ -74,25 +71,16 @@ try
|
|||
user_messages.first
|
||||
};
|
||||
|
||||
if(!my_host(user_id.host()))
|
||||
continue;
|
||||
|
||||
const json::object &device_messages
|
||||
{
|
||||
user_messages.second
|
||||
};
|
||||
|
||||
for(const auto &device_message : device_messages)
|
||||
{
|
||||
const string_view &device_id
|
||||
{
|
||||
device_message.first
|
||||
};
|
||||
|
||||
const json::object &message_body
|
||||
{
|
||||
device_message.second
|
||||
};
|
||||
|
||||
for(const auto &[device_id, message_body] : device_messages)
|
||||
handle_m_direct_to_device(eval, edu, user_id, device_id, message_body);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
|
@ -111,12 +99,21 @@ handle_m_direct_to_device(m::vm::eval &eval,
|
|||
const m::user::id &user_id,
|
||||
const string_view &device_id,
|
||||
const json::object &message)
|
||||
try
|
||||
{
|
||||
const m::user::room user_room
|
||||
{
|
||||
user_id
|
||||
};
|
||||
|
||||
send(user_room, at<"sender"_>(edu), "ircd.to_device",
|
||||
{
|
||||
{ "sender", at<"sender"_>(edu) },
|
||||
{ "type", at<"type"_>(edu) },
|
||||
{ "device_id", device_id },
|
||||
{ "content", message },
|
||||
});
|
||||
|
||||
log::info
|
||||
{
|
||||
m::log, "%s sent '%s' to %s device '%s' (%zu bytes)",
|
||||
|
@ -127,3 +124,15 @@ handle_m_direct_to_device(m::vm::eval &eval,
|
|||
size(string_view{message})
|
||||
};
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
log::derror
|
||||
{
|
||||
m::log, "m.direct_to_device %s to %s device of %s from %s :%s ",
|
||||
at<"type"_>(edu),
|
||||
device_id,
|
||||
string_view{user_id},
|
||||
at<"sender"_>(edu),
|
||||
e.what()
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue