requestKey method

Future<void> requestKey()

If this event is encrypted and the decryption was not successful because the session is unknown, this requests the session key from other devices in the room. If the event is not encrypted or the decryption failed because of a different error, this throws an exception.

Implementation

Future<void> requestKey() async {
  if (type != EventTypes.Encrypted ||
      messageType != MessageTypes.BadEncrypted ||
      content['can_request_session'] != true) {
    throw ('Session key not requestable');
  }

  final sessionId = content.tryGet<String>('session_id');
  final senderKey = content.tryGet<String>('sender_key');
  if (sessionId == null || senderKey == null) {
    throw ('Unknown session_id or sender_key');
  }
  await room.requestSessionKey(sessionId, senderKey);
  return;
}