Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 58b8df9

Browse files
authored
Display "The sender has blocked you from receiving this message" error message instead of "Unable to decrypt message" (#10202)
1 parent fbeddba commit 58b8df9

File tree

6 files changed

+98
-8
lines changed

6 files changed

+98
-8
lines changed

src/components/views/messages/DecryptionFailureBody.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import React, { ReactNode } from "react";
17+
import React from "react";
18+
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
1819

1920
import { _t } from "../../../languageHandler";
2021
import { IBodyProps } from "./IBodyProps";
2122

23+
function getErrorMessage(mxEvent?: MatrixEvent): string {
24+
return mxEvent?.isEncryptedDisabledForUnverifiedDevices
25+
? _t("The sender has blocked you from receiving this message")
26+
: _t("Unable to decrypt message");
27+
}
28+
2229
// A placeholder element for messages that could not be decrypted
23-
export default class DecryptionFailureBody extends React.Component<Partial<IBodyProps>> {
24-
public render(): ReactNode {
25-
return <div className="mx_DecryptionFailureBody mx_EventTile_content">{_t("Unable to decrypt message")}</div>;
26-
}
30+
export function DecryptionFailureBody({ mxEvent }: Partial<IBodyProps>): JSX.Element {
31+
return <div className="mx_DecryptionFailureBody mx_EventTile_content">{getErrorMessage(mxEvent)}</div>;
2732
}

src/components/views/messages/MessageEvent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import { MPollEndBody } from "./MPollEndBody";
4141
import MLocationBody from "./MLocationBody";
4242
import MjolnirBody from "./MjolnirBody";
4343
import MBeaconBody from "./MBeaconBody";
44-
import DecryptionFailureBody from "./DecryptionFailureBody";
44+
import { DecryptionFailureBody } from "./DecryptionFailureBody";
4545
import { GetRelationsForEvent, IEventTileOps } from "../rooms/EventTile";
4646
import { VoiceBroadcastBody, VoiceBroadcastInfoEventType, VoiceBroadcastInfoState } from "../../../voice-broadcast";
4747

src/components/views/rooms/EventTile.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { Layout } from "../../../settings/enums/Layout";
3535
import { formatTime } from "../../../DateUtils";
3636
import { MatrixClientPeg } from "../../../MatrixClientPeg";
3737
import MatrixClientContext from "../../../contexts/MatrixClientContext";
38-
import DecryptionFailureBody from "../messages/DecryptionFailureBody";
38+
import { DecryptionFailureBody } from "../messages/DecryptionFailureBody";
3939
import { E2EState } from "./E2EIcon";
4040
import RoomAvatar from "../avatars/RoomAvatar";
4141
import MessageContextMenu from "../context_menus/MessageContextMenu";
@@ -1270,7 +1270,7 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
12701270
{this.props.mxEvent.isRedacted() ? (
12711271
<RedactedBody mxEvent={this.props.mxEvent} />
12721272
) : this.props.mxEvent.isDecryptionFailure() ? (
1273-
<DecryptionFailureBody />
1273+
<DecryptionFailureBody mxEvent={this.props.mxEvent} />
12741274
) : (
12751275
MessagePreviewStore.instance.generatePreviewForEvent(this.props.mxEvent)
12761276
)}

src/i18n/strings/en_EN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,7 @@
23302330
"Last month": "Last month",
23312331
"The beginning of the room": "The beginning of the room",
23322332
"Jump to date": "Jump to date",
2333+
"The sender has blocked you from receiving this message": "The sender has blocked you from receiving this message",
23332334
"%(displayName)s (%(matrixId)s)": "%(displayName)s (%(matrixId)s)",
23342335
"Downloading": "Downloading",
23352336
"Decrypting": "Decrypting",
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2023 The Matrix.org Foundation C.I.C.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import React from "react";
18+
import { render } from "@testing-library/react";
19+
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
20+
21+
import { mkEvent } from "../../../test-utils";
22+
import { DecryptionFailureBody } from "../../../../src/components/views/messages/DecryptionFailureBody";
23+
24+
describe("DecryptionFailureBody", () => {
25+
function customRender(event: MatrixEvent) {
26+
return render(<DecryptionFailureBody mxEvent={event} />);
27+
}
28+
29+
it(`Should display "Unable to decrypt message"`, () => {
30+
// When
31+
const event = mkEvent({
32+
type: "m.room.message",
33+
room: "myfakeroom",
34+
user: "myfakeuser",
35+
content: {
36+
msgtype: "m.bad.encrypted",
37+
},
38+
event: true,
39+
});
40+
const { container } = customRender(event);
41+
42+
// Then
43+
expect(container).toMatchSnapshot();
44+
});
45+
46+
it(`Should display "The sender has blocked you from receiving this message"`, () => {
47+
// When
48+
const event = mkEvent({
49+
type: "m.room.message",
50+
room: "myfakeroom",
51+
user: "myfakeuser",
52+
content: {
53+
msgtype: "m.bad.encrypted",
54+
},
55+
event: true,
56+
});
57+
jest.spyOn(event, "isEncryptedDisabledForUnverifiedDevices", "get").mockReturnValue(true);
58+
const { container } = customRender(event);
59+
60+
// Then
61+
expect(container).toMatchSnapshot();
62+
});
63+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`DecryptionFailureBody Should display "The sender has blocked you from receiving this message" 1`] = `
4+
<div>
5+
<div
6+
class="mx_DecryptionFailureBody mx_EventTile_content"
7+
>
8+
The sender has blocked you from receiving this message
9+
</div>
10+
</div>
11+
`;
12+
13+
exports[`DecryptionFailureBody Should display "Unable to decrypt message" 1`] = `
14+
<div>
15+
<div
16+
class="mx_DecryptionFailureBody mx_EventTile_content"
17+
>
18+
Unable to decrypt message
19+
</div>
20+
</div>
21+
`;

0 commit comments

Comments
 (0)