0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

modules/client/rooms/send: Fix public echo of server-side command input.

This commit is contained in:
Jason Volk 2021-01-25 00:57:13 -08:00
parent ec0dd70da1
commit e4969901a1
2 changed files with 39 additions and 16 deletions

View file

@ -21,7 +21,7 @@ static void
save_transaction_id(const m::event &, save_transaction_id(const m::event &,
m::vm::eval &); m::vm::eval &);
static m::resource::response static m::event::id::buf
handle_command(client &, handle_command(client &,
const m::resource::request &, const m::resource::request &,
const room &); const room &);
@ -141,6 +141,7 @@ put__send(client &client,
room_id, &copts room_id, &copts
}; };
bool command_echo {false};
if(type == "m.room.message") if(type == "m.room.message")
{ {
const m::room::message message const m::room::message message
@ -148,14 +149,34 @@ put__send(client &client,
content content
}; };
const bool cmd const bool command
{ {
json::get<"msgtype"_>(message) == "m.text" && json::get<"msgtype"_>(message) == "m.text"
startswith(json::get<"body"_>(message), "\\\\") && startswith(json::get<"body"_>(message), "\\\\")
}; };
if(cmd) const bool echo
return handle_command(client, request, room); {
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 const auto event_id
@ -163,6 +184,15 @@ put__send(client &client,
m::send(room, request.user_id, type, content) 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 return m::resource::response
{ {
client, json::members client, json::members
@ -172,7 +202,7 @@ put__send(client &client,
}; };
} }
m::resource::response m::event::id::buf
handle_command(client &client, handle_command(client &client,
const m::resource::request &request, const m::resource::request &request,
const room &room) const room &room)
@ -192,14 +222,7 @@ handle_command(client &client,
}) })
}; };
return m::resource::response return event_id;
{
client, json::members
{
{ "event_id", event_id },
{ "cmd", true },
}
};
} }
void void