Skip to content

Commit 9332c55

Browse files
committed
matrix-sdk-base: merge StrippedRoom and Room
1 parent f6f382e commit 9332c55

File tree

8 files changed

+30
-178
lines changed

8 files changed

+30
-178
lines changed

matrix_sdk_base/src/client.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use zeroize::Zeroizing;
6363
use crate::{
6464
error::Result,
6565
event_handler::Handler,
66-
rooms::{RoomInfo, RoomType, StrippedRoomInfo},
66+
rooms::{RoomInfo, RoomType},
6767
session::Session,
6868
store::{ambiguity_map::AmbiguityCache, Result as StoreResult, StateChanges, Store},
6969
EventHandler, RoomState,
@@ -481,7 +481,7 @@ impl BaseClient {
481481
}
482482
}
483483
_ => {
484-
room_info.handle_state_event(&s);
484+
room_info.handle_state_event(&s.content());
485485
changes.add_state_event(room_id, s.clone());
486486
}
487487
},
@@ -525,7 +525,7 @@ impl BaseClient {
525525
fn handle_invited_state(
526526
&self,
527527
events: Vec<Raw<AnyStrippedStateEvent>>,
528-
room_info: &mut StrippedRoomInfo,
528+
room_info: &mut RoomInfo,
529529
) -> (
530530
InviteState,
531531
BTreeMap<UserId, StrippedMemberEvent>,
@@ -549,7 +549,7 @@ impl BaseClient {
549549
),
550550
}
551551
} else {
552-
room_info.handle_state_event(&e);
552+
room_info.handle_state_event(&e.content());
553553
state_events
554554
.entry(e.content().event_type().to_owned())
555555
.or_insert_with(BTreeMap::new)
@@ -598,7 +598,7 @@ impl BaseClient {
598598
})
599599
{
600600
state.events.push(event.clone());
601-
room_info.handle_state_event(&event);
601+
room_info.handle_state_event(&event.content());
602602

603603
if let AnySyncStateEvent::RoomMember(member) = event {
604604
match MemberEvent::try_from(member) {

matrix_sdk_base/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ mod store;
5454
pub use event_handler::{CustomEvent, EventHandler};
5555
pub use rooms::{
5656
InvitedRoom, JoinedRoom, LeftRoom, Room, RoomInfo, RoomMember, RoomState, RoomType,
57-
StrippedRoom, StrippedRoomInfo,
5857
};
5958
pub use store::{StateChanges, StateStore, Store, StoreError};
6059

matrix_sdk_base/src/rooms/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
mod members;
22
mod normal;
3-
mod stripped;
43

54
use matrix_sdk_common::{
65
events::room::{
@@ -10,7 +9,6 @@ use matrix_sdk_common::{
109
identifiers::UserId,
1110
};
1211
pub use normal::{Room, RoomInfo, RoomType};
13-
pub use stripped::{StrippedRoom, StrippedRoomInfo};
1412

1513
pub use members::RoomMember;
1614

@@ -140,11 +138,11 @@ impl Deref for LeftRoom {
140138
/// A room in an invited state.
141139
#[derive(Debug, Clone)]
142140
pub struct InvitedRoom {
143-
pub(crate) inner: StrippedRoom,
141+
pub(crate) inner: Room,
144142
}
145143

146144
impl Deref for InvitedRoom {
147-
type Target = StrippedRoom;
145+
type Target = Room;
148146

149147
fn deref(&self) -> &Self::Target {
150148
&self.inner

matrix_sdk_base/src/rooms/normal.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use matrix_sdk_common::{
2929
guest_access::GuestAccess, history_visibility::HistoryVisibility, join_rules::JoinRule,
3030
tombstone::TombstoneEventContent,
3131
},
32-
AnySyncStateEvent, EventType,
32+
AnySyncStateEvent, AnyStateEventContent, EventType,
3333
},
3434
identifiers::{RoomAliasId, RoomId, UserId},
3535
};
@@ -43,7 +43,7 @@ use crate::{
4343

4444
use super::{BaseRoomInfo, RoomMember};
4545

46-
/// The underlying room data structure collecting state for joined and left rooms.
46+
/// The underlying room data structure collecting state for joined, left and invtied rooms.
4747
#[derive(Debug, Clone)]
4848
pub struct Room {
4949
room_id: Arc<RoomId>,
@@ -484,8 +484,8 @@ impl RoomInfo {
484484
self.base_info.encryption.is_some()
485485
}
486486

487-
pub(crate) fn handle_state_event(&mut self, event: &AnySyncStateEvent) -> bool {
488-
self.base_info.handle_state_event(&event.content())
487+
pub(crate) fn handle_state_event(&mut self, event: &AnyStateEventContent) -> bool {
488+
self.base_info.handle_state_event(&event)
489489
}
490490

491491
pub(crate) fn update_notification_count(

matrix_sdk_base/src/rooms/stripped.rs

Lines changed: 0 additions & 145 deletions
This file was deleted.

matrix_sdk_base/src/store/memory_store.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use tracing::info;
3333

3434
use crate::deserialized_responses::{MemberEvent, StrippedMemberEvent};
3535

36-
use super::{Result, RoomInfo, StateChanges, StateStore, StrippedRoomInfo};
36+
use super::{Result, RoomInfo, StateChanges, StateStore};
3737

3838
#[derive(Debug, Clone)]
3939
pub struct MemoryStore {
@@ -49,7 +49,7 @@ pub struct MemoryStore {
4949
#[allow(clippy::type_complexity)]
5050
room_state: Arc<DashMap<RoomId, DashMap<String, DashMap<String, AnySyncStateEvent>>>>,
5151
room_account_data: Arc<DashMap<RoomId, DashMap<String, AnyBasicEvent>>>,
52-
stripped_room_info: Arc<DashMap<RoomId, StrippedRoomInfo>>,
52+
stripped_room_info: Arc<DashMap<RoomId, RoomInfo>>,
5353
#[allow(clippy::type_complexity)]
5454
stripped_room_state:
5555
Arc<DashMap<RoomId, DashMap<String, DashMap<String, AnyStrippedStateEvent>>>>,
@@ -291,7 +291,7 @@ impl MemoryStore {
291291
self.room_info.iter().map(|r| r.clone()).collect()
292292
}
293293

294-
fn get_stripped_room_infos(&self) -> Vec<StrippedRoomInfo> {
294+
fn get_stripped_room_infos(&self) -> Vec<RoomInfo> {
295295
#[allow(clippy::map_clone)]
296296
self.stripped_room_info.iter().map(|r| r.clone()).collect()
297297
}
@@ -357,7 +357,7 @@ impl StateStore for MemoryStore {
357357
Ok(self.get_room_infos())
358358
}
359359

360-
async fn get_stripped_room_infos(&self) -> Result<Vec<StrippedRoomInfo>> {
360+
async fn get_stripped_room_infos(&self) -> Result<Vec<RoomInfo>> {
361361
Ok(self.get_stripped_room_infos())
362362
}
363363

matrix_sdk_base/src/store/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use sled::Db;
3535

3636
use crate::{
3737
deserialized_responses::{MemberEvent, StrippedMemberEvent},
38-
rooms::{RoomInfo, RoomType, StrippedRoom, StrippedRoomInfo},
38+
rooms::{RoomInfo, RoomType},
3939
InvitedRoom, JoinedRoom, LeftRoom, Room, RoomState, Session,
4040
};
4141

@@ -164,8 +164,8 @@ pub trait StateStore: AsyncTraitDeps {
164164
/// Get all the pure `RoomInfo`s the store knows about.
165165
async fn get_room_infos(&self) -> Result<Vec<RoomInfo>>;
166166

167-
/// Get all the pure `StrippedRoomInfo`s the store knows about.
168-
async fn get_stripped_room_infos(&self) -> Result<Vec<StrippedRoomInfo>>;
167+
/// Get all the pure `RoomInfo`s the store knows about.
168+
async fn get_stripped_room_infos(&self) -> Result<Vec<RoomInfo>>;
169169

170170
/// Get all the users that use the given display name in the given room.
171171
///
@@ -192,7 +192,7 @@ pub struct Store {
192192
pub(crate) session: Arc<RwLock<Option<Session>>>,
193193
pub(crate) sync_token: Arc<RwLock<Option<String>>>,
194194
rooms: Arc<DashMap<RoomId, Room>>,
195-
stripped_rooms: Arc<DashMap<RoomId, StrippedRoom>>,
195+
stripped_rooms: Arc<DashMap<RoomId, Room>>,
196196
}
197197

198198
impl Store {
@@ -216,7 +216,7 @@ impl Store {
216216
}
217217

218218
for info in self.inner.get_stripped_room_infos().await? {
219-
let room = StrippedRoom::restore(&session.user_id, self.inner.clone(), info);
219+
let room = Room::restore(&session.user_id, self.inner.clone(), info);
220220
self.stripped_rooms.insert(room.room_id().to_owned(), room);
221221
}
222222

@@ -315,12 +315,12 @@ impl Store {
315315
})
316316
}
317317

318-
fn get_stripped_room(&self, room_id: &RoomId) -> Option<StrippedRoom> {
318+
fn get_stripped_room(&self, room_id: &RoomId) -> Option<Room> {
319319
#[allow(clippy::map_clone)]
320320
self.stripped_rooms.get(room_id).map(|r| r.clone())
321321
}
322322

323-
pub(crate) async fn get_or_create_stripped_room(&self, room_id: &RoomId) -> StrippedRoom {
323+
pub(crate) async fn get_or_create_stripped_room(&self, room_id: &RoomId) -> Room {
324324
let session = self.session.read().await;
325325
let user_id = &session
326326
.as_ref()
@@ -329,7 +329,7 @@ impl Store {
329329

330330
self.stripped_rooms
331331
.entry(room_id.clone())
332-
.or_insert_with(|| StrippedRoom::new(user_id, self.inner.clone(), room_id))
332+
.or_insert_with(|| Room::new(user_id, self.inner.clone(), room_id, RoomType::Invited))
333333
.clone()
334334
}
335335

@@ -384,8 +384,8 @@ pub struct StateChanges {
384384
pub stripped_state: BTreeMap<RoomId, BTreeMap<String, BTreeMap<String, AnyStrippedStateEvent>>>,
385385
/// A mapping of `RoomId` to a map of users and their `StrippedMemberEvent`.
386386
pub stripped_members: BTreeMap<RoomId, BTreeMap<UserId, StrippedMemberEvent>>,
387-
/// A map of `RoomId` to `StrippedRoomInfo`.
388-
pub invited_room_info: BTreeMap<RoomId, StrippedRoomInfo>,
387+
/// A map of `RoomId` to `RoomInfo`.
388+
pub invited_room_info: BTreeMap<RoomId, RoomInfo>,
389389
}
390390

391391
impl StateChanges {
@@ -408,8 +408,8 @@ impl StateChanges {
408408
.insert(room.room_id.as_ref().to_owned(), room);
409409
}
410410

411-
/// Update the `StateChanges` struct with the given `StrippedRoomInfo`.
412-
pub fn add_stripped_room(&mut self, room: StrippedRoomInfo) {
411+
/// Update the `StateChanges` struct with the given `RoomInfo`.
412+
pub fn add_stripped_room(&mut self, room: RoomInfo) {
413413
self.invited_room_info
414414
.insert(room.room_id.as_ref().to_owned(), room);
415415
}

0 commit comments

Comments
 (0)