@@ -6,15 +6,17 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
6
6
Please see LICENSE files in the repository root for full details.
7
7
*/
8
8
9
+ import classNames from "classnames" ;
9
10
import React , { forwardRef , ForwardRefExoticComponent , useContext } from "react" ;
10
11
import { MatrixEvent } from "matrix-js-sdk/src/matrix" ;
11
12
import { DecryptionFailureCode } from "matrix-js-sdk/src/crypto-api" ;
12
13
13
14
import { _t } from "../../../languageHandler" ;
14
15
import { IBodyProps } from "./IBodyProps" ;
15
16
import { LocalDeviceVerificationStateContext } from "../../../contexts/LocalDeviceVerificationStateContext" ;
17
+ import { Icon as WarningBadgeIcon } from "../../../../res/img/compound/error-16px.svg" ;
16
18
17
- function getErrorMessage ( mxEvent : MatrixEvent , isVerified : boolean | undefined ) : string {
19
+ function getErrorMessage ( mxEvent : MatrixEvent , isVerified : boolean | undefined ) : string | React . JSX . Element {
18
20
switch ( mxEvent . decryptionFailureReason ) {
19
21
case DecryptionFailureCode . MEGOLM_KEY_WITHHELD_FOR_UNVERIFIED_DEVICE :
20
22
return _t ( "timeline|decryption_failure|blocked" ) ;
@@ -33,15 +35,39 @@ function getErrorMessage(mxEvent: MatrixEvent, isVerified: boolean | undefined):
33
35
34
36
case DecryptionFailureCode . HISTORICAL_MESSAGE_USER_NOT_JOINED :
35
37
return _t ( "timeline|decryption_failure|historical_event_user_not_joined" ) ;
38
+
39
+ case DecryptionFailureCode . SENDER_IDENTITY_PREVIOUSLY_VERIFIED :
40
+ return (
41
+ < span >
42
+ < WarningBadgeIcon className = "mx_Icon mx_Icon_16" />
43
+ { _t ( "timeline|decryption_failure|sender_identity_previously_verified" ) }
44
+ </ span >
45
+ ) ;
46
+
47
+ case DecryptionFailureCode . UNSIGNED_SENDER_DEVICE :
48
+ // TODO: event should be hidden instead of showing this error (only
49
+ // happens when invisible crypto is enabled)
50
+ return _t ( "encryption|event_shield_reason_unsigned_device" ) ;
36
51
}
37
52
return _t ( "timeline|decryption_failure|unable_to_decrypt" ) ;
38
53
}
39
54
55
+ function getErrorExtraClass ( mxEvent : MatrixEvent ) : Record < string , boolean > {
56
+ switch ( mxEvent . decryptionFailureReason ) {
57
+ case DecryptionFailureCode . SENDER_IDENTITY_PREVIOUSLY_VERIFIED :
58
+ return { mx_DecryptionFailureVerifiedIdentityChanged : true } ;
59
+
60
+ default :
61
+ return { } ;
62
+ }
63
+ }
64
+
40
65
// A placeholder element for messages that could not be decrypted
41
66
export const DecryptionFailureBody = forwardRef < HTMLDivElement , IBodyProps > ( ( { mxEvent } , ref ) : React . JSX . Element => {
42
67
const verificationState = useContext ( LocalDeviceVerificationStateContext ) ;
68
+ const classes = classNames ( "mx_DecryptionFailureBody" , "mx_EventTile_content" , getErrorExtraClass ( mxEvent ) ) ;
43
69
return (
44
- < div className = "mx_DecryptionFailureBody mx_EventTile_content" ref = { ref } >
70
+ < div className = { classes } ref = { ref } >
45
71
{ getErrorMessage ( mxEvent , verificationState ) }
46
72
</ div >
47
73
) ;
0 commit comments