From 58b8df98688129ef0b0e8e2164ac16b3244f628a Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Wed, 22 Feb 2023 11:39:09 +0100 Subject: [PATCH] Display "The sender has blocked you from receiving this message" error message instead of "Unable to decrypt message" (#10202) --- .../views/messages/DecryptionFailureBody.tsx | 17 +++-- .../views/messages/MessageEvent.tsx | 2 +- src/components/views/rooms/EventTile.tsx | 4 +- src/i18n/strings/en_EN.json | 1 + .../messages/DecryptionFailureBody-test.tsx | 63 +++++++++++++++++++ .../DecryptionFailureBody-test.tsx.snap | 21 +++++++ 6 files changed, 99 insertions(+), 9 deletions(-) create mode 100644 test/components/views/messages/DecryptionFailureBody-test.tsx create mode 100644 test/components/views/messages/__snapshots__/DecryptionFailureBody-test.tsx.snap diff --git a/src/components/views/messages/DecryptionFailureBody.tsx b/src/components/views/messages/DecryptionFailureBody.tsx index 4c1d6e08b8..0120b960a8 100644 --- a/src/components/views/messages/DecryptionFailureBody.tsx +++ b/src/components/views/messages/DecryptionFailureBody.tsx @@ -14,14 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -import React, { ReactNode } from "react"; +import React from "react"; +import { MatrixEvent } from "matrix-js-sdk/src/matrix"; import { _t } from "../../../languageHandler"; import { IBodyProps } from "./IBodyProps"; -// A placeholder element for messages that could not be decrypted -export default class DecryptionFailureBody extends React.Component> { - public render(): ReactNode { - return
{_t("Unable to decrypt message")}
; - } +function getErrorMessage(mxEvent?: MatrixEvent): string { + return mxEvent?.isEncryptedDisabledForUnverifiedDevices + ? _t("The sender has blocked you from receiving this message") + : _t("Unable to decrypt message"); +} + +// A placeholder element for messages that could not be decrypted +export function DecryptionFailureBody({ mxEvent }: Partial): JSX.Element { + return
{getErrorMessage(mxEvent)}
; } diff --git a/src/components/views/messages/MessageEvent.tsx b/src/components/views/messages/MessageEvent.tsx index b7a8f60831..a32747cd2e 100644 --- a/src/components/views/messages/MessageEvent.tsx +++ b/src/components/views/messages/MessageEvent.tsx @@ -41,7 +41,7 @@ import { MPollEndBody } from "./MPollEndBody"; import MLocationBody from "./MLocationBody"; import MjolnirBody from "./MjolnirBody"; import MBeaconBody from "./MBeaconBody"; -import DecryptionFailureBody from "./DecryptionFailureBody"; +import { DecryptionFailureBody } from "./DecryptionFailureBody"; import { GetRelationsForEvent, IEventTileOps } from "../rooms/EventTile"; import { VoiceBroadcastBody, VoiceBroadcastInfoEventType, VoiceBroadcastInfoState } from "../../../voice-broadcast"; diff --git a/src/components/views/rooms/EventTile.tsx b/src/components/views/rooms/EventTile.tsx index d1198e60d3..fa32df68a6 100644 --- a/src/components/views/rooms/EventTile.tsx +++ b/src/components/views/rooms/EventTile.tsx @@ -35,7 +35,7 @@ import { Layout } from "../../../settings/enums/Layout"; import { formatTime } from "../../../DateUtils"; import { MatrixClientPeg } from "../../../MatrixClientPeg"; import MatrixClientContext from "../../../contexts/MatrixClientContext"; -import DecryptionFailureBody from "../messages/DecryptionFailureBody"; +import { DecryptionFailureBody } from "../messages/DecryptionFailureBody"; import { E2EState } from "./E2EIcon"; import RoomAvatar from "../avatars/RoomAvatar"; import MessageContextMenu from "../context_menus/MessageContextMenu"; @@ -1270,7 +1270,7 @@ export class UnwrappedEventTile extends React.Component {this.props.mxEvent.isRedacted() ? ( ) : this.props.mxEvent.isDecryptionFailure() ? ( - + ) : ( MessagePreviewStore.instance.generatePreviewForEvent(this.props.mxEvent) )} diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index c2a7b5e1f2..076ccfdfb4 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -2330,6 +2330,7 @@ "Last month": "Last month", "The beginning of the room": "The beginning of the room", "Jump to date": "Jump to date", + "The sender has blocked you from receiving this message": "The sender has blocked you from receiving this message", "%(displayName)s (%(matrixId)s)": "%(displayName)s (%(matrixId)s)", "Downloading": "Downloading", "Decrypting": "Decrypting", diff --git a/test/components/views/messages/DecryptionFailureBody-test.tsx b/test/components/views/messages/DecryptionFailureBody-test.tsx new file mode 100644 index 0000000000..e8d4fce56e --- /dev/null +++ b/test/components/views/messages/DecryptionFailureBody-test.tsx @@ -0,0 +1,63 @@ +/* + * Copyright 2023 The Matrix.org Foundation C.I.C. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from "react"; +import { render } from "@testing-library/react"; +import { MatrixEvent } from "matrix-js-sdk/src/matrix"; + +import { mkEvent } from "../../../test-utils"; +import { DecryptionFailureBody } from "../../../../src/components/views/messages/DecryptionFailureBody"; + +describe("DecryptionFailureBody", () => { + function customRender(event: MatrixEvent) { + return render(); + } + + it(`Should display "Unable to decrypt message"`, () => { + // When + const event = mkEvent({ + type: "m.room.message", + room: "myfakeroom", + user: "myfakeuser", + content: { + msgtype: "m.bad.encrypted", + }, + event: true, + }); + const { container } = customRender(event); + + // Then + expect(container).toMatchSnapshot(); + }); + + it(`Should display "The sender has blocked you from receiving this message"`, () => { + // When + const event = mkEvent({ + type: "m.room.message", + room: "myfakeroom", + user: "myfakeuser", + content: { + msgtype: "m.bad.encrypted", + }, + event: true, + }); + jest.spyOn(event, "isEncryptedDisabledForUnverifiedDevices", "get").mockReturnValue(true); + const { container } = customRender(event); + + // Then + expect(container).toMatchSnapshot(); + }); +}); diff --git a/test/components/views/messages/__snapshots__/DecryptionFailureBody-test.tsx.snap b/test/components/views/messages/__snapshots__/DecryptionFailureBody-test.tsx.snap new file mode 100644 index 0000000000..c0096b6467 --- /dev/null +++ b/test/components/views/messages/__snapshots__/DecryptionFailureBody-test.tsx.snap @@ -0,0 +1,21 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`DecryptionFailureBody Should display "The sender has blocked you from receiving this message" 1`] = ` +
+
+ The sender has blocked you from receiving this message +
+
+`; + +exports[`DecryptionFailureBody Should display "Unable to decrypt message" 1`] = ` +
+
+ Unable to decrypt message +
+
+`;