@@ -38,7 +38,7 @@ use ruma::{
38
38
use serde:: { Deserialize , Serialize } ;
39
39
use serde_json:: { value:: RawValue as RawJsonValue , Value } ;
40
40
use tokio:: sync:: mpsc:: { unbounded_channel, UnboundedReceiver } ;
41
- use tracing:: error;
41
+ use tracing:: { error, info } ;
42
42
43
43
use super :: { machine:: SendEventResponse , StateKeySelector } ;
44
44
use crate :: { event_handler:: EventHandlerDropGuard , room:: MessagesOptions , Error , Result , Room } ;
@@ -305,13 +305,13 @@ impl<T> EventReceiver<T> {
305
305
// value through the widget driver and only serialize here to allow potimizing
306
306
// with `serde(borrow)`.
307
307
#[ derive( Deserialize , Serialize ) ]
308
- struct RoomIdEncryptionSerializer < ' a > {
308
+ struct RoomIdEncryptionSerializer {
309
309
#[ serde( skip_serializing_if = "Option::is_none" ) ]
310
310
room_id : Option < OwnedRoomId > ,
311
311
#[ serde( skip_serializing_if = "Option::is_none" ) ]
312
312
encrypted : Option < bool > ,
313
- #[ serde( flatten, borrow ) ]
314
- rest : & ' a RawJsonValue ,
313
+ #[ serde( flatten) ]
314
+ rest : Value ,
315
315
}
316
316
317
317
/// Attach additional properties to the event.
@@ -328,12 +328,45 @@ fn add_props_to_raw<T>(
328
328
room_id : Option < OwnedRoomId > ,
329
329
encryption_info : Option < & EncryptionInfo > ,
330
330
) -> Result < Raw < T > > {
331
- match raw. deserialize_as :: < RoomIdEncryptionSerializer < ' _ > > ( ) {
331
+ match raw. deserialize_as :: < RoomIdEncryptionSerializer > ( ) {
332
332
Ok ( mut event) => {
333
333
event. room_id = room_id. or ( event. room_id ) ;
334
334
event. encrypted = encryption_info. map ( |_| true ) . or ( event. encrypted ) ;
335
+ info ! ( "rest is: {:?}" , event. rest) ;
335
336
Ok ( Raw :: new ( & event) ?. cast ( ) )
336
337
}
337
338
Err ( e) => Err ( Error :: from ( e) ) ,
338
339
}
339
340
}
341
+ #[ cfg( test) ]
342
+ mod tests {
343
+ use ruma:: { room_id, serde:: Raw } ;
344
+ use serde_json:: json;
345
+
346
+ use super :: add_props_to_raw;
347
+
348
+ #[ test]
349
+ fn test_app_props_to_raw ( ) {
350
+ let raw = Raw :: new ( & json ! ( {
351
+ "encrypted" : true ,
352
+ "type" : "m.room.message" ,
353
+ "content" : {
354
+ "body" : "Hello world"
355
+ }
356
+ } ) )
357
+ . unwrap ( ) ;
358
+ let room_id = room_id ! ( "!my_id:example.org" ) ;
359
+ let new = add_props_to_raw ( & raw , Some ( room_id. to_owned ( ) ) , None ) . unwrap ( ) ;
360
+ assert_eq ! (
361
+ serde_json:: to_value( new) . unwrap( ) ,
362
+ json!( {
363
+ "encrypted" : true ,
364
+ "room_id" : "!my_id:example.org" ,
365
+ "type" : "m.room.message" ,
366
+ "content" : {
367
+ "body" : "Hello world"
368
+ }
369
+ } )
370
+ ) ;
371
+ }
372
+ }
0 commit comments