Skip to content

Commit 5039b2d

Browse files
committed
modules/m_command: Support typing notifications while command is processing.
1 parent 6dd7ed4 commit 5039b2d

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

modules/m_command.cc

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,20 @@ struct command_result
4040
string_view msgtype {"m.notice"};
4141
};
4242

43+
conf::item<bool>
44+
command_typing
45+
{
46+
{ "name", "ircd.m.command.typing" },
47+
{ "default", false },
48+
};
49+
4350
static command_result
4451
execute_command(const mutable_buffer &buf,
4552
const m::user &user,
4653
const m::room &room,
4754
const string_view &cmd,
48-
const m::event::id &reply_to);
55+
const m::event::id &reply_to,
56+
const bool public_response);
4957

5058
void
5159
handle_command(const m::event &event,
@@ -153,7 +161,7 @@ try
153161

154162
const auto &[html, alt, msgtype]
155163
{
156-
execute_command(buf, user, room_id, cmd, reply_id)
164+
execute_command(buf, user, room_id, cmd, reply_id, public_response)
157165
};
158166

159167
if(!html && !alt)
@@ -307,9 +315,30 @@ execute_command(const mutable_buffer &buf,
307315
const m::user &user,
308316
const m::room &room,
309317
const string_view &cmd,
310-
const m::event::id &reply_id)
318+
const m::event::id &reply_id,
319+
const bool public_response)
311320
try
312321
{
322+
m::typing::edu typing
323+
{
324+
{ "room_id", room.room_id },
325+
{ "typing", true },
326+
{ "user_id", user.user_id },
327+
{ "timeout", (30000ms).count() },
328+
};
329+
330+
if(public_response && command_typing)
331+
m::typing::commit{typing};
332+
333+
const unwind done_typing{[&]
334+
{
335+
if(public_response && command_typing)
336+
{
337+
json::get<"typing"_>(typing) = false;
338+
m::typing::commit{typing};
339+
}
340+
}};
341+
313342
if(startswith(cmd, '#'))
314343
return command__control(buf, user, room, lstrip(cmd, '#'));
315344

0 commit comments

Comments
 (0)