feat: Replace isSuccessful with canSend
This commit is contained in:
@@ -8,6 +8,7 @@ class EncryptionResult {
|
||||
this.ciphertext,
|
||||
this.encryptedKeys,
|
||||
this.deviceEncryptionErrors,
|
||||
this.canSend,
|
||||
);
|
||||
|
||||
/// The actual message that was encrypted.
|
||||
@@ -20,9 +21,7 @@ class EncryptionResult {
|
||||
/// Mapping of a JID to
|
||||
final Map<String, List<EncryptToJidError>> deviceEncryptionErrors;
|
||||
|
||||
// TODO: Turn this into a property that is computed in [onOutgoingStanza].
|
||||
/// True if the encryption was a success. This means that we could encrypt for
|
||||
/// at least one ratchet per recipient. [recipients] is the number of recipients
|
||||
/// that the message should've been encrypted for.
|
||||
bool isSuccess(int recipients) => encryptedKeys.length == recipients;
|
||||
/// A flag indicating that the message could be sent like that, i.e. we were able
|
||||
/// to encrypt to at-least one device per recipient.
|
||||
final bool canSend;
|
||||
}
|
||||
|
||||
@@ -630,6 +630,9 @@ class OmemoManager {
|
||||
ciphertext = null;
|
||||
}
|
||||
|
||||
final successfulEncryptions = Map<String, int>.fromEntries(
|
||||
stanza.recipientJids.map((jid) => MapEntry(jid, 0)),
|
||||
);
|
||||
final encryptionErrors = <String, List<EncryptToJidError>>{};
|
||||
final addedRatchetKeys = List<RatchetMapKey>.empty(growable: true);
|
||||
final kex = <RatchetMapKey, OMEMOKeyExchange>{};
|
||||
@@ -770,6 +773,7 @@ class OmemoManager {
|
||||
true,
|
||||
),
|
||||
);
|
||||
successfulEncryptions[jid] = successfulEncryptions[jid]! + 1;
|
||||
} else if (!ratchet.acknowledged) {
|
||||
// The ratchet as not yet been acked.
|
||||
// Keep sending the old KEX
|
||||
@@ -789,6 +793,7 @@ class OmemoManager {
|
||||
true,
|
||||
),
|
||||
);
|
||||
successfulEncryptions[jid] = successfulEncryptions[jid]! + 1;
|
||||
} else {
|
||||
// The ratchet exists and is acked
|
||||
encryptedKeys.appendOrCreate(
|
||||
@@ -799,6 +804,7 @@ class OmemoManager {
|
||||
false,
|
||||
),
|
||||
);
|
||||
successfulEncryptions[jid] = successfulEncryptions[jid]! + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -807,6 +813,7 @@ class OmemoManager {
|
||||
ciphertext,
|
||||
encryptedKeys,
|
||||
encryptionErrors,
|
||||
successfulEncryptions.values.every((n) => n > 0),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user