Use correct push rule to evaluate room-wide mentions (#12318)
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>pull/28217/head
parent
42ac873c55
commit
e807457276
|
@ -17,11 +17,11 @@ limitations under the License.
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import ReactDOM from "react-dom";
|
import ReactDOM from "react-dom";
|
||||||
import { PushProcessor } from "matrix-js-sdk/src/pushprocessor";
|
import { PushProcessor } from "matrix-js-sdk/src/pushprocessor";
|
||||||
import { MatrixEvent, MatrixClient } from "matrix-js-sdk/src/matrix";
|
import { MatrixClient, MatrixEvent, RuleId } from "matrix-js-sdk/src/matrix";
|
||||||
import { TooltipProvider } from "@vector-im/compound-web";
|
import { TooltipProvider } from "@vector-im/compound-web";
|
||||||
|
|
||||||
import SettingsStore from "../settings/SettingsStore";
|
import SettingsStore from "../settings/SettingsStore";
|
||||||
import { Pill, PillType, pillRoomNotifLen, pillRoomNotifPos } from "../components/views/elements/Pill";
|
import { Pill, pillRoomNotifLen, pillRoomNotifPos, PillType } from "../components/views/elements/Pill";
|
||||||
import { parsePermalink } from "./permalinks/Permalinks";
|
import { parsePermalink } from "./permalinks/Permalinks";
|
||||||
import { PermalinkParts } from "./permalinks/PermalinkConstructor";
|
import { PermalinkParts } from "./permalinks/PermalinkConstructor";
|
||||||
|
|
||||||
|
@ -127,7 +127,9 @@ export function pillifyLinks(
|
||||||
|
|
||||||
if (roomNotifTextNodes.length > 0) {
|
if (roomNotifTextNodes.length > 0) {
|
||||||
const pushProcessor = new PushProcessor(matrixClient);
|
const pushProcessor = new PushProcessor(matrixClient);
|
||||||
const atRoomRule = pushProcessor.getPushRuleById(".m.rule.roomnotif");
|
const atRoomRule = pushProcessor.getPushRuleById(
|
||||||
|
mxEvent.getContent()["m.mentions"] !== undefined ? RuleId.IsRoomMention : RuleId.AtRoomNotification,
|
||||||
|
);
|
||||||
if (atRoomRule && pushProcessor.ruleMatchesEvent(atRoomRule, mxEvent)) {
|
if (atRoomRule && pushProcessor.ruleMatchesEvent(atRoomRule, mxEvent)) {
|
||||||
// Now replace all those nodes with Pills
|
// Now replace all those nodes with Pills
|
||||||
for (const roomNotifTextNode of roomNotifTextNodes) {
|
for (const roomNotifTextNode of roomNotifTextNodes) {
|
||||||
|
|
|
@ -195,7 +195,7 @@ export function createTestClient(): MatrixClient {
|
||||||
isUserIgnored: jest.fn().mockReturnValue(false),
|
isUserIgnored: jest.fn().mockReturnValue(false),
|
||||||
getCapabilities: jest.fn().mockResolvedValue({}),
|
getCapabilities: jest.fn().mockResolvedValue({}),
|
||||||
supportsThreads: jest.fn().mockReturnValue(false),
|
supportsThreads: jest.fn().mockReturnValue(false),
|
||||||
supportsIntentionalMentions: () => false,
|
supportsIntentionalMentions: jest.fn().mockReturnValue(false),
|
||||||
getRoomUpgradeHistory: jest.fn().mockReturnValue([]),
|
getRoomUpgradeHistory: jest.fn().mockReturnValue([]),
|
||||||
getOpenIdToken: jest.fn().mockResolvedValue(undefined),
|
getOpenIdToken: jest.fn().mockResolvedValue(undefined),
|
||||||
registerWithIdentityServer: jest.fn().mockResolvedValue({}),
|
registerWithIdentityServer: jest.fn().mockResolvedValue({}),
|
||||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { render } from "@testing-library/react";
|
import { render } from "@testing-library/react";
|
||||||
import { MatrixEvent, ConditionKind, EventType, PushRuleActionName, Room, TweakName } from "matrix-js-sdk/src/matrix";
|
import { MatrixEvent, ConditionKind, EventType, PushRuleActionName, Room, TweakName } from "matrix-js-sdk/src/matrix";
|
||||||
|
import { mocked } from "jest-mock";
|
||||||
|
|
||||||
import { pillifyLinks } from "../../src/utils/pillify";
|
import { pillifyLinks } from "../../src/utils/pillify";
|
||||||
import { stubClient } from "../test-utils";
|
import { stubClient } from "../test-utils";
|
||||||
|
@ -36,7 +37,9 @@ describe("pillify", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
stubClient();
|
stubClient();
|
||||||
const cli = MatrixClientPeg.safeGet();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
(cli.getRoom as jest.Mock).mockReturnValue(new Room(roomId, cli, cli.getUserId()!));
|
const room = new Room(roomId, cli, cli.getUserId()!);
|
||||||
|
room.currentState.mayTriggerNotifOfType = jest.fn().mockReturnValue(true);
|
||||||
|
(cli.getRoom as jest.Mock).mockReturnValue(room);
|
||||||
cli.pushRules!.global = {
|
cli.pushRules!.global = {
|
||||||
override: [
|
override: [
|
||||||
{
|
{
|
||||||
|
@ -58,6 +61,28 @@ describe("pillify", () => {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
rule_id: ".m.rule.is_room_mention",
|
||||||
|
default: true,
|
||||||
|
enabled: true,
|
||||||
|
conditions: [
|
||||||
|
{
|
||||||
|
kind: ConditionKind.EventPropertyIs,
|
||||||
|
key: "content.m\\.mentions.room",
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
kind: ConditionKind.SenderNotificationPermission,
|
||||||
|
key: "room",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
actions: [
|
||||||
|
PushRuleActionName.Notify,
|
||||||
|
{
|
||||||
|
set_tweak: TweakName.Highlight,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -81,6 +106,29 @@ describe("pillify", () => {
|
||||||
expect(container.querySelector(".mx_Pill.mx_AtRoomPill")?.textContent).toBe("!@room");
|
expect(container.querySelector(".mx_Pill.mx_AtRoomPill")?.textContent).toBe("!@room");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should pillify @room in an intentional mentions world", () => {
|
||||||
|
mocked(MatrixClientPeg.safeGet().supportsIntentionalMentions).mockReturnValue(true);
|
||||||
|
const { container } = render(<div>@room</div>);
|
||||||
|
const containers: Element[] = [];
|
||||||
|
pillifyLinks(
|
||||||
|
MatrixClientPeg.safeGet(),
|
||||||
|
[container],
|
||||||
|
new MatrixEvent({
|
||||||
|
room_id: roomId,
|
||||||
|
type: EventType.RoomMessage,
|
||||||
|
content: {
|
||||||
|
"body": "@room",
|
||||||
|
"m.mentions": {
|
||||||
|
room: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
containers,
|
||||||
|
);
|
||||||
|
expect(containers).toHaveLength(1);
|
||||||
|
expect(container.querySelector(".mx_Pill.mx_AtRoomPill")?.textContent).toBe("!@room");
|
||||||
|
});
|
||||||
|
|
||||||
it("should not double up pillification on repeated calls", () => {
|
it("should not double up pillification on repeated calls", () => {
|
||||||
const { container } = render(<div>@room</div>);
|
const { container } = render(<div>@room</div>);
|
||||||
const containers: Element[] = [];
|
const containers: Element[] = [];
|
||||||
|
|
Loading…
Reference in New Issue