Skip to content

Commit

Permalink
chore: Remove the get_ of some Store's methods.
Browse files Browse the repository at this point in the history
This patch renames `Store::get_rooms`, `::get_rooms_filtered` and
`::get_room` to respectively `::rooms`, `::rooms_filtered` and `::room`.
This `get_` prefix isn't really Rust idiomatic.
  • Loading branch information
Hywan committed Jun 13, 2024
1 parent 9ccf94d commit 984b95b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
17 changes: 8 additions & 9 deletions crates/matrix-sdk-base/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ impl BaseClient {

/// Get all the rooms this client knows about.
pub fn get_rooms(&self) -> Vec<Room> {
self.store.get_rooms()
self.store.rooms()
}

/// Get all the rooms this client knows about, filtered by room state.
pub fn get_rooms_filtered(&self, filter: RoomStateFilter) -> Vec<Room> {
self.store.get_rooms_filtered(filter)
self.store.rooms_filtered(filter)
}

/// Lookup the Room for the given RoomId, or create one, if it didn't exist
Expand Down Expand Up @@ -637,7 +637,7 @@ impl BaseClient {

if let Some(room) = changes.room_infos.get_mut(room_id) {
room.base_info.dm_targets.insert(user_id.clone());
} else if let Some(room) = self.store.get_room(room_id) {
} else if let Some(room) = self.store.room(room_id) {
let mut info = room.clone_info();
if info.base_info.dm_targets.insert(user_id.clone()) {
changes.add_room(info);
Expand Down Expand Up @@ -1111,8 +1111,8 @@ impl BaseClient {
}

for (room_id, room_info) in &changes.room_infos {
if let Some(room) = self.store.get_room(room_id) {
room.set_room_info(room_info.clone(), trigger_room_list_update);
if let Some(room) = self.store.room(room_id) {
room.set_room_info(room_info.clone(), trigger_room_list_update)
}
}
}
Expand Down Expand Up @@ -1143,13 +1143,12 @@ impl BaseClient {
return Err(Error::InvalidReceiveMembersParameters);
}

let mut chunk = Vec::with_capacity(response.chunk.len());

let Some(room) = self.store.get_room(room_id) else {
let Some(room) = self.store.room(room_id) else {
// The room is unknown to us: leave early.
return Ok(());
};

let mut chunk = Vec::with_capacity(response.chunk.len());
let mut changes = StateChanges::default();

#[cfg(feature = "e2e-encryption")]
Expand Down Expand Up @@ -1309,7 +1308,7 @@ impl BaseClient {
///
/// * `room_id` - The id of the room that should be fetched.
pub fn get_room(&self, room_id: &RoomId) -> Option<Room> {
self.store.get_room(room_id)
self.store.room(room_id)
}

/// Get the olm machine.
Expand Down
6 changes: 3 additions & 3 deletions crates/matrix-sdk-base/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ impl Store {
}

/// Get all the rooms this store knows about.
pub fn get_rooms(&self) -> Vec<Room> {
pub fn rooms(&self) -> Vec<Room> {
self.rooms.read().unwrap().values().cloned().collect()
}

/// Get all the rooms this store knows about, filtered by state.
pub fn get_rooms_filtered(&self, filter: RoomStateFilter) -> Vec<Room> {
pub fn rooms_filtered(&self, filter: RoomStateFilter) -> Vec<Room> {
self.rooms
.read()
.unwrap()
Expand All @@ -219,7 +219,7 @@ impl Store {
}

/// Get the room with the given room id.
pub fn get_room(&self, room_id: &RoomId) -> Option<Room> {
pub fn room(&self, room_id: &RoomId) -> Option<Room> {
self.rooms.read().unwrap().get(room_id).cloned()
}

Expand Down

0 comments on commit 984b95b

Please sign in to comment.