send method

Future<void> send(
  1. String type,
  2. Map<String, dynamic> payload
)

Implementation

Future<void> send(
  String type,
  Map<String, dynamic> payload,
) async {
  makePayload(payload);
  Logs().i('[Key Verification] Sending type $type: $payload');
  if (room != null) {
    Logs().i('[Key Verification] Sending to $userId in room ${room!.id}...');
    if ({EventTypes.KeyVerificationRequest}.contains(type)) {
      payload['msgtype'] = type;
      payload['to'] = userId;
      payload['body'] =
          'Attempting verification request. ($type) Apparently your client doesn\'t support this';
      type = EventTypes.Message;
    }
    final newTransactionId = await room!.sendEvent(payload, type: type);
    if (transactionId == null) {
      transactionId = newTransactionId;
      encryption.keyVerificationManager.addRequest(this);
    }
  } else {
    Logs().i('[Key Verification] Sending to $userId device $deviceId...');
    if (deviceId == '*') {
      if ({
        EventTypes.KeyVerificationRequest,
        EventTypes.KeyVerificationCancel,
      }.contains(type)) {
        final deviceKeys =
            client.userDeviceKeys[userId]?.deviceKeys.values.where(
          (deviceKey) => deviceKey.hasValidSignatureChain(
            verifiedByTheirMasterKey: true,
          ),
        );

        if (deviceKeys != null) {
          await client.sendToDeviceEncrypted(
            deviceKeys.toList(),
            type,
            payload,
          );
        }
      } else {
        Logs().e(
          '[Key Verification] Tried to broadcast and un-broadcastable type: $type',
        );
      }
    } else {
      if (client.userDeviceKeys[userId]?.deviceKeys[deviceId] != null) {
        await client.sendToDeviceEncrypted(
          [client.userDeviceKeys[userId]!.deviceKeys[deviceId]!],
          type,
          payload,
        );
      } else {
        Logs().e('[Key Verification] Unknown device');
      }
    }
  }
}