Remove reply fallback from notifications (#11278)
* Remove reply fallback from notifications * Add test
This commit is contained in:
parent
8f000384fe
commit
9fcd1f2434
2 changed files with 35 additions and 3 deletions
|
@ -52,6 +52,7 @@ import ToastStore from "./stores/ToastStore";
|
||||||
import { ElementCall } from "./models/Call";
|
import { ElementCall } from "./models/Call";
|
||||||
import { VoiceBroadcastChunkEventType, VoiceBroadcastInfoEventType } from "./voice-broadcast";
|
import { VoiceBroadcastChunkEventType, VoiceBroadcastInfoEventType } from "./voice-broadcast";
|
||||||
import { getSenderName } from "./utils/event/getSenderName";
|
import { getSenderName } from "./utils/event/getSenderName";
|
||||||
|
import { stripPlainReply } from "./utils/Reply";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Dispatches:
|
* Dispatches:
|
||||||
|
@ -138,7 +139,7 @@ class NotifierClass {
|
||||||
// notificationMessageForEvent includes sender, but we already have the sender here
|
// notificationMessageForEvent includes sender, but we already have the sender here
|
||||||
const msgType = ev.getContent().msgtype;
|
const msgType = ev.getContent().msgtype;
|
||||||
if (ev.getContent().body && (!msgType || !msgTypeHandlers.hasOwnProperty(msgType))) {
|
if (ev.getContent().body && (!msgType || !msgTypeHandlers.hasOwnProperty(msgType))) {
|
||||||
msg = ev.getContent().body;
|
msg = stripPlainReply(ev.getContent().body);
|
||||||
}
|
}
|
||||||
} else if (ev.getType() === "m.room.member") {
|
} else if (ev.getType() === "m.room.member") {
|
||||||
// context is all in the message here, we don't need
|
// context is all in the message here, we don't need
|
||||||
|
@ -149,7 +150,7 @@ class NotifierClass {
|
||||||
// notificationMessageForEvent includes sender, but we've just out sender in the title
|
// notificationMessageForEvent includes sender, but we've just out sender in the title
|
||||||
const msgType = ev.getContent().msgtype;
|
const msgType = ev.getContent().msgtype;
|
||||||
if (ev.getContent().body && (!msgType || !msgTypeHandlers.hasOwnProperty(msgType))) {
|
if (ev.getContent().body && (!msgType || !msgTypeHandlers.hasOwnProperty(msgType))) {
|
||||||
msg = ev.getContent().body;
|
msg = stripPlainReply(ev.getContent().body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,13 @@ import {
|
||||||
createLocalNotificationSettingsIfNeeded,
|
createLocalNotificationSettingsIfNeeded,
|
||||||
getLocalNotificationAccountDataEventType,
|
getLocalNotificationAccountDataEventType,
|
||||||
} from "../src/utils/notifications";
|
} from "../src/utils/notifications";
|
||||||
import { getMockClientWithEventEmitter, mkEvent, mockClientMethodsUser, mockPlatformPeg } from "./test-utils";
|
import {
|
||||||
|
getMockClientWithEventEmitter,
|
||||||
|
mkEvent,
|
||||||
|
mkMessage,
|
||||||
|
mockClientMethodsUser,
|
||||||
|
mockPlatformPeg,
|
||||||
|
} from "./test-utils";
|
||||||
import { IncomingCallToast } from "../src/toasts/IncomingCallToast";
|
import { IncomingCallToast } from "../src/toasts/IncomingCallToast";
|
||||||
import { SdkContextClass } from "../src/contexts/SDKContext";
|
import { SdkContextClass } from "../src/contexts/SDKContext";
|
||||||
import UserActivity from "../src/UserActivity";
|
import UserActivity from "../src/UserActivity";
|
||||||
|
@ -42,6 +48,7 @@ import { ThreadPayload } from "../src/dispatcher/payloads/ThreadPayload";
|
||||||
import { Action } from "../src/dispatcher/actions";
|
import { Action } from "../src/dispatcher/actions";
|
||||||
import { VoiceBroadcastChunkEventType, VoiceBroadcastInfoState } from "../src/voice-broadcast";
|
import { VoiceBroadcastChunkEventType, VoiceBroadcastInfoState } from "../src/voice-broadcast";
|
||||||
import { mkVoiceBroadcastInfoStateEvent } from "./voice-broadcast/utils/test-utils";
|
import { mkVoiceBroadcastInfoStateEvent } from "./voice-broadcast/utils/test-utils";
|
||||||
|
import { addReplyToMessageContent } from "../src/utils/Reply";
|
||||||
|
|
||||||
jest.mock("../src/utils/notifications", () => ({
|
jest.mock("../src/utils/notifications", () => ({
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@ -307,6 +314,30 @@ describe("Notifier", () => {
|
||||||
Notifier.displayPopupNotification(audioEvent, testRoom);
|
Notifier.displayPopupNotification(audioEvent, testRoom);
|
||||||
expect(MockPlatform.displayNotification).not.toHaveBeenCalled();
|
expect(MockPlatform.displayNotification).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should strip reply fallback", () => {
|
||||||
|
const event = mkMessage({
|
||||||
|
msg: "Test",
|
||||||
|
event: true,
|
||||||
|
user: mockClient.getSafeUserId(),
|
||||||
|
room: testRoom.roomId,
|
||||||
|
});
|
||||||
|
const reply = mkMessage({
|
||||||
|
msg: "This was a triumph",
|
||||||
|
event: true,
|
||||||
|
user: mockClient.getSafeUserId(),
|
||||||
|
room: testRoom.roomId,
|
||||||
|
});
|
||||||
|
addReplyToMessageContent(reply.getContent(), event, { includeLegacyFallback: true });
|
||||||
|
Notifier.displayPopupNotification(reply, testRoom);
|
||||||
|
expect(MockPlatform.displayNotification).toHaveBeenCalledWith(
|
||||||
|
"@bob:example.org (!room1:server)",
|
||||||
|
"This was a triumph",
|
||||||
|
expect.any(String),
|
||||||
|
testRoom,
|
||||||
|
reply,
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("getSoundForRoom", () => {
|
describe("getSoundForRoom", () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue