You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-31 15:24:23 +03:00
Revert "Revert "Move all related messages into main timeline on redaction""
This reverts commit 257b40bceb
.
This commit is contained in:
@ -134,6 +134,94 @@ describe("MatrixEvent", () => {
|
|||||||
expect(threadLiveEventIds(room, 0)).not.toContain(ev.getId());
|
expect(threadLiveEventIds(room, 0)).not.toContain(ev.getId());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should move reactions to a redacted event into the main timeline", async () => {
|
||||||
|
// Given an event in a thread with a reaction
|
||||||
|
const mockClient = createMockClient();
|
||||||
|
const room = new Room("!roomid:e.xyz", mockClient, "myname");
|
||||||
|
const threadRoot = createEvent("$threadroot:server");
|
||||||
|
const ev = createThreadedEvent("$event1:server", threadRoot.getId()!);
|
||||||
|
const reaction = createReactionEvent("$reaction:server", ev.getId()!);
|
||||||
|
|
||||||
|
await room.addLiveEvents([threadRoot, ev, reaction]);
|
||||||
|
await room.createThreadsTimelineSets();
|
||||||
|
expect(reaction.threadRootId).toEqual(threadRoot.getId());
|
||||||
|
expect(mainTimelineLiveEventIds(room)).toEqual([threadRoot.getId()]);
|
||||||
|
expect(threadLiveEventIds(room, 0)).toEqual([threadRoot.getId(), ev.getId(), reaction.getId()]);
|
||||||
|
|
||||||
|
// When I redact the event
|
||||||
|
const redaction = createRedaction(ev.getId()!);
|
||||||
|
ev.makeRedacted(redaction, room);
|
||||||
|
|
||||||
|
// Then the reaction moves into the main timeline
|
||||||
|
expect(reaction.threadRootId).toBeUndefined();
|
||||||
|
expect(mainTimelineLiveEventIds(room)).toEqual([threadRoot.getId(), ev.getId(), reaction.getId()]);
|
||||||
|
expect(threadLiveEventIds(room, 0)).not.toContain(reaction.getId());
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should move edits of a redacted event into the main timeline", async () => {
|
||||||
|
// Given an event in a thread with a reaction
|
||||||
|
const mockClient = createMockClient();
|
||||||
|
const room = new Room("!roomid:e.xyz", mockClient, "myname");
|
||||||
|
const threadRoot = createEvent("$threadroot:server");
|
||||||
|
const ev = createThreadedEvent("$event1:server", threadRoot.getId()!);
|
||||||
|
const edit = createEditEvent("$edit:server", ev.getId()!);
|
||||||
|
|
||||||
|
await room.addLiveEvents([threadRoot, ev, edit]);
|
||||||
|
await room.createThreadsTimelineSets();
|
||||||
|
expect(edit.threadRootId).toEqual(threadRoot.getId());
|
||||||
|
expect(mainTimelineLiveEventIds(room)).toEqual([threadRoot.getId()]);
|
||||||
|
expect(threadLiveEventIds(room, 0)).toEqual([threadRoot.getId(), ev.getId(), edit.getId()]);
|
||||||
|
|
||||||
|
// When I redact the event
|
||||||
|
const redaction = createRedaction(ev.getId()!);
|
||||||
|
ev.makeRedacted(redaction, room);
|
||||||
|
|
||||||
|
// Then the edit moves into the main timeline
|
||||||
|
expect(edit.threadRootId).toBeUndefined();
|
||||||
|
expect(mainTimelineLiveEventIds(room)).toEqual([threadRoot.getId(), ev.getId(), edit.getId()]);
|
||||||
|
expect(threadLiveEventIds(room, 0)).not.toContain(edit.getId());
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should move reactions to replies to replies a redacted event into the main timeline", async () => {
|
||||||
|
// Given an event in a thread with a reaction
|
||||||
|
const mockClient = createMockClient();
|
||||||
|
const room = new Room("!roomid:e.xyz", mockClient, "myname");
|
||||||
|
const threadRoot = createEvent("$threadroot:server");
|
||||||
|
const ev = createThreadedEvent("$event1:server", threadRoot.getId()!);
|
||||||
|
const reply1 = createReplyEvent("$reply1:server", ev.getId()!);
|
||||||
|
const reply2 = createReplyEvent("$reply2:server", reply1.getId()!);
|
||||||
|
const reaction = createReactionEvent("$reaction:server", reply2.getId()!);
|
||||||
|
|
||||||
|
await room.addLiveEvents([threadRoot, ev, reply1, reply2, reaction]);
|
||||||
|
await room.createThreadsTimelineSets();
|
||||||
|
expect(reaction.threadRootId).toEqual(threadRoot.getId());
|
||||||
|
expect(mainTimelineLiveEventIds(room)).toEqual([threadRoot.getId()]);
|
||||||
|
expect(threadLiveEventIds(room, 0)).toEqual([
|
||||||
|
threadRoot.getId(),
|
||||||
|
ev.getId(),
|
||||||
|
reply1.getId(),
|
||||||
|
reply2.getId(),
|
||||||
|
reaction.getId(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// When I redact the event
|
||||||
|
const redaction = createRedaction(ev.getId()!);
|
||||||
|
ev.makeRedacted(redaction, room);
|
||||||
|
|
||||||
|
// Then the replies move to the main thread and the reaction disappears
|
||||||
|
expect(reaction.threadRootId).toBeUndefined();
|
||||||
|
expect(mainTimelineLiveEventIds(room)).toEqual([
|
||||||
|
threadRoot.getId(),
|
||||||
|
ev.getId(),
|
||||||
|
reply1.getId(),
|
||||||
|
reply2.getId(),
|
||||||
|
reaction.getId(),
|
||||||
|
]);
|
||||||
|
expect(threadLiveEventIds(room, 0)).not.toContain(reply1.getId());
|
||||||
|
expect(threadLiveEventIds(room, 0)).not.toContain(reply2.getId());
|
||||||
|
expect(threadLiveEventIds(room, 0)).not.toContain(reaction.getId());
|
||||||
|
});
|
||||||
|
|
||||||
function createMockClient(): MatrixClient {
|
function createMockClient(): MatrixClient {
|
||||||
return {
|
return {
|
||||||
supportsThreads: jest.fn().mockReturnValue(true),
|
supportsThreads: jest.fn().mockReturnValue(true),
|
||||||
@ -166,6 +254,51 @@ describe("MatrixEvent", () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createEditEvent(eventId: string, repliedToId: string): MatrixEvent {
|
||||||
|
return new MatrixEvent({
|
||||||
|
type: "m.room.message",
|
||||||
|
content: {
|
||||||
|
"body": "Edited",
|
||||||
|
"m.new_content": {
|
||||||
|
body: "Edited",
|
||||||
|
},
|
||||||
|
"m.relates_to": {
|
||||||
|
event_id: repliedToId,
|
||||||
|
rel_type: "m.replace",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
event_id: eventId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function createReplyEvent(eventId: string, repliedToId: string): MatrixEvent {
|
||||||
|
return new MatrixEvent({
|
||||||
|
type: "m.room.message",
|
||||||
|
content: {
|
||||||
|
"m.relates_to": {
|
||||||
|
event_id: repliedToId,
|
||||||
|
key: "x",
|
||||||
|
rel_type: "m.in_reply_to",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
event_id: eventId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function createReactionEvent(eventId: string, reactedToId: string): MatrixEvent {
|
||||||
|
return new MatrixEvent({
|
||||||
|
type: "m.reaction",
|
||||||
|
content: {
|
||||||
|
"m.relates_to": {
|
||||||
|
event_id: reactedToId,
|
||||||
|
key: "x",
|
||||||
|
rel_type: "m.annotation",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
event_id: eventId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function createRedaction(redactedEventid: string): MatrixEvent {
|
function createRedaction(redactedEventid: string): MatrixEvent {
|
||||||
return new MatrixEvent({
|
return new MatrixEvent({
|
||||||
type: "m.room.redaction",
|
type: "m.room.redaction",
|
||||||
|
@ -1210,12 +1210,27 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
|
|||||||
|
|
||||||
// If the redacted event was in a thread
|
// If the redacted event was in a thread
|
||||||
if (room && this.threadRootId && this.threadRootId !== this.getId()) {
|
if (room && this.threadRootId && this.threadRootId !== this.getId()) {
|
||||||
this.moveToMainTimeline(room);
|
this.moveAllRelatedToMainTimeline(room);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.invalidateExtensibleEvent();
|
this.invalidateExtensibleEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private moveAllRelatedToMainTimeline(room: Room): void {
|
||||||
|
const thread = this.thread;
|
||||||
|
this.moveToMainTimeline(room);
|
||||||
|
|
||||||
|
// If we dont have access to the thread, we can only move this
|
||||||
|
// event, not things related to it.
|
||||||
|
if (thread) {
|
||||||
|
for (const event of thread.events) {
|
||||||
|
if (event.getRelation()?.event_id === this.getId()) {
|
||||||
|
event.moveAllRelatedToMainTimeline(room);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private moveToMainTimeline(room: Room): void {
|
private moveToMainTimeline(room: Room): void {
|
||||||
// Remove it from its thread
|
// Remove it from its thread
|
||||||
this.thread?.timelineSet.removeEvent(this.getId()!);
|
this.thread?.timelineSet.removeEvent(this.getId()!);
|
||||||
|
Reference in New Issue
Block a user