Implement MSC3952: intentional mentions (#9983)
Implements the intentional mentions feature of MSC3952 (behind a labs flag). If enabled, this will send an org.matrix.msc3952.mentions property on events that will contain the user IDs and/or whether the room is being mentioned. These mentions also gets propagated via some custom behaviour for replies and edits.
This commit is contained in:
parent
5a1a91f16a
commit
e19127f8ad
11 changed files with 431 additions and 23 deletions
|
@ -21,8 +21,9 @@ import encrypt, { IEncryptedFile } from "matrix-encrypt-attachment";
|
|||
|
||||
import ContentMessages, { UploadCanceledError, uploadFile } from "../src/ContentMessages";
|
||||
import { doMaybeLocalRoomAction } from "../src/utils/local-room";
|
||||
import { createTestClient } from "./test-utils";
|
||||
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({}) }));
|
||||
|
||||
|
@ -51,6 +52,7 @@ describe("ContentMessages", () => {
|
|||
|
||||
beforeEach(() => {
|
||||
client = {
|
||||
getSafeUserId: jest.fn().mockReturnValue("@alice:test"),
|
||||
sendStickerMessage: jest.fn(),
|
||||
sendMessage: jest.fn(),
|
||||
isRoomEncrypted: jest.fn().mockReturnValue(false),
|
||||
|
@ -221,6 +223,34 @@ describe("ContentMessages", () => {
|
|||
expect(upload.total).toBe(1234);
|
||||
await prom;
|
||||
});
|
||||
|
||||
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({
|
||||
type: "m.room.message",
|
||||
user: "@bob:test",
|
||||
room: roomId,
|
||||
content: {},
|
||||
event: true,
|
||||
});
|
||||
await contentMessages.sendContentToRoom(file, roomId, undefined, client, replyToEvent);
|
||||
expect(client.sendMessage).toHaveBeenCalledWith(
|
||||
roomId,
|
||||
null,
|
||||
expect.objectContaining({
|
||||
"url": "mxc://server/file",
|
||||
"msgtype": "m.image",
|
||||
"org.matrix.msc3952.mentions": {
|
||||
user_ids: ["@bob:test"],
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getCurrentUploads", () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue