make e2ee recovery logic optional

This commit is contained in:
Sorunome 2020-05-20 10:24:48 +02:00
parent 11d788b68f
commit a3fc73dfc1
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C
2 changed files with 10 additions and 3 deletions

View File

@ -77,7 +77,14 @@ class Client {
Database database;
Client(this.clientName, {this.debug = false, this.database}) {
bool enableE2eeRecovery;
/// Create a client
/// clientName = unique identifier of this client
/// debug: Print debug output?
/// database: The database instance to use
/// enableE2eeRecovery: Enable additional logic to try to recover from bad e2ee sessions
Client(this.clientName, {this.debug = false, this.database, this.enableE2eeRecovery = false}) {
onLoginStateChanged.stream.listen((loginState) {
print('LoginState: ${loginState.toString()}');
});

View File

@ -1814,7 +1814,7 @@ class Room {
final session = await client.database.getDbInboundGroupSession(client.id, id, sessionId);
if (session == null) {
// no session found, let's request it!
if (!_requestedSessionIds.contains(sessionId) && senderKey != null) {
if (client.enableE2eeRecovery && !_requestedSessionIds.contains(sessionId) && senderKey != null) {
unawaited(requestSessionKey(sessionId, senderKey));
_requestedSessionIds.add(sessionId);
}
@ -1876,7 +1876,7 @@ class Room {
decryptedPayload = json.decode(decryptResult.plaintext);
} catch (exception) {
// alright, if this was actually by our own outbound group session, we might as well clear it
if ((_outboundGroupSession?.session_id() ?? '') == event.content['session_id']) {
if (client.enableE2eeRecovery && (_outboundGroupSession?.session_id() ?? '') == event.content['session_id']) {
clearOutboundGroupSession(wipe: true);
}
if (exception.toString() == DecryptError.UNKNOWN_SESSION) {