add internal gomuks command support

This commit is contained in:
Henry Hiles 2026-11-03 14:11:39 -05:00
commit 8650c44266
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs

View file

@ -13,6 +13,7 @@ import "package:nexus/controllers/client_state.dart";
import "package:nexus/controllers/settings.dart";
import "package:nexus/helpers/extensions/gomuks_buffer.dart";
import "package:nexus/main.dart";
import "package:nexus/models/content/bot_command_description.dart";
import "package:nexus/models/account.dart";
import "package:nexus/models/capabilities.dart";
import "package:nexus/models/content/message.dart";
@ -240,8 +241,23 @@ class ClientController(final String? accountId) extends AsyncNotifier<int> {
Future<void> redactEvent(RedactEventRequest report) =>
_sendCommand("redact_event", report.toJson());
Future<Event> sendMessage(SendMessageRequest request) async =>
Event.fromJson(await _sendCommand("send_message", request.toJson()));
/// Null for gomuks' own commands that don't reply.
Future<Event?> sendMessage(SendMessageRequest request) async =>
switch (await _sendCommand("send_message", request.toJson())) {
final Map<String, dynamic> json => .fromJson(json),
_ => null,
};
/// The MSC4391 definitions of gomuks' own commands.
Future<IList<BotCommandDescriptionContent>> getCommandDefinitions() async =>
switch (await _sendCommand("get_command_definitions")) {
final List definitions => .new(
definitions.whereType<Map<String, dynamic>>().map(
BotCommandDescriptionContent.fromJson,
),
),
_ => const .empty(),
};
Future<Event> sendEvent(SendEventRequest request) async =>
Event.fromJson(await _sendCommand("send_event", request.toJson()));