sendToDevice method

  1. @override
Future<void> sendToDevice(
  1. String eventType,
  2. String txnId,
  3. Map<String, Map<String, Map<String, dynamic>>> messages
)

Sends a raw to_device event with a eventType, a txnId and a content messages. Before sending, it tries to re-send potentially queued to_device events and adds the current one to the queue, should it fail.

Implementation

@override
Future<void> sendToDevice(
  String eventType,
  String txnId,
  Map<String, Map<String, Map<String, dynamic>>> messages,
) async {
  try {
    await processToDeviceQueue();
    await super.sendToDevice(eventType, txnId, messages);
  } catch (e, s) {
    Logs().w(
        '[Client] Problem while sending to_device event, retrying later...',
        e,
        s);
    final database = this.database;
    if (database != null) {
      _toDeviceQueueNeedsProcessing = true;
      await database.insertIntoToDeviceQueue(
          eventType, txnId, json.encode(messages));
    }
    rethrow;
  }
}