Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit c5befa1

Browse files
author
Kerry
authored
Stabilize support for MSC3952: intentional mentions (#10967)
* enable feature_intentional_mentions with v1.7 * org.matrix.msc3952.mentions -> m.mentions * update push rules test util * only support stable version 1.7 * use stable values for msc3952 push rules * use stable intentional mentions rule sin test models * unstable feature in settings controller
1 parent 113b630 commit c5befa1

12 files changed

+88
-85
lines changed

src/components/views/rooms/SendMessageComposer.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export function attachMentions(
8989
}
9090

9191
// The mentions property *always* gets included to disable legacy push rules.
92-
const mentions: IMentions = (content["org.matrix.msc3952.mentions"] = {});
92+
const mentions: IMentions = (content["m.mentions"] = {});
9393

9494
const userMentions = new Set<string>();
9595
let roomMention = false;
@@ -100,7 +100,7 @@ export function attachMentions(
100100
userMentions.add(replyToEvent.sender!.userId);
101101
// TODO What do we do if the reply event *doeesn't* have this property?
102102
// Try to fish out replies from the contents?
103-
const userIds = replyToEvent.getContent()["org.matrix.msc3952.mentions"]?.user_ids;
103+
const userIds = replyToEvent.getContent()["m.mentions"]?.user_ids;
104104
if (Array.isArray(userIds)) {
105105
userIds.forEach((userId) => userMentions.add(userId));
106106
}
@@ -127,7 +127,7 @@ export function attachMentions(
127127
if (editedContent) {
128128
// First, the new event content gets the *full* set of users.
129129
const newContent = content["m.new_content"];
130-
const newMentions: IMentions = (newContent["org.matrix.msc3952.mentions"] = {});
130+
const newMentions: IMentions = (newContent["m.mentions"] = {});
131131

132132
// Only include the users/room if there is any content.
133133
if (userMentions.size) {
@@ -139,7 +139,7 @@ export function attachMentions(
139139

140140
// Fetch the mentions from the original event and remove any previously
141141
// mentioned users.
142-
const prevMentions = editedContent["org.matrix.msc3952.mentions"];
142+
const prevMentions = editedContent["m.mentions"];
143143
if (Array.isArray(prevMentions?.user_ids)) {
144144
prevMentions!.user_ids.forEach((userId) => userMentions.delete(userId));
145145
}

src/settings/Settings.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,12 @@ export const SETTINGS: { [setting: string]: ISetting } = {
552552
displayName: _td("Enable intentional mentions"),
553553
labsGroup: LabGroup.Rooms,
554554
default: false,
555-
controller: new ServerSupportUnstableFeatureController("feature_intentional_mentions", defaultWatchManager, [
556-
["org.matrix.msc3952_intentional_mentions"],
557-
]),
555+
controller: new ServerSupportUnstableFeatureController(
556+
"feature_intentional_mentions",
557+
defaultWatchManager,
558+
[["org.matrix.msc3952_intentional_mentions"]],
559+
"v1.7",
560+
),
558561
},
559562
"feature_ask_to_join": {
560563
default: false,

test/ContentMessages-test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ describe("ContentMessages", () => {
245245
expect.objectContaining({
246246
"url": "mxc://server/file",
247247
"msgtype": "m.image",
248-
"org.matrix.msc3952.mentions": {
248+
"m.mentions": {
249249
user_ids: ["@bob:test"],
250250
},
251251
}),

test/components/views/rooms/EditMessageComposer-test.tsx

+22-22
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe("<EditMessageComposer/>", () => {
6969
"format": "org.matrix.custom.html",
7070
"formatted_body":
7171
'hey <a href="https://matrix.to/#/@bob:server.org">Bob</a> and <a href="https://matrix.to/#/@charlie:server.org">Charlie</a>',
72-
"org.matrix.msc3952.mentions": {
72+
"m.mentions": {
7373
user_ids: ["@bob:server.org", "@charlie:server.org"],
7474
},
7575
},
@@ -303,8 +303,8 @@ describe("<EditMessageComposer/>", () => {
303303
const messageContent = mockClient.sendMessage.mock.calls[0][2];
304304

305305
// both content.mentions and new_content.mentions are empty
306-
expect(messageContent["org.matrix.msc3952.mentions"]).toEqual({});
307-
expect(messageContent["m.new_content"]["org.matrix.msc3952.mentions"]).toEqual({});
306+
expect(messageContent["m.mentions"]).toEqual({});
307+
expect(messageContent["m.new_content"]["m.mentions"]).toEqual({});
308308
});
309309

310310
it("should retain mentions in the original message that are not removed by the edit", async () => {
@@ -319,9 +319,9 @@ describe("<EditMessageComposer/>", () => {
319319
const messageContent = mockClient.sendMessage.mock.calls[0][2];
320320

321321
// no new mentions were added, so nothing in top level mentions
322-
expect(messageContent["org.matrix.msc3952.mentions"]).toEqual({});
322+
expect(messageContent["m.mentions"]).toEqual({});
323323
// bob is still mentioned, charlie removed
324-
expect(messageContent["m.new_content"]["org.matrix.msc3952.mentions"]).toEqual({
324+
expect(messageContent["m.new_content"]["m.mentions"]).toEqual({
325325
user_ids: ["@bob:server.org"],
326326
});
327327
});
@@ -338,9 +338,9 @@ describe("<EditMessageComposer/>", () => {
338338
const messageContent = mockClient.sendMessage.mock.calls[0][2];
339339

340340
// no new mentions were added, so nothing in top level mentions
341-
expect(messageContent["org.matrix.msc3952.mentions"]).toEqual({});
341+
expect(messageContent["m.mentions"]).toEqual({});
342342
// bob is not longer mentioned in the edited message, so empty mentions in new_content
343-
expect(messageContent["m.new_content"]["org.matrix.msc3952.mentions"]).toEqual({});
343+
expect(messageContent["m.new_content"]["m.mentions"]).toEqual({});
344344
});
345345

346346
it("should add mentions that were added in the edit", async () => {
@@ -357,10 +357,10 @@ describe("<EditMessageComposer/>", () => {
357357
const messageContent = mockClient.sendMessage.mock.calls[0][2];
358358

359359
// new mention in the edit
360-
expect(messageContent["org.matrix.msc3952.mentions"]).toEqual({
360+
expect(messageContent["m.mentions"]).toEqual({
361361
user_ids: ["@dan:server.org"],
362362
});
363-
expect(messageContent["m.new_content"]["org.matrix.msc3952.mentions"]).toEqual({
363+
expect(messageContent["m.new_content"]["m.mentions"]).toEqual({
364364
user_ids: ["@dan:server.org"],
365365
});
366366
});
@@ -380,11 +380,11 @@ describe("<EditMessageComposer/>", () => {
380380
const messageContent = mockClient.sendMessage.mock.calls[0][2];
381381

382382
// new mention in the edit
383-
expect(messageContent["org.matrix.msc3952.mentions"]).toEqual({
383+
expect(messageContent["m.mentions"]).toEqual({
384384
user_ids: ["@dan:server.org"],
385385
});
386386
// all mentions in the edited version of the event
387-
expect(messageContent["m.new_content"]["org.matrix.msc3952.mentions"]).toEqual({
387+
expect(messageContent["m.new_content"]["m.mentions"]).toEqual({
388388
user_ids: ["@bob:server.org", "@dan:server.org"],
389389
});
390390
});
@@ -411,7 +411,7 @@ describe("<EditMessageComposer/>", () => {
411411
event_id: originalEvent.getId(),
412412
},
413413
},
414-
"org.matrix.msc3952.mentions": {
414+
"m.mentions": {
415415
user_ids: [originalEvent.getSender()!],
416416
},
417417
},
@@ -430,7 +430,7 @@ describe("<EditMessageComposer/>", () => {
430430
event_id: originalEvent.getId(),
431431
},
432432
},
433-
"org.matrix.msc3952.mentions": {
433+
"m.mentions": {
434434
user_ids: [
435435
// sender of event we replied to
436436
originalEvent.getSender()!,
@@ -457,9 +457,9 @@ describe("<EditMessageComposer/>", () => {
457457
const messageContent = mockClient.sendMessage.mock.calls[0][2];
458458

459459
// no new mentions from edit
460-
expect(messageContent["org.matrix.msc3952.mentions"]).toEqual({});
460+
expect(messageContent["m.mentions"]).toEqual({});
461461
// edited reply still mentions the parent event sender
462-
expect(messageContent["m.new_content"]["org.matrix.msc3952.mentions"]).toEqual({
462+
expect(messageContent["m.new_content"]["m.mentions"]).toEqual({
463463
user_ids: [originalEvent.getSender()],
464464
});
465465
});
@@ -476,12 +476,12 @@ describe("<EditMessageComposer/>", () => {
476476
const messageContent = mockClient.sendMessage.mock.calls[0][2];
477477

478478
// new mention in edit
479-
expect(messageContent["org.matrix.msc3952.mentions"]).toEqual({
479+
expect(messageContent["m.mentions"]).toEqual({
480480
user_ids: ["@dan:server.org"],
481481
});
482482
// edited reply still mentions the parent event sender
483483
// plus new mention @dan
484-
expect(messageContent["m.new_content"]["org.matrix.msc3952.mentions"]).toEqual({
484+
expect(messageContent["m.new_content"]["m.mentions"]).toEqual({
485485
user_ids: [originalEvent.getSender(), "@dan:server.org"],
486486
});
487487
});
@@ -497,10 +497,10 @@ describe("<EditMessageComposer/>", () => {
497497
const messageContent = mockClient.sendMessage.mock.calls[0][2];
498498

499499
// no mentions in edit
500-
expect(messageContent["org.matrix.msc3952.mentions"]).toEqual({});
500+
expect(messageContent["m.mentions"]).toEqual({});
501501
// edited reply still mentions the parent event sender
502502
// existing @bob mention removed
503-
expect(messageContent["m.new_content"]["org.matrix.msc3952.mentions"]).toEqual({
503+
expect(messageContent["m.new_content"]["m.mentions"]).toEqual({
504504
user_ids: [originalEvent.getSender()],
505505
});
506506
});
@@ -518,7 +518,7 @@ describe("<EditMessageComposer/>", () => {
518518
event_id: originalEvent.getId(),
519519
},
520520
},
521-
"org.matrix.msc3952.mentions": {
521+
"m.mentions": {
522522
user_ids: [
523523
// sender of event we replied to
524524
originalEvent.getSender()!,
@@ -537,9 +537,9 @@ describe("<EditMessageComposer/>", () => {
537537
const messageContent = mockClient.sendMessage.mock.calls[0][2];
538538

539539
// no mentions in edit
540-
expect(messageContent["org.matrix.msc3952.mentions"]).toEqual({});
540+
expect(messageContent["m.mentions"]).toEqual({});
541541
// edited reply still mentions the parent event sender
542-
expect(messageContent["m.new_content"]["org.matrix.msc3952.mentions"]).toEqual({
542+
expect(messageContent["m.new_content"]["m.mentions"]).toEqual({
543543
user_ids: [originalEvent.getSender()],
544544
});
545545
});

test/components/views/rooms/SendMessageComposer-test.tsx

+29-29
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ describe("<SendMessageComposer/>", () => {
178178
const content: IContent = {};
179179
attachMentions("@alice:test", content, model, undefined);
180180
expect(content).toEqual({
181-
"org.matrix.msc3952.mentions": {},
181+
"m.mentions": {},
182182
});
183183
});
184184

@@ -187,7 +187,7 @@ describe("<SendMessageComposer/>", () => {
187187
const content: IContent = {};
188188
attachMentions("@alice:test", content, model, undefined);
189189
expect(content).toEqual({
190-
"org.matrix.msc3952.mentions": { user_ids: ["@bob:test"] },
190+
"m.mentions": { user_ids: ["@bob:test"] },
191191
});
192192
});
193193

@@ -198,27 +198,27 @@ describe("<SendMessageComposer/>", () => {
198198
type: "m.room.message",
199199
user: "@bob:test",
200200
room: "!abc:test",
201-
content: { "org.matrix.msc3952.mentions": {} },
201+
content: { "m.mentions": {} },
202202
event: true,
203203
});
204204
let content: IContent = {};
205205
attachMentions("@alice:test", content, model, replyToEvent);
206206
expect(content).toEqual({
207-
"org.matrix.msc3952.mentions": { user_ids: ["@bob:test"] },
207+
"m.mentions": { user_ids: ["@bob:test"] },
208208
});
209209

210210
// It also adds any other mentioned users, but removes yourself.
211211
replyToEvent = mkEvent({
212212
type: "m.room.message",
213213
user: "@bob:test",
214214
room: "!abc:test",
215-
content: { "org.matrix.msc3952.mentions": { user_ids: ["@alice:test", "@charlie:test"] } },
215+
content: { "m.mentions": { user_ids: ["@alice:test", "@charlie:test"] } },
216216
event: true,
217217
});
218218
content = {};
219219
attachMentions("@alice:test", content, model, replyToEvent);
220220
expect(content).toEqual({
221-
"org.matrix.msc3952.mentions": { user_ids: ["@bob:test", "@charlie:test"] },
221+
"m.mentions": { user_ids: ["@bob:test", "@charlie:test"] },
222222
});
223223
});
224224

@@ -227,7 +227,7 @@ describe("<SendMessageComposer/>", () => {
227227
const content: IContent = {};
228228
attachMentions("@alice:test", content, model, undefined);
229229
expect(content).toEqual({
230-
"org.matrix.msc3952.mentions": { room: true },
230+
"m.mentions": { room: true },
231231
});
232232
});
233233

@@ -238,13 +238,13 @@ describe("<SendMessageComposer/>", () => {
238238
type: "m.room.message",
239239
user: "@alice:test",
240240
room: "!abc:test",
241-
content: { "org.matrix.msc3952.mentions": { room: true } },
241+
content: { "m.mentions": { room: true } },
242242
event: true,
243243
});
244244
const content: IContent = {};
245245
attachMentions("@alice:test", content, model, replyToEvent);
246246
expect(content).toEqual({
247-
"org.matrix.msc3952.mentions": {},
247+
"m.mentions": {},
248248
});
249249
});
250250

@@ -256,13 +256,13 @@ describe("<SendMessageComposer/>", () => {
256256
user: "@alice:test",
257257
room: "!abc:test",
258258
// @ts-ignore - Purposefully testing invalid data.
259-
content: { "org.matrix.msc3952.mentions": { user_ids: "@bob:test" } },
259+
content: { "m.mentions": { user_ids: "@bob:test" } },
260260
event: true,
261261
});
262262
const content: IContent = {};
263263
attachMentions("@alice:test", content, model, replyToEvent);
264264
expect(content).toEqual({
265-
"org.matrix.msc3952.mentions": {},
265+
"m.mentions": {},
266266
});
267267
});
268268

@@ -273,21 +273,21 @@ describe("<SendMessageComposer/>", () => {
273273
const prevContent: IContent = {};
274274
attachMentions("@alice:test", content, model, undefined, prevContent);
275275
expect(content).toEqual({
276-
"org.matrix.msc3952.mentions": {},
277-
"m.new_content": { "org.matrix.msc3952.mentions": {} },
276+
"m.mentions": {},
277+
"m.new_content": { "m.mentions": {} },
278278
});
279279
});
280280

281281
it("mentions do not propagate", () => {
282282
const model = new EditorModel([], partsCreator);
283283
const content: IContent = { "m.new_content": {} };
284284
const prevContent: IContent = {
285-
"org.matrix.msc3952.mentions": { user_ids: ["@bob:test"], room: true },
285+
"m.mentions": { user_ids: ["@bob:test"], room: true },
286286
};
287287
attachMentions("@alice:test", content, model, undefined, prevContent);
288288
expect(content).toEqual({
289-
"org.matrix.msc3952.mentions": {},
290-
"m.new_content": { "org.matrix.msc3952.mentions": {} },
289+
"m.mentions": {},
290+
"m.new_content": { "m.mentions": {} },
291291
});
292292
});
293293

@@ -297,19 +297,19 @@ describe("<SendMessageComposer/>", () => {
297297
const prevContent: IContent = {};
298298
attachMentions("@alice:test", content, model, undefined, prevContent);
299299
expect(content).toEqual({
300-
"org.matrix.msc3952.mentions": { user_ids: ["@bob:test"] },
301-
"m.new_content": { "org.matrix.msc3952.mentions": { user_ids: ["@bob:test"] } },
300+
"m.mentions": { user_ids: ["@bob:test"] },
301+
"m.new_content": { "m.mentions": { user_ids: ["@bob:test"] } },
302302
});
303303
});
304304

305305
it("test prev user mentions", () => {
306306
const model = new EditorModel([partsCreator.userPill("Bob", "@bob:test")], partsCreator);
307307
const content: IContent = { "m.new_content": {} };
308-
const prevContent: IContent = { "org.matrix.msc3952.mentions": { user_ids: ["@bob:test"] } };
308+
const prevContent: IContent = { "m.mentions": { user_ids: ["@bob:test"] } };
309309
attachMentions("@alice:test", content, model, undefined, prevContent);
310310
expect(content).toEqual({
311-
"org.matrix.msc3952.mentions": {},
312-
"m.new_content": { "org.matrix.msc3952.mentions": { user_ids: ["@bob:test"] } },
311+
"m.mentions": {},
312+
"m.new_content": { "m.mentions": { user_ids: ["@bob:test"] } },
313313
});
314314
});
315315

@@ -319,19 +319,19 @@ describe("<SendMessageComposer/>", () => {
319319
const prevContent: IContent = {};
320320
attachMentions("@alice:test", content, model, undefined, prevContent);
321321
expect(content).toEqual({
322-
"org.matrix.msc3952.mentions": { room: true },
323-
"m.new_content": { "org.matrix.msc3952.mentions": { room: true } },
322+
"m.mentions": { room: true },
323+
"m.new_content": { "m.mentions": { room: true } },
324324
});
325325
});
326326

327327
it("test prev room mention", () => {
328328
const model = new EditorModel([partsCreator.atRoomPill("@room")], partsCreator);
329329
const content: IContent = { "m.new_content": {} };
330-
const prevContent: IContent = { "org.matrix.msc3952.mentions": { room: true } };
330+
const prevContent: IContent = { "m.mentions": { room: true } };
331331
attachMentions("@alice:test", content, model, undefined, prevContent);
332332
expect(content).toEqual({
333-
"org.matrix.msc3952.mentions": {},
334-
"m.new_content": { "org.matrix.msc3952.mentions": { room: true } },
333+
"m.mentions": {},
334+
"m.new_content": { "m.mentions": { room: true } },
335335
});
336336
});
337337

@@ -340,11 +340,11 @@ describe("<SendMessageComposer/>", () => {
340340
const model = new EditorModel([], partsCreator);
341341
const content: IContent = { "m.new_content": {} };
342342
// @ts-ignore - Purposefully testing invalid data.
343-
const prevContent: IContent = { "org.matrix.msc3952.mentions": { user_ids: "@bob:test" } };
343+
const prevContent: IContent = { "m.mentions": { user_ids: "@bob:test" } };
344344
attachMentions("@alice:test", content, model, undefined, prevContent);
345345
expect(content).toEqual({
346-
"org.matrix.msc3952.mentions": {},
347-
"m.new_content": { "org.matrix.msc3952.mentions": {} },
346+
"m.mentions": {},
347+
"m.new_content": { "m.mentions": {} },
348348
});
349349
});
350350
});

0 commit comments

Comments
 (0)