@@ -59,9 +59,11 @@ impl TimestampArg for u64 {
59
59
}
60
60
}
61
61
62
- #[ derive( Debug , Default ) ]
62
+ #[ derive( Debug , Default , Serialize ) ]
63
63
struct Unsigned {
64
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
64
65
transaction_id : Option < OwnedTransactionId > ,
66
+ #[ serde( rename = "m.relations" , skip_serializing_if = "Option::is_none" ) ]
65
67
relations : Option < BundledMessageLikeRelations < Raw < AnySyncTimelineEvent > > > ,
66
68
}
67
69
@@ -156,19 +158,7 @@ where
156
158
}
157
159
158
160
if let Some ( unsigned) = self . unsigned {
159
- let mut unsigned_json = json ! ( { } ) ;
160
-
161
- // We can't plain serialize `Unsigned`, otherwise this would result in some
162
- // `null` fields when options are set to none, which Ruma rejects.
163
- let unsigned_obj = unsigned_json. as_object_mut ( ) . unwrap ( ) ;
164
- if let Some ( transaction_id) = unsigned. transaction_id {
165
- unsigned_obj. insert ( "transaction_id" . to_owned ( ) , json ! ( transaction_id) ) ;
166
- }
167
- if let Some ( relations) = unsigned. relations {
168
- unsigned_obj. insert ( "m.relations" . to_owned ( ) , json ! ( relations) ) ;
169
- }
170
-
171
- map. insert ( "unsigned" . to_owned ( ) , unsigned_json) ;
161
+ map. insert ( "unsigned" . to_owned ( ) , json ! ( unsigned) ) ;
172
162
}
173
163
174
164
if let Some ( state_key) = self . state_key {
0 commit comments