@@ -16,6 +16,7 @@ limitations under the License.
16
16
17
17
import { MatrixClient } from "./client" ;
18
18
import { IEvent , MatrixEvent , MatrixEventEvent } from "./models/event" ;
19
+ import { RelationType } from "./@types/event" ;
19
20
20
21
export type EventMapper = ( obj : Partial < IEvent > ) => MatrixEvent ;
21
22
@@ -55,6 +56,19 @@ export function eventMapperFor(client: MatrixClient, options: MapperOpts): Event
55
56
preventReEmit = true ;
56
57
}
57
58
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
+
58
72
const thread = room ?. findThreadForEvent ( event ) ;
59
73
if ( thread ) {
60
74
event . setThread ( thread ) ;
0 commit comments