Skip to content

Commit a849607

Browse files
committed
Fix remaining sync response Debug event content leaks
… for real this time.
1 parent dab4cdd commit a849607

File tree

1 file changed

+68
-4
lines changed

1 file changed

+68
-4
lines changed

crates/matrix-sdk-base/src/sync.rs

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
1717
use std::{collections::BTreeMap, fmt};
1818

19-
use matrix_sdk_common::deserialized_responses::SyncTimelineEvent;
19+
use matrix_sdk_common::{debug::DebugRawEvent, deserialized_responses::SyncTimelineEvent};
2020
use ruma::{
2121
api::client::{
2222
push::get_notifications::v3::Notification,
@@ -81,7 +81,7 @@ impl fmt::Debug for SyncResponse {
8181
}
8282

8383
/// Updates to rooms in a [`SyncResponse`].
84-
#[derive(Clone, Debug, Default)]
84+
#[derive(Clone, Default)]
8585
pub struct Rooms {
8686
/// The rooms that the user has left or been banned from.
8787
pub leave: BTreeMap<OwnedRoomId, LeftRoom>,
@@ -91,8 +91,19 @@ pub struct Rooms {
9191
pub invite: BTreeMap<OwnedRoomId, InvitedRoom>,
9292
}
9393

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+
94105
/// Updates to joined rooms.
95-
#[derive(Clone, Debug)]
106+
#[derive(Clone)]
96107
pub struct JoinedRoom {
97108
/// Counts of unread notifications for this room.
98109
pub unread_notifications: UnreadNotificationsCount,
@@ -110,6 +121,18 @@ pub struct JoinedRoom {
110121
pub ephemeral: Vec<Raw<AnySyncEphemeralRoomEvent>>,
111122
}
112123

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+
113136
impl JoinedRoom {
114137
pub(crate) fn new(
115138
timeline: Timeline,
@@ -142,7 +165,7 @@ impl From<RumaUnreadNotificationsCount> for UnreadNotificationsCount {
142165
}
143166

144167
/// Updates to left rooms.
145-
#[derive(Clone, Debug)]
168+
#[derive(Clone)]
146169
pub struct LeftRoom {
147170
/// The timeline of messages and state changes in the room up to the point
148171
/// when the user left.
@@ -166,6 +189,16 @@ impl LeftRoom {
166189
}
167190
}
168191

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+
169202
/// Events in the room.
170203
#[derive(Clone, Debug, Default)]
171204
pub struct Timeline {
@@ -186,3 +219,34 @@ impl Timeline {
186219
Self { limited, prev_batch, ..Default::default() }
187220
}
188221
}
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

Comments
 (0)