16
16
17
17
use std:: { collections:: BTreeMap , fmt} ;
18
18
19
- use matrix_sdk_common:: deserialized_responses:: SyncTimelineEvent ;
19
+ use matrix_sdk_common:: { debug :: DebugRawEvent , deserialized_responses:: SyncTimelineEvent } ;
20
20
use ruma:: {
21
21
api:: client:: {
22
22
push:: get_notifications:: v3:: Notification ,
@@ -81,7 +81,7 @@ impl fmt::Debug for SyncResponse {
81
81
}
82
82
83
83
/// Updates to rooms in a [`SyncResponse`].
84
- #[ derive( Clone , Debug , Default ) ]
84
+ #[ derive( Clone , Default ) ]
85
85
pub struct Rooms {
86
86
/// The rooms that the user has left or been banned from.
87
87
pub leave : BTreeMap < OwnedRoomId , LeftRoom > ,
@@ -91,8 +91,19 @@ pub struct Rooms {
91
91
pub invite : BTreeMap < OwnedRoomId , InvitedRoom > ,
92
92
}
93
93
94
+ #[ cfg( not( tarpaulin_include) ) ]
95
+ impl fmt:: Debug for Rooms {
96
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
97
+ f. debug_struct ( "Rooms" )
98
+ . field ( "leave" , & self . leave )
99
+ . field ( "join" , & self . join )
100
+ . field ( "invite" , & DebugInvitedRooms ( & self . invite ) )
101
+ . finish ( )
102
+ }
103
+ }
104
+
94
105
/// Updates to joined rooms.
95
- #[ derive( Clone , Debug ) ]
106
+ #[ derive( Clone ) ]
96
107
pub struct JoinedRoom {
97
108
/// Counts of unread notifications for this room.
98
109
pub unread_notifications : UnreadNotificationsCount ,
@@ -110,6 +121,18 @@ pub struct JoinedRoom {
110
121
pub ephemeral : Vec < Raw < AnySyncEphemeralRoomEvent > > ,
111
122
}
112
123
124
+ impl fmt:: Debug for JoinedRoom {
125
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
126
+ f. debug_struct ( "JoinedRoom" )
127
+ . field ( "unread_notifications" , & self . unread_notifications )
128
+ . field ( "timeline" , & self . timeline )
129
+ . field ( "state" , & DebugListOfRawEvents ( & self . state ) )
130
+ . field ( "account_data" , & DebugListOfRawEventsNoId ( & self . account_data ) )
131
+ . field ( "ephemeral" , & self . ephemeral )
132
+ . finish ( )
133
+ }
134
+ }
135
+
113
136
impl JoinedRoom {
114
137
pub ( crate ) fn new (
115
138
timeline : Timeline ,
@@ -142,7 +165,7 @@ impl From<RumaUnreadNotificationsCount> for UnreadNotificationsCount {
142
165
}
143
166
144
167
/// Updates to left rooms.
145
- #[ derive( Clone , Debug ) ]
168
+ #[ derive( Clone ) ]
146
169
pub struct LeftRoom {
147
170
/// The timeline of messages and state changes in the room up to the point
148
171
/// when the user left.
@@ -166,6 +189,16 @@ impl LeftRoom {
166
189
}
167
190
}
168
191
192
+ impl fmt:: Debug for LeftRoom {
193
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
194
+ f. debug_struct ( "JoinedRoom" )
195
+ . field ( "timeline" , & self . timeline )
196
+ . field ( "state" , & DebugListOfRawEvents ( & self . state ) )
197
+ . field ( "account_data" , & DebugListOfRawEventsNoId ( & self . account_data ) )
198
+ . finish ( )
199
+ }
200
+ }
201
+
169
202
/// Events in the room.
170
203
#[ derive( Clone , Debug , Default ) ]
171
204
pub struct Timeline {
@@ -186,3 +219,34 @@ impl Timeline {
186
219
Self { limited, prev_batch, ..Default :: default ( ) }
187
220
}
188
221
}
222
+
223
+ struct DebugInvitedRooms < ' a > ( & ' a BTreeMap < OwnedRoomId , InvitedRoom > ) ;
224
+
225
+ #[ cfg( not( tarpaulin_include) ) ]
226
+ impl < ' a > fmt:: Debug for DebugInvitedRooms < ' a > {
227
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
228
+ f. debug_map ( ) . entries ( self . 0 . iter ( ) . map ( |( k, v) | ( k, DebugInvitedRoom ( v) ) ) ) . finish ( )
229
+ }
230
+ }
231
+
232
+ struct DebugInvitedRoom < ' a > ( & ' a InvitedRoom ) ;
233
+
234
+ #[ cfg( not( tarpaulin_include) ) ]
235
+ impl < ' a > fmt:: Debug for DebugInvitedRoom < ' a > {
236
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
237
+ f. debug_struct ( "InvitedRoom" )
238
+ . field ( "invite_state" , & DebugListOfRawEvents ( & self . 0 . invite_state . events ) )
239
+ . finish ( )
240
+ }
241
+ }
242
+
243
+ struct DebugListOfRawEvents < ' a , T > ( & ' a [ Raw < T > ] ) ;
244
+
245
+ #[ cfg( not( tarpaulin_include) ) ]
246
+ impl < ' a , T > fmt:: Debug for DebugListOfRawEvents < ' a , T > {
247
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
248
+ let mut list = f. debug_list ( ) ;
249
+ list. entries ( self . 0 . iter ( ) . map ( DebugRawEvent ) ) ;
250
+ list. finish ( )
251
+ }
252
+ }
0 commit comments