diff --git a/modules/client/rooms/send.cc b/modules/client/rooms/send.cc index e39710c1f..e3656b7ea 100644 --- a/modules/client/rooms/send.cc +++ b/modules/client/rooms/send.cc @@ -21,7 +21,7 @@ static void save_transaction_id(const m::event &, m::vm::eval &); -static m::resource::response +static m::event::id::buf handle_command(client &, const m::resource::request &, const room &); @@ -141,6 +141,7 @@ put__send(client &client, room_id, &copts }; + bool command_echo {false}; if(type == "m.room.message") { const m::room::message message @@ -148,14 +149,34 @@ put__send(client &client, content }; - const bool cmd + const bool command { - json::get<"msgtype"_>(message) == "m.text" && - startswith(json::get<"body"_>(message), "\\\\") + json::get<"msgtype"_>(message) == "m.text" + && startswith(json::get<"body"_>(message), "\\\\") }; - if(cmd) - return handle_command(client, request, room); + const bool echo + { + startswith(lstrip(json::get<"body"_>(message), "\\\\"), '!') + }; + + if(command && !echo) + { + const auto event_id + { + handle_command(client, request, room) + }; + + return m::resource::response + { + client, json::members + { + { "event_id", event_id }, + { "cmd", true }, + } + }; + } + else command_echo = command && echo; } const auto event_id @@ -163,6 +184,15 @@ put__send(client &client, m::send(room, request.user_id, type, content) }; + // For public echo, run the command after sending the command to the room. + if(command_echo) + { + const auto cmd_event_id + { + handle_command(client, request, room) + }; + } + return m::resource::response { client, json::members @@ -172,7 +202,7 @@ put__send(client &client, }; } -m::resource::response +m::event::id::buf handle_command(client &client, const m::resource::request &request, const room &room) @@ -192,14 +222,7 @@ handle_command(client &client, }) }; - return m::resource::response - { - client, json::members - { - { "event_id", event_id }, - { "cmd", true }, - } - }; + return event_id; } void diff --git a/modules/m_command.cc b/modules/m_command.cc index bfa7b8b3d..8a4bf24b6 100644 --- a/modules/m_command.cc +++ b/modules/m_command.cc @@ -166,7 +166,7 @@ try { "formatted_body", html? html_val: undef_val }, { "room_id", room_id }, { "input", input }, - }); + }); } catch(const std::exception &e) {