Skip to content

Commit 13f50fb

Browse files
authored
fix(sdk): Remove Deref impl for SlidingSyncRoom
fix(sdk): Remove `Deref` impl for `SlidingSyncRoom`
2 parents 12cbff2 + 0f7646a commit 13f50fb

File tree

4 files changed

+44
-22
lines changed

4 files changed

+44
-22
lines changed

bindings/matrix-sdk-ffi/src/sliding_sync.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,23 @@ impl SlidingSyncRoom {
130130
}
131131

132132
pub fn is_dm(&self) -> Option<bool> {
133-
self.inner.is_dm
133+
self.inner.is_dm()
134134
}
135135

136136
pub fn is_initial(&self) -> Option<bool> {
137-
self.inner.initial
137+
self.inner.is_initial_response()
138138
}
139+
139140
pub fn is_loading_more(&self) -> bool {
140141
self.inner.is_loading_more()
141142
}
142143

143144
pub fn has_unread_notifications(&self) -> bool {
144-
!self.inner.unread_notifications.is_empty()
145+
self.inner.has_unread_notifications()
145146
}
146147

147148
pub fn unread_notifications(&self) -> Arc<UnreadNotificationsCount> {
148-
Arc::new(self.inner.unread_notifications.clone().into())
149+
Arc::new(self.inner.unread_notifications().clone().into())
149150
}
150151

151152
pub fn full_room(&self) -> Option<Arc<Room>> {

crates/matrix-sdk/src/sliding_sync.rs

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use std::{
1717
collections::BTreeMap,
1818
fmt::Debug,
19-
ops::Deref,
19+
ops::{Deref, Not},
2020
sync::{
2121
atomic::{AtomicBool, AtomicU8, Ordering},
2222
Arc, Mutex,
@@ -34,13 +34,17 @@ use matrix_sdk_base::{deserialized_responses::SyncTimelineEvent, sync::SyncRespo
3434
use ruma::{
3535
api::client::{
3636
error::ErrorKind,
37-
sync::sync_events::v4::{
38-
self, AccountDataConfig, E2EEConfig, ExtensionsConfig, ReceiptConfig, ToDeviceConfig,
39-
TypingConfig,
37+
sync::sync_events::{
38+
v4::{
39+
self, AccountDataConfig, E2EEConfig, ExtensionsConfig, ReceiptConfig,
40+
ToDeviceConfig, TypingConfig,
41+
},
42+
UnreadNotificationsCount,
4043
},
4144
},
4245
assign,
43-
events::TimelineEventType,
46+
events::{AnySyncStateEvent, TimelineEventType},
47+
serde::Raw,
4448
OwnedRoomId, RoomId, UInt,
4549
};
4650
use serde::{Deserialize, Serialize};
@@ -163,7 +167,7 @@ impl From<&SlidingSyncRoom> for FrozenSlidingSyncRoom {
163167
fn from(value: &SlidingSyncRoom) -> Self {
164168
let locked_tl = value.timeline.lock_ref();
165169
let tl_len = locked_tl.len();
166-
// To not overflow the database, we only freeze the newest 10 items. on doing
170+
// To not overflow the database, we only freeze the newest 10 items. On doing
167171
// so, we must drop the `prev_batch` key however, as we'd otherwise
168172
// create a gap between what we have loaded and where the
169173
// prev_batch-key will start loading when paginating backwards.
@@ -275,6 +279,31 @@ impl SlidingSyncRoom {
275279
self.inner.name.as_deref()
276280
}
277281

282+
/// Is this a direct message?
283+
pub fn is_dm(&self) -> Option<bool> {
284+
self.inner.is_dm
285+
}
286+
287+
/// Was this an initial response.
288+
pub fn is_initial_response(&self) -> Option<bool> {
289+
self.inner.initial
290+
}
291+
292+
/// Is there any unread notifications?
293+
pub fn has_unread_notifications(&self) -> bool {
294+
self.inner.unread_notifications.is_empty().not()
295+
}
296+
297+
/// Get unread notifications.
298+
pub fn unread_notifications(&self) -> &UnreadNotificationsCount {
299+
&self.inner.unread_notifications
300+
}
301+
302+
/// Get the required state.
303+
pub fn required_state(&self) -> &Vec<Raw<AnySyncStateEvent>> {
304+
&self.inner.required_state
305+
}
306+
278307
fn update(&mut self, room_data: &v4::SlidingSyncRoom, timeline: Vec<SyncTimelineEvent>) {
279308
let v4::SlidingSyncRoom {
280309
name,
@@ -331,13 +360,6 @@ impl SlidingSyncRoom {
331360
}
332361
}
333362

334-
impl Deref for SlidingSyncRoom {
335-
type Target = v4::SlidingSyncRoom;
336-
fn deref(&self) -> &Self::Target {
337-
&self.inner
338-
}
339-
}
340-
341363
type ViewState = Mutable<SlidingSyncState>;
342364
type SyncMode = Mutable<SlidingSyncMode>;
343365
type StringState = Mutable<Option<String>>;

labs/jack-in/src/components/details.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ impl Details {
5151
return;
5252
};
5353

54-
let name = room_data.name.clone().unwrap_or_else(|| "unknown".to_owned());
54+
let name = room_data.name().unwrap_or("unknown").to_owned();
5555

5656
let state_events = room_data
57-
.required_state
57+
.required_state()
5858
.iter()
5959
.filter_map(|r| r.deserialize().ok())
6060
.fold(BTreeMap::<String, Vec<_>>::new(), |mut b, r| {

labs/jack-in/src/components/rooms.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ impl MockComponent for Rooms {
6464
let mut paras = vec![];
6565

6666
for r in self.sstate.get_all_rooms() {
67-
let mut cells =
68-
vec![Cell::from(r.name.clone().unwrap_or_else(|| "unknown".to_owned()))];
69-
if let Some(c) = r.unread_notifications.notification_count {
67+
let mut cells = vec![Cell::from(r.name().unwrap_or("unknown").to_owned())];
68+
if let Some(c) = r.unread_notifications().notification_count {
7069
let count: u32 = c.try_into().unwrap_or_default();
7170
if count > 0 {
7271
cells.push(Cell::from(c.to_string()))

0 commit comments

Comments
 (0)