@@ -130,4 +130,49 @@ describe("Relations", function() {
130130 await relationsCreated ;
131131 }
132132 } ) ;
133+
134+ it ( "should ignore m.replace for state events" , async ( ) => {
135+ const userId = "@bob:example.com" ;
136+ const room = new Room ( "room123" , null , userId ) ;
137+ const relations = new Relations ( "m.replace" , "m.room.topic" , room ) ;
138+
139+ // Create an instance of a state event with rel_type m.replace
140+ const originalTopic = new MatrixEvent ( {
141+ "sender" : userId ,
142+ "type" : "m.room.topic" ,
143+ "event_id" : "$orig" ,
144+ "room_id" : room . roomId ,
145+ "content" : {
146+ "topic" : "orig" ,
147+ } ,
148+ "state_key" : "" ,
149+ } ) ;
150+ const badlyEditedTopic = new MatrixEvent ( {
151+ "sender" : userId ,
152+ "type" : "m.room.topic" ,
153+ "event_id" : "$orig" ,
154+ "room_id" : room . roomId ,
155+ "content" : {
156+ "topic" : "topic" ,
157+ "m.new_content" : {
158+ "topic" : "edit" ,
159+ } ,
160+ "m.relates_to" : {
161+ "event_id" : "$orig" ,
162+ "rel_type" : "m.replace" ,
163+ } ,
164+ } ,
165+ "state_key" : "" ,
166+ } ) ;
167+
168+ await relations . setTargetEvent ( originalTopic ) ;
169+ expect ( originalTopic . replacingEvent ( ) ) . toBe ( null ) ;
170+ expect ( originalTopic . getContent ( ) . topic ) . toBe ( "orig" ) ;
171+
172+ await relations . addEvent ( badlyEditedTopic ) ;
173+ expect ( originalTopic . replacingEvent ( ) ) . toBe ( null ) ;
174+ expect ( originalTopic . getContent ( ) . topic ) . toBe ( "orig" ) ;
175+ expect ( badlyEditedTopic . replacingEvent ( ) ) . toBe ( null ) ;
176+ expect ( badlyEditedTopic . getContent ( ) . topic ) . toBe ( "topic" ) ;
177+ } ) ;
133178} ) ;
0 commit comments