sendMessageByInboxId method
Returns a map with messageId and the live DM topic (the conversation
that was actually sent to — send is find-or-create, so this is always the
canonical DM topic). topic may be null on platforms that don't surface it.
Implementation
@override
Future<Map<String, dynamic>?> sendMessageByInboxId(
String recipientInboxId,
dynamic message,
String authorityId,
String typeId,
int versionMajor,
) async {
try {
final params = <String, dynamic>{
'recipientInboxId': recipientInboxId,
'message': message,
'authorityId': authorityId,
'typeId': typeId,
'versionMajor': versionMajor,
}.jsify() as JSObject;
final result = await _promiseToFuture(
_clientManager.sendMessageByInboxId(params),
);
final messageId = (result as JSString?)?.toDart;
// Resolve the live DM topic so the Dart layer can heal a stale cached
// topic (parity with iOS/Android/Windows). Reuses the same
// find-or-create the send used. Best-effort: a miss just skips healing.
String? liveTopic;
try {
final dm = await findOrCreateDMWithInboxId(recipientInboxId);
liveTopic = dm['topic'] as String?;
} catch (_) {
liveTopic = null;
}
return {'messageId': messageId, 'topic': liveTopic};
} catch (e) {
throw Exception('Failed to send message by inbox ID: $e');
}
}