mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 15:33:54 +01:00
modules/client/rooms/send: Fix public echo of server-side command input.
This commit is contained in:
parent
ec0dd70da1
commit
e4969901a1
2 changed files with 39 additions and 16 deletions
|
@ -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
|
||||||
|
|
|
@ -166,7 +166,7 @@ try
|
||||||
{ "formatted_body", html? html_val: undef_val },
|
{ "formatted_body", html? html_val: undef_val },
|
||||||
{ "room_id", room_id },
|
{ "room_id", room_id },
|
||||||
{ "input", input },
|
{ "input", input },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch(const std::exception &e)
|
catch(const std::exception &e)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue