@@ -36,6 +36,7 @@ import { TypedEventEmitter } from "./typed-event-emitter";
36
36
import { EventStatus } from "./event-status" ;
37
37
import { DecryptionError } from "../crypto/algorithms" ;
38
38
import { CryptoBackend } from "../common-crypto/CryptoBackend" ;
39
+ import { WITHHELD_MESSAGES } from "../crypto/OlmDevice" ;
39
40
40
41
export { EventStatus } from "./event-status" ;
41
42
@@ -272,6 +273,12 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
272
273
private thread ?: Thread ;
273
274
private threadId ?: string ;
274
275
276
+ /*
277
+ * True if this event is an encrypted event which we failed to decrypt, the receiver's device is unverified and
278
+ * the sender has disabled encrypting to unverified devices.
279
+ */
280
+ private encryptedDisabledForUnverifiedDevices = false ;
281
+
275
282
/* Set an approximate timestamp for the event relative the local clock.
276
283
* This will inherently be approximate because it doesn't take into account
277
284
* the time between the server putting the 'age' field on the event as it sent
@@ -324,12 +331,6 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
324
331
*/
325
332
public verificationRequest ?: VerificationRequest ;
326
333
327
- /*
328
- * True if this event is an encrypted event which we failed to decrypt, the receiver's device is unverified and
329
- * the sender has disabled encrypting to unverified devices.
330
- */
331
- public isEncryptedDisabledForUnverifiedDevices = false ;
332
-
333
334
private readonly reEmitter : TypedReEmitter < MatrixEventEmittedEvents , MatrixEventHandlerMap > ;
334
335
335
336
/**
@@ -710,6 +711,10 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
710
711
return this . clearEvent ?. content ?. msgtype === "m.bad.encrypted" ;
711
712
}
712
713
714
+ public isEncryptedDisabledForUnverifiedDevices ( ) : boolean {
715
+ return this . isDecryptionFailure ( ) && this . encryptedDisabledForUnverifiedDevices ;
716
+ }
717
+
713
718
public shouldAttemptDecryption ( ) : boolean {
714
719
if ( this . isRedacted ( ) ) return false ;
715
720
if ( this . isBeingDecrypted ( ) ) return false ;
@@ -905,8 +910,7 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
905
910
body : "** Unable to decrypt: " + reason + " **" ,
906
911
} ,
907
912
} ,
908
- isEncryptedDisabledForUnverifiedDevices :
909
- reason === "DecryptionError: The sender has disabled encrypting to unverified devices." ,
913
+ encryptedDisabledForUnverifiedDevices : reason === `DecryptionError: ${ WITHHELD_MESSAGES [ "m.unverified" ] } ` ,
910
914
} ;
911
915
}
912
916
@@ -928,8 +932,7 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
928
932
this . claimedEd25519Key = decryptionResult . claimedEd25519Key ?? null ;
929
933
this . forwardingCurve25519KeyChain = decryptionResult . forwardingCurve25519KeyChain || [ ] ;
930
934
this . untrusted = decryptionResult . untrusted || false ;
931
- this . isEncryptedDisabledForUnverifiedDevices =
932
- decryptionResult . isEncryptedDisabledForUnverifiedDevices || false ;
935
+ this . encryptedDisabledForUnverifiedDevices = decryptionResult . encryptedDisabledForUnverifiedDevices || false ;
933
936
this . invalidateExtensibleEvent ( ) ;
934
937
}
935
938
0 commit comments