sendMessageByInboxId method

  1. @override
Future<Map<String, dynamic>?> sendMessageByInboxId(
  1. String recipientInboxId,
  2. dynamic message,
  3. String authorityId,
  4. String typeId,
  5. int versionMajor,
)
override

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 {
  await _ensureInitialized();
  final contentBytes = _extractContentBytes(message, authorityId, typeId,
      versionMajor);
  final messageId = await rust_messaging.sendMessageByInboxId(
      inboxId: recipientInboxId, contentBytes: contentBytes);
  // Resolve the live DM topic so the Dart layer can heal a stale cached
  // topic (parity with iOS/Android). Reuses the same find-or-create the
  // send used — idempotent and local after the first call — so no Rust
  // bridge change/codegen is needed. Best-effort: a lookup failure just
  // skips healing rather than failing the send.
  String? liveTopic;
  try {
    final dm = await rust_conversations.findOrCreateDmWithInboxId(
        inboxId: recipientInboxId);
    liveTopic = dm.topic;
  } catch (_) {
    liveTopic = null;
  }
  return {'messageId': messageId, 'topic': liveTopic};
}