mirror of
https://github.com/matrix-construct/construct
synced 2024-11-01 03:18:54 +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)
|
m::vm::eval &eval)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(m::my_host(at<"origin"_>(event)))
|
|
||||||
return;
|
|
||||||
|
|
||||||
const json::object &content
|
const json::object &content
|
||||||
{
|
{
|
||||||
at<"content"_>(event)
|
at<"content"_>(event)
|
||||||
|
@ -74,27 +71,18 @@ try
|
||||||
user_messages.first
|
user_messages.first
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if(!my_host(user_id.host()))
|
||||||
|
continue;
|
||||||
|
|
||||||
const json::object &device_messages
|
const json::object &device_messages
|
||||||
{
|
{
|
||||||
user_messages.second
|
user_messages.second
|
||||||
};
|
};
|
||||||
|
|
||||||
for(const auto &device_message : device_messages)
|
for(const auto &[device_id, message_body] : device_messages)
|
||||||
{
|
|
||||||
const string_view &device_id
|
|
||||||
{
|
|
||||||
device_message.first
|
|
||||||
};
|
|
||||||
|
|
||||||
const json::object &message_body
|
|
||||||
{
|
|
||||||
device_message.second
|
|
||||||
};
|
|
||||||
|
|
||||||
handle_m_direct_to_device(eval, edu, user_id, device_id, message_body);
|
handle_m_direct_to_device(eval, edu, user_id, device_id, message_body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch(const std::exception &e)
|
catch(const std::exception &e)
|
||||||
{
|
{
|
||||||
log::derror
|
log::derror
|
||||||
|
@ -111,12 +99,21 @@ handle_m_direct_to_device(m::vm::eval &eval,
|
||||||
const m::user::id &user_id,
|
const m::user::id &user_id,
|
||||||
const string_view &device_id,
|
const string_view &device_id,
|
||||||
const json::object &message)
|
const json::object &message)
|
||||||
|
try
|
||||||
{
|
{
|
||||||
const m::user::room user_room
|
const m::user::room user_room
|
||||||
{
|
{
|
||||||
user_id
|
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
|
log::info
|
||||||
{
|
{
|
||||||
m::log, "%s sent '%s' to %s device '%s' (%zu bytes)",
|
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})
|
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