Default intentional mentions (#11602)
* Default intentional mentions * wait for autocomplete to settle before submitting edit * lint * Update strings --------- Co-authored-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
parent
237038aa56
commit
3608d52c4a
9 changed files with 282 additions and 349 deletions
|
@ -90,10 +90,9 @@ export function attachMentions(
|
|||
replyToEvent: MatrixEvent | undefined,
|
||||
editedContent: IContent | null = null,
|
||||
): void {
|
||||
// If this feature is disabled, do nothing.
|
||||
if (!SettingsStore.getValue("feature_intentional_mentions")) {
|
||||
return;
|
||||
}
|
||||
// We always attach the mentions even if the home server doesn't yet support
|
||||
// intentional mentions. This is safe because m.mentions is an additive change
|
||||
// that should simply be ignored by incapable home servers.
|
||||
|
||||
// The mentions property *always* gets included to disable legacy push rules.
|
||||
const mentions: IMentions = (content["m.mentions"] = {});
|
||||
|
|
|
@ -1151,7 +1151,6 @@
|
|||
"voice_broadcast": "Voice broadcast",
|
||||
"rust_crypto": "Rust cryptography implementation",
|
||||
"hidebold": "Hide notification dot (only display counters badges)",
|
||||
"intentional_mentions": "Enable intentional mentions",
|
||||
"ask_to_join": "Enable ask to join",
|
||||
"new_room_decoration_ui": "New room header & details interface",
|
||||
"beta_feature": "This is a beta feature",
|
||||
|
|
|
@ -531,20 +531,6 @@ export const SETTINGS: { [setting: string]: ISetting } = {
|
|||
labsGroup: LabGroup.Rooms,
|
||||
default: false,
|
||||
},
|
||||
// MSC3952 intentional mentions support.
|
||||
"feature_intentional_mentions": {
|
||||
isFeature: true,
|
||||
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
|
||||
displayName: _td("labs|intentional_mentions"),
|
||||
labsGroup: LabGroup.Rooms,
|
||||
default: false,
|
||||
controller: new ServerSupportUnstableFeatureController(
|
||||
"feature_intentional_mentions",
|
||||
defaultWatchManager,
|
||||
[["org.matrix.msc3952_intentional_mentions"]],
|
||||
"v1.7",
|
||||
),
|
||||
},
|
||||
"feature_ask_to_join": {
|
||||
default: false,
|
||||
displayName: _td("labs|ask_to_join"),
|
||||
|
|
|
@ -23,7 +23,6 @@ import ContentMessages, { UploadCanceledError, uploadFile } from "../src/Content
|
|||
import { doMaybeLocalRoomAction } from "../src/utils/local-room";
|
||||
import { createTestClient, mkEvent } from "./test-utils";
|
||||
import { BlurhashEncoder } from "../src/BlurhashEncoder";
|
||||
import SettingsStore from "../src/settings/SettingsStore";
|
||||
|
||||
jest.mock("matrix-encrypt-attachment", () => ({ encryptAttachment: jest.fn().mockResolvedValue({}) }));
|
||||
|
||||
|
@ -278,10 +277,6 @@ describe("ContentMessages", () => {
|
|||
});
|
||||
|
||||
it("properly handles replies", async () => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockImplementation(
|
||||
(settingName) => settingName === "feature_intentional_mentions",
|
||||
);
|
||||
|
||||
mocked(client.uploadContent).mockResolvedValue({ content_uri: "mxc://server/file" });
|
||||
const file = new File([], "fileName", { type: "image/jpeg" });
|
||||
const replyToEvent = mkEvent({
|
||||
|
|
|
@ -112,6 +112,7 @@ describe("ThreadView", () => {
|
|||
"rel_type": RelationType.Thread,
|
||||
},
|
||||
"msgtype": MsgType.Text,
|
||||
"m.mentions": {},
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -137,13 +137,15 @@ describe("<EditMessageComposer/>", () => {
|
|||
...editedEvent.getContent(),
|
||||
"body": " * original message + edit",
|
||||
"m.new_content": {
|
||||
body: "original message + edit",
|
||||
msgtype: "m.text",
|
||||
"body": "original message + edit",
|
||||
"msgtype": "m.text",
|
||||
"m.mentions": {},
|
||||
},
|
||||
"m.relates_to": {
|
||||
event_id: editedEvent.getId(),
|
||||
rel_type: "m.replace",
|
||||
},
|
||||
"m.mentions": {},
|
||||
};
|
||||
expect(mockClient.sendMessage).toHaveBeenCalledWith(editedEvent.getRoomId()!, null, expectedBody);
|
||||
});
|
||||
|
@ -168,13 +170,15 @@ describe("<EditMessageComposer/>", () => {
|
|||
"body": " * hello world",
|
||||
"msgtype": "m.text",
|
||||
"m.new_content": {
|
||||
body: "hello world",
|
||||
msgtype: "m.text",
|
||||
"body": "hello world",
|
||||
"msgtype": "m.text",
|
||||
"m.mentions": {},
|
||||
},
|
||||
"m.relates_to": {
|
||||
event_id: editedEvent.getId(),
|
||||
rel_type: "m.replace",
|
||||
},
|
||||
"m.mentions": {},
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -191,15 +195,17 @@ describe("<EditMessageComposer/>", () => {
|
|||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": " * hello <em>world</em>",
|
||||
"m.new_content": {
|
||||
body: "hello *world*",
|
||||
msgtype: "m.text",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: "hello <em>world</em>",
|
||||
"body": "hello *world*",
|
||||
"msgtype": "m.text",
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": "hello <em>world</em>",
|
||||
"m.mentions": {},
|
||||
},
|
||||
"m.relates_to": {
|
||||
event_id: editedEvent.getId(),
|
||||
rel_type: "m.replace",
|
||||
},
|
||||
"m.mentions": {},
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -216,15 +222,17 @@ describe("<EditMessageComposer/>", () => {
|
|||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": " * blinks <strong>quickly</strong>",
|
||||
"m.new_content": {
|
||||
body: "blinks __quickly__",
|
||||
msgtype: "m.emote",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: "blinks <strong>quickly</strong>",
|
||||
"body": "blinks __quickly__",
|
||||
"msgtype": "m.emote",
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": "blinks <strong>quickly</strong>",
|
||||
"m.mentions": {},
|
||||
},
|
||||
"m.relates_to": {
|
||||
event_id: editedEvent.getId(),
|
||||
rel_type: "m.replace",
|
||||
},
|
||||
"m.mentions": {},
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -240,13 +248,15 @@ describe("<EditMessageComposer/>", () => {
|
|||
"body": " * ✨sparkles✨",
|
||||
"msgtype": "m.emote",
|
||||
"m.new_content": {
|
||||
body: "✨sparkles✨",
|
||||
msgtype: "m.emote",
|
||||
"body": "✨sparkles✨",
|
||||
"msgtype": "m.emote",
|
||||
"m.mentions": {},
|
||||
},
|
||||
"m.relates_to": {
|
||||
event_id: editedEvent.getId(),
|
||||
rel_type: "m.replace",
|
||||
},
|
||||
"m.mentions": {},
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -264,33 +274,19 @@ describe("<EditMessageComposer/>", () => {
|
|||
"body": " * //dev/null is my favourite place",
|
||||
"msgtype": "m.text",
|
||||
"m.new_content": {
|
||||
body: "//dev/null is my favourite place",
|
||||
msgtype: "m.text",
|
||||
"body": "//dev/null is my favourite place",
|
||||
"msgtype": "m.text",
|
||||
"m.mentions": {},
|
||||
},
|
||||
"m.relates_to": {
|
||||
event_id: editedEvent.getId(),
|
||||
rel_type: "m.replace",
|
||||
},
|
||||
"m.mentions": {},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("with feature_intentional_mentions enabled", () => {
|
||||
const mockSettings = (mockValues: Record<string, unknown> = {}) => {
|
||||
const defaultMockValues = {
|
||||
feature_intentional_mentions: true,
|
||||
};
|
||||
jest.spyOn(SettingsStore, "getValue")
|
||||
.mockClear()
|
||||
.mockImplementation((settingName) => {
|
||||
return { ...defaultMockValues, ...mockValues }[settingName];
|
||||
});
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
mockSettings();
|
||||
});
|
||||
|
||||
describe("when message is not a reply", () => {
|
||||
it("should attach an empty mentions object for a message with no mentions", async () => {
|
||||
const editState = new EditorStateTransfer(editedEvent);
|
||||
|
@ -349,6 +345,8 @@ describe("<EditMessageComposer/>", () => {
|
|||
const editContent = " and @d";
|
||||
await editText(editContent);
|
||||
|
||||
// wait for autocompletion to render
|
||||
await screen.findByText("Dan");
|
||||
// submit autocomplete for mention
|
||||
await editText("{enter}");
|
||||
|
||||
|
@ -372,6 +370,8 @@ describe("<EditMessageComposer/>", () => {
|
|||
await editText("{backspace}{backspace}");
|
||||
// and replace with @room
|
||||
await editText("@d");
|
||||
// wait for autocompletion to render
|
||||
await screen.findByText("Dan");
|
||||
// submit autocomplete for @dan mention
|
||||
await editText("{enter}");
|
||||
|
||||
|
@ -468,6 +468,8 @@ describe("<EditMessageComposer/>", () => {
|
|||
const editState = new EditorStateTransfer(replyEvent);
|
||||
getComponent(editState);
|
||||
await editText(" and @d");
|
||||
// wait for autocompletion to render
|
||||
await screen.findByText("Dan");
|
||||
// submit autocomplete for @dan mention
|
||||
await editText("{enter}");
|
||||
|
||||
|
@ -544,5 +546,4 @@ describe("<EditMessageComposer/>", () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -39,7 +39,6 @@ import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalink
|
|||
import { mockPlatformPeg } from "../../../test-utils/platform";
|
||||
import { doMaybeLocalRoomAction } from "../../../../src/utils/local-room";
|
||||
import { addTextToComposer } from "../../../test-utils/composer";
|
||||
import SettingsStore from "../../../../src/settings/SettingsStore";
|
||||
|
||||
jest.mock("../../../../src/utils/local-room", () => ({
|
||||
doMaybeLocalRoomAction: jest.fn(),
|
||||
|
@ -97,8 +96,9 @@ describe("<SendMessageComposer/>", () => {
|
|||
const content = createMessageContent("@alice:test", model, undefined, undefined, permalinkCreator);
|
||||
|
||||
expect(content).toEqual({
|
||||
body: "hello world",
|
||||
msgtype: "m.text",
|
||||
"body": "hello world",
|
||||
"msgtype": "m.text",
|
||||
"m.mentions": {},
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -110,10 +110,11 @@ describe("<SendMessageComposer/>", () => {
|
|||
const content = createMessageContent("@alice:test", model, undefined, undefined, permalinkCreator);
|
||||
|
||||
expect(content).toEqual({
|
||||
body: "hello *world*",
|
||||
msgtype: "m.text",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: "hello <em>world</em>",
|
||||
"body": "hello *world*",
|
||||
"msgtype": "m.text",
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": "hello <em>world</em>",
|
||||
"m.mentions": {},
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -125,10 +126,11 @@ describe("<SendMessageComposer/>", () => {
|
|||
const content = createMessageContent("@alice:test", model, undefined, undefined, permalinkCreator);
|
||||
|
||||
expect(content).toEqual({
|
||||
body: "blinks __quickly__",
|
||||
msgtype: "m.emote",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: "blinks <strong>quickly</strong>",
|
||||
"body": "blinks __quickly__",
|
||||
"msgtype": "m.emote",
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": "blinks <strong>quickly</strong>",
|
||||
"m.mentions": {},
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -141,8 +143,9 @@ describe("<SendMessageComposer/>", () => {
|
|||
const content = createMessageContent("@alice:test", model, undefined, undefined, permalinkCreator);
|
||||
|
||||
expect(content).toEqual({
|
||||
body: "✨sparkles✨",
|
||||
msgtype: "m.emote",
|
||||
"body": "✨sparkles✨",
|
||||
"msgtype": "m.emote",
|
||||
"m.mentions": {},
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -155,23 +158,14 @@ describe("<SendMessageComposer/>", () => {
|
|||
const content = createMessageContent("@alice:test", model, undefined, undefined, permalinkCreator);
|
||||
|
||||
expect(content).toEqual({
|
||||
body: "/dev/null is my favourite place",
|
||||
msgtype: "m.text",
|
||||
"body": "/dev/null is my favourite place",
|
||||
"msgtype": "m.text",
|
||||
"m.mentions": {},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("attachMentions", () => {
|
||||
beforeEach(() => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockImplementation(
|
||||
(settingName) => settingName === "feature_intentional_mentions",
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockReset();
|
||||
});
|
||||
|
||||
const partsCreator = createPartCreator();
|
||||
|
||||
it("no mentions", () => {
|
||||
|
@ -488,8 +482,9 @@ describe("<SendMessageComposer/>", () => {
|
|||
fireEvent.keyDown(container.querySelector(".mx_SendMessageComposer")!, { key: "Enter" });
|
||||
|
||||
expect(mockClient.sendMessage).toHaveBeenCalledWith("myfakeroom", null, {
|
||||
body: "test message",
|
||||
msgtype: MsgType.Text,
|
||||
"body": "test message",
|
||||
"msgtype": MsgType.Text,
|
||||
"m.mentions": {},
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -507,8 +502,9 @@ describe("<SendMessageComposer/>", () => {
|
|||
fireEvent.keyDown(container.querySelector(".mx_SendMessageComposer")!, { key: "Enter" });
|
||||
|
||||
expect(mockClient.sendMessage).toHaveBeenCalledWith("myfakeroom", null, {
|
||||
body: "test message",
|
||||
msgtype: MsgType.Text,
|
||||
"body": "test message",
|
||||
"msgtype": MsgType.Text,
|
||||
"m.mentions": {},
|
||||
});
|
||||
|
||||
expect(defaultDispatcher.dispatch).toHaveBeenCalledWith({ action: `effects.confetti` });
|
||||
|
@ -534,8 +530,9 @@ describe("<SendMessageComposer/>", () => {
|
|||
fireEvent.keyDown(container.querySelector(".mx_SendMessageComposer")!, { key: "Enter" });
|
||||
|
||||
expect(mockClient.sendMessage).toHaveBeenCalledWith("myfakeroom", null, {
|
||||
body: "test message",
|
||||
msgtype: MsgType.Text,
|
||||
"body": "test message",
|
||||
"msgtype": MsgType.Text,
|
||||
"m.mentions": {},
|
||||
});
|
||||
|
||||
expect(defaultDispatcher.dispatch).not.toHaveBeenCalledWith({ action: `effects.confetti` });
|
||||
|
|
|
@ -27,7 +27,6 @@ import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalink
|
|||
import { VoiceRecordingStore } from "../../../../src/stores/VoiceRecordingStore";
|
||||
import { PlaybackClock } from "../../../../src/audio/PlaybackClock";
|
||||
import { mkEvent } from "../../../test-utils";
|
||||
import SettingsStore from "../../../../src/settings/SettingsStore";
|
||||
|
||||
jest.mock("../../../../src/utils/local-room", () => ({
|
||||
doMaybeLocalRoomAction: jest.fn(),
|
||||
|
@ -103,10 +102,6 @@ describe("<VoiceRecordComposerTile/>", () => {
|
|||
return fn(roomId);
|
||||
},
|
||||
);
|
||||
|
||||
jest.spyOn(SettingsStore, "getValue").mockImplementation(
|
||||
(settingName) => settingName === "feature_intentional_mentions",
|
||||
);
|
||||
});
|
||||
|
||||
describe("send", () => {
|
||||
|
|
|
@ -15,18 +15,11 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import React from "react";
|
||||
import { render, screen, waitFor } from "@testing-library/react";
|
||||
import { defer } from "matrix-js-sdk/src/utils";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
|
||||
import LabsUserSettingsTab from "../../../../../../src/components/views/settings/tabs/user/LabsUserSettingsTab";
|
||||
import SettingsStore from "../../../../../../src/settings/SettingsStore";
|
||||
import {
|
||||
getMockClientWithEventEmitter,
|
||||
mockClientMethodsServer,
|
||||
mockClientMethodsUser,
|
||||
} from "../../../../../test-utils";
|
||||
import SdkConfig from "../../../../../../src/SdkConfig";
|
||||
import MatrixClientBackedController from "../../../../../../src/settings/controllers/MatrixClientBackedController";
|
||||
|
||||
describe("<LabsUserSettingsTab />", () => {
|
||||
const sdkConfigSpy = jest.spyOn(SdkConfig, "get");
|
||||
|
@ -36,12 +29,6 @@ describe("<LabsUserSettingsTab />", () => {
|
|||
};
|
||||
const getComponent = () => <LabsUserSettingsTab {...defaultProps} />;
|
||||
|
||||
const userId = "@alice:server.org";
|
||||
const cli = getMockClientWithEventEmitter({
|
||||
...mockClientMethodsUser(userId),
|
||||
...mockClientMethodsServer(),
|
||||
});
|
||||
|
||||
const settingsValueSpy = jest.spyOn(SettingsStore, "getValue");
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -73,31 +60,4 @@ describe("<LabsUserSettingsTab />", () => {
|
|||
const labsSections = container.getElementsByClassName("mx_SettingsSubsection");
|
||||
expect(labsSections).toHaveLength(9);
|
||||
});
|
||||
|
||||
it("allow setting a labs flag which requires unstable support once support is confirmed", async () => {
|
||||
// enable labs
|
||||
sdkConfigSpy.mockImplementation((configName) => configName === "show_labs_settings");
|
||||
|
||||
const deferred = defer<boolean>();
|
||||
cli.doesServerSupportUnstableFeature.mockImplementation(async (featureName) => {
|
||||
return featureName === "org.matrix.msc3952_intentional_mentions" ? deferred.promise : false;
|
||||
});
|
||||
MatrixClientBackedController.matrixClient = cli;
|
||||
|
||||
const { queryByText } = render(getComponent());
|
||||
|
||||
expect(
|
||||
queryByText("Enable intentional mentions")!
|
||||
.closest(".mx_SettingsFlag")!
|
||||
.querySelector(".mx_AccessibleButton"),
|
||||
).toHaveAttribute("aria-disabled", "true");
|
||||
deferred.resolve(true);
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
queryByText("Enable intentional mentions")!
|
||||
.closest(".mx_SettingsFlag")!
|
||||
.querySelector(".mx_AccessibleButton"),
|
||||
).toHaveAttribute("aria-disabled", "false");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue