feat: show call participants in room list (Discord-style)
Docker / Docker Buildx (push) Has been cancelled
Build Debian package / Build package (release) Has been cancelled
Build and Deploy / prepare (release) Has been cancelled
Deploy release / Deploy to Cloudflare Pages (release) Has been cancelled
Build and Deploy / Trigger Pro pipeline (release) Has been cancelled
Build and Deploy / Windows arm64 (release) Has been cancelled
Build and Deploy / Windows x64 (release) Has been cancelled
Build and Deploy / macOS (release) Has been cancelled
Build and Deploy / Linux amd64 (sqlcipher static) (release) Has been cancelled
Build and Deploy / Linux arm64 (sqlcipher static) (release) Has been cancelled
Build and Deploy / ${{ needs.prepare.outputs.deploy == 'true' && 'Deploy' || 'Deploy (dry-run)' }} (release) Has been cancelled
Build and Deploy / Deploy builds to ESS (release) Has been cancelled
Docker / Docker Buildx (push) Has been cancelled
Build Debian package / Build package (release) Has been cancelled
Build and Deploy / prepare (release) Has been cancelled
Deploy release / Deploy to Cloudflare Pages (release) Has been cancelled
Build and Deploy / Trigger Pro pipeline (release) Has been cancelled
Build and Deploy / Windows arm64 (release) Has been cancelled
Build and Deploy / Windows x64 (release) Has been cancelled
Build and Deploy / macOS (release) Has been cancelled
Build and Deploy / Linux amd64 (sqlcipher static) (release) Has been cancelled
Build and Deploy / Linux arm64 (sqlcipher static) (release) Has been cancelled
Build and Deploy / ${{ needs.prepare.outputs.deploy == 'true' && 'Deploy' || 'Deploy (dry-run)' }} (release) Has been cancelled
Build and Deploy / Deploy builds to ESS (release) Has been cancelled
This commit is contained in:
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
Copyright 2024 New Vector Ltd.
|
||||
Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { type IContent } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { attachMentions } from "../../../src/utils/messages";
|
||||
import EditorModel from "../../../src/editor/model";
|
||||
import { mkEvent } from "../../test-utils";
|
||||
import { createPartCreator } from "../editor/mock";
|
||||
|
||||
describe("attachMentions", () => {
|
||||
const partsCreator = createPartCreator();
|
||||
|
||||
it("no mentions", () => {
|
||||
const model = new EditorModel([], partsCreator);
|
||||
const content: IContent = {};
|
||||
attachMentions("@alice:test", content, model, undefined);
|
||||
expect(content).toEqual({
|
||||
"m.mentions": {},
|
||||
});
|
||||
});
|
||||
|
||||
it("test user mentions", () => {
|
||||
const model = new EditorModel([partsCreator.userPill("Bob", "@bob:test")], partsCreator);
|
||||
const content: IContent = {};
|
||||
attachMentions("@alice:test", content, model, undefined);
|
||||
expect(content).toEqual({
|
||||
"m.mentions": { user_ids: ["@bob:test"] },
|
||||
});
|
||||
});
|
||||
|
||||
it("test reply", () => {
|
||||
// Replying to an event adds the sender to the list of mentioned users.
|
||||
const model = new EditorModel([], partsCreator);
|
||||
let replyToEvent = mkEvent({
|
||||
type: "m.room.message",
|
||||
user: "@bob:test",
|
||||
room: "!abc:test",
|
||||
content: { "m.mentions": {} },
|
||||
event: true,
|
||||
});
|
||||
let content: IContent = {};
|
||||
attachMentions("@alice:test", content, model, replyToEvent);
|
||||
expect(content).toEqual({
|
||||
"m.mentions": { user_ids: ["@bob:test"] },
|
||||
});
|
||||
|
||||
// It no longer adds any other mentioned users
|
||||
replyToEvent = mkEvent({
|
||||
type: "m.room.message",
|
||||
user: "@bob:test",
|
||||
room: "!abc:test",
|
||||
content: { "m.mentions": { user_ids: ["@alice:test", "@charlie:test"] } },
|
||||
event: true,
|
||||
});
|
||||
content = {};
|
||||
attachMentions("@alice:test", content, model, replyToEvent);
|
||||
expect(content).toEqual({
|
||||
"m.mentions": { user_ids: ["@bob:test"] },
|
||||
});
|
||||
});
|
||||
|
||||
it("test room mention", () => {
|
||||
const model = new EditorModel([partsCreator.atRoomPill("@room")], partsCreator);
|
||||
const content: IContent = {};
|
||||
attachMentions("@alice:test", content, model, undefined);
|
||||
expect(content).toEqual({
|
||||
"m.mentions": { room: true },
|
||||
});
|
||||
});
|
||||
|
||||
it("test reply to room mention", () => {
|
||||
// Replying to a room mention shouldn't automatically be a room mention.
|
||||
const model = new EditorModel([], partsCreator);
|
||||
const replyToEvent = mkEvent({
|
||||
type: "m.room.message",
|
||||
user: "@alice:test",
|
||||
room: "!abc:test",
|
||||
content: { "m.mentions": { room: true } },
|
||||
event: true,
|
||||
});
|
||||
const content: IContent = {};
|
||||
attachMentions("@alice:test", content, model, replyToEvent);
|
||||
expect(content).toEqual({
|
||||
"m.mentions": {},
|
||||
});
|
||||
});
|
||||
|
||||
it("test broken mentions", () => {
|
||||
// Replying to a room mention shouldn't automatically be a room mention.
|
||||
const model = new EditorModel([], partsCreator);
|
||||
const replyToEvent = mkEvent({
|
||||
type: "m.room.message",
|
||||
user: "@alice:test",
|
||||
room: "!abc:test",
|
||||
// @ts-ignore - Purposefully testing invalid data.
|
||||
content: { "m.mentions": { user_ids: "@bob:test" } },
|
||||
event: true,
|
||||
});
|
||||
const content: IContent = {};
|
||||
attachMentions("@alice:test", content, model, replyToEvent);
|
||||
expect(content).toEqual({
|
||||
"m.mentions": {},
|
||||
});
|
||||
});
|
||||
|
||||
describe("attachMentions with edit", () => {
|
||||
it("no mentions", () => {
|
||||
const model = new EditorModel([], partsCreator);
|
||||
const content: IContent = { "m.new_content": {} };
|
||||
const prevContent: IContent = {};
|
||||
attachMentions("@alice:test", content, model, undefined, prevContent);
|
||||
expect(content).toEqual({
|
||||
"m.mentions": {},
|
||||
"m.new_content": { "m.mentions": {} },
|
||||
});
|
||||
});
|
||||
|
||||
it("mentions do not propagate", () => {
|
||||
const model = new EditorModel([], partsCreator);
|
||||
const content: IContent = { "m.new_content": {} };
|
||||
const prevContent: IContent = {
|
||||
"m.mentions": { user_ids: ["@bob:test"], room: true },
|
||||
};
|
||||
attachMentions("@alice:test", content, model, undefined, prevContent);
|
||||
expect(content).toEqual({
|
||||
"m.mentions": {},
|
||||
"m.new_content": { "m.mentions": {} },
|
||||
});
|
||||
});
|
||||
|
||||
it("test user mentions", () => {
|
||||
const model = new EditorModel([partsCreator.userPill("Bob", "@bob:test")], partsCreator);
|
||||
const content: IContent = { "m.new_content": {} };
|
||||
const prevContent: IContent = {};
|
||||
attachMentions("@alice:test", content, model, undefined, prevContent);
|
||||
expect(content).toEqual({
|
||||
"m.mentions": { user_ids: ["@bob:test"] },
|
||||
"m.new_content": { "m.mentions": { user_ids: ["@bob:test"] } },
|
||||
});
|
||||
});
|
||||
|
||||
it("test prev user mentions", () => {
|
||||
const model = new EditorModel([partsCreator.userPill("Bob", "@bob:test")], partsCreator);
|
||||
const content: IContent = { "m.new_content": {} };
|
||||
const prevContent: IContent = { "m.mentions": { user_ids: ["@bob:test"] } };
|
||||
attachMentions("@alice:test", content, model, undefined, prevContent);
|
||||
expect(content).toEqual({
|
||||
"m.mentions": {},
|
||||
"m.new_content": { "m.mentions": { user_ids: ["@bob:test"] } },
|
||||
});
|
||||
});
|
||||
|
||||
it("test room mention", () => {
|
||||
const model = new EditorModel([partsCreator.atRoomPill("@room")], partsCreator);
|
||||
const content: IContent = { "m.new_content": {} };
|
||||
const prevContent: IContent = {};
|
||||
attachMentions("@alice:test", content, model, undefined, prevContent);
|
||||
expect(content).toEqual({
|
||||
"m.mentions": { room: true },
|
||||
"m.new_content": { "m.mentions": { room: true } },
|
||||
});
|
||||
});
|
||||
|
||||
it("test prev room mention", () => {
|
||||
const model = new EditorModel([partsCreator.atRoomPill("@room")], partsCreator);
|
||||
const content: IContent = { "m.new_content": {} };
|
||||
const prevContent: IContent = { "m.mentions": { room: true } };
|
||||
attachMentions("@alice:test", content, model, undefined, prevContent);
|
||||
expect(content).toEqual({
|
||||
"m.mentions": {},
|
||||
"m.new_content": { "m.mentions": { room: true } },
|
||||
});
|
||||
});
|
||||
|
||||
it("test broken mentions", () => {
|
||||
// Replying to a room mention shouldn't automatically be a room mention.
|
||||
const model = new EditorModel([], partsCreator);
|
||||
const content: IContent = { "m.new_content": {} };
|
||||
// @ts-ignore - Purposefully testing invalid data.
|
||||
const prevContent: IContent = { "m.mentions": { user_ids: "@bob:test" } };
|
||||
attachMentions("@alice:test", content, model, undefined, prevContent);
|
||||
expect(content).toEqual({
|
||||
"m.mentions": {},
|
||||
"m.new_content": { "m.mentions": {} },
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user