request method

Future<void> request(
  1. String type, [
  2. List<DeviceKeys>? devices
])

Implementation

Future<void> request(String type, [List<DeviceKeys>? devices]) async {
  // only send to own, verified devices
  Logs().i('[SSSS] Requesting type $type...');
  if (devices == null || devices.isEmpty) {
    if (!client.userDeviceKeys.containsKey(client.userID)) {
      Logs().w('[SSSS] User does not have any devices');
      return;
    }
    devices =
        client.userDeviceKeys[client.userID]!.deviceKeys.values.toList();
  }
  devices.removeWhere((DeviceKeys d) =>
      d.userId != client.userID ||
      !d.verified ||
      d.blocked ||
      d.deviceId == client.deviceID);
  if (devices.isEmpty) {
    Logs().w('[SSSS] No devices');
    return;
  }
  final requestId = client.generateUniqueTransactionId();
  final request = _ShareRequest(
    requestId: requestId,
    type: type,
    devices: devices,
  );
  pendingShareRequests[requestId] = request;
  await client.sendToDeviceEncrypted(devices, EventTypes.SecretRequest, {
    'action': 'request',
    'requesting_device_id': client.deviceID,
    'request_id': requestId,
    'name': type,
  });
}