Skip to content

Commit 9e37980

Browse files
authored
Handle edits which are bundled with an event, per MSC3925 (#3045)
1 parent de176db commit 9e37980

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/event-mapper.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616

1717
import { MatrixClient } from "./client";
1818
import { IEvent, MatrixEvent, MatrixEventEvent } from "./models/event";
19+
import { RelationType } from "./@types/event";
1920

2021
export type EventMapper = (obj: Partial<IEvent>) => MatrixEvent;
2122

@@ -55,6 +56,19 @@ export function eventMapperFor(client: MatrixClient, options: MapperOpts): Event
5556
preventReEmit = true;
5657
}
5758

59+
// if there is a complete edit bundled alongside the event, perform the replacement.
60+
// (prior to MSC3925, events were automatically replaced on the server-side. MSC3925 proposes that that doesn't
61+
// happen automatically but the server does provide us with the whole content of the edit event.)
62+
const bundledEdit = event.getServerAggregatedRelation<Partial<IEvent>>(RelationType.Replace);
63+
if (bundledEdit?.content) {
64+
const replacement = mapper(bundledEdit);
65+
// XXX: it's worth noting that the spec says we should only respect encrypted edits if, once decrypted, the
66+
// replacement has a `m.new_content` property. The problem is that we haven't yet decrypted the replacement
67+
// (it should be happening in the background), so we can't enforce this. Possibly we should for decryption
68+
// to complete, but that sounds a bit racy. For now, we just assume it's ok.
69+
event.makeReplaced(replacement);
70+
}
71+
5872
const thread = room?.findThreadForEvent(event);
5973
if (thread) {
6074
event.setThread(thread);

0 commit comments

Comments
 (0)