Skip to content

Commit abf0bbb

Browse files
Hywanstefanceriu
authored andcommitted
fix(base): Use the room::display_name processor for sync v2.
This patch uses `room::display_name` and `changes::save_only` to compute the new display name for all rooms and save them, for sync v2 only.
1 parent c1d885f commit abf0bbb

File tree

2 files changed

+18
-30
lines changed

2 files changed

+18
-30
lines changed

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ impl BaseClient {
533533

534534
let push_rules = self.get_push_rules(&global_account_data_processor).await?;
535535

536-
let mut new_rooms = RoomUpdates::default();
536+
let mut room_updates = RoomUpdates::default();
537537
let mut notifications = Default::default();
538538

539539
let mut updated_members_in_room: BTreeMap<OwnedRoomId, BTreeSet<OwnedUserId>> =
@@ -564,7 +564,7 @@ impl BaseClient {
564564
)
565565
.await?;
566566

567-
new_rooms.joined.insert(room_id, joined_room_update);
567+
room_updates.joined.insert(room_id, joined_room_update);
568568
}
569569

570570
for (room_id, left_room) in response.rooms.leave {
@@ -591,7 +591,7 @@ impl BaseClient {
591591
)
592592
.await?;
593593

594-
new_rooms.left.insert(room_id, left_room_update);
594+
room_updates.left.insert(room_id, left_room_update);
595595
}
596596

597597
for (room_id, invited_room) in response.rooms.invite {
@@ -608,7 +608,7 @@ impl BaseClient {
608608
)
609609
.await?;
610610

611-
new_rooms.invited.insert(room_id, invited_room_update);
611+
room_updates.invited.insert(room_id, invited_room_update);
612612
}
613613

614614
for (room_id, knocked_room) in response.rooms.knock {
@@ -625,7 +625,7 @@ impl BaseClient {
625625
)
626626
.await?;
627627

628-
new_rooms.knocked.insert(room_id, knocked_room_update);
628+
room_updates.knocked.insert(room_id, knocked_room_update);
629629
}
630630

631631
global_account_data_processor.apply(&mut context, &self.state_store).await;
@@ -654,12 +654,19 @@ impl BaseClient {
654654
.await?;
655655
}
656656

657+
let mut context = Context::default();
658+
657659
// Now that all the rooms information have been saved, update the display name
658-
// cache (which relies on information stored in the database). This will
659-
// live in memory, until the next sync which will saves the room info to
660-
// disk; we do this to avoid saving that would be redundant with the
661-
// above. Oh well.
662-
new_rooms.update_in_memory_caches(&self.state_store).await;
660+
// of the updated rooms (which relies on information stored in the database).
661+
processors::room::display_name::update_for_rooms(
662+
&mut context,
663+
&room_updates,
664+
&self.state_store,
665+
)
666+
.await;
667+
668+
// Save the new display name updates if any.
669+
processors::changes::save_only(context, &self.state_store).await?;
663670

664671
for (room_id, member_ids) in updated_members_in_room {
665672
if let Some(room) = self.get_room(&room_id) {
@@ -673,7 +680,7 @@ impl BaseClient {
673680
}
674681

675682
let response = SyncResponse {
676-
rooms: new_rooms,
683+
rooms: room_updates,
677684
presence: response.presence.events,
678685
account_data: response.account_data.events,
679686
to_device,

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use serde::{Deserialize, Serialize};
3535
use crate::{
3636
debug::{DebugInvitedRoom, DebugKnockedRoom, DebugListOfRawEvents, DebugListOfRawEventsNoId},
3737
deserialized_responses::{AmbiguityChange, RawAnySyncOrStrippedTimelineEvent},
38-
store::BaseStateStore,
3938
};
4039

4140
/// Generalized representation of a `/sync` response.
@@ -81,24 +80,6 @@ pub struct RoomUpdates {
8180
pub knocked: BTreeMap<OwnedRoomId, KnockedRoomUpdate>,
8281
}
8382

84-
impl RoomUpdates {
85-
/// Update the caches for the rooms that received updates.
86-
///
87-
/// This will only fill the in-memory caches, not save the info on disk.
88-
pub(crate) async fn update_in_memory_caches(&self, store: &BaseStateStore) {
89-
for room in self
90-
.left
91-
.keys()
92-
.chain(self.joined.keys())
93-
.chain(self.invited.keys())
94-
.chain(self.knocked.keys())
95-
.filter_map(|room_id| store.room(room_id))
96-
{
97-
let _ = room.compute_display_name().await;
98-
}
99-
}
100-
}
101-
10283
#[cfg(not(tarpaulin_include))]
10384
impl fmt::Debug for RoomUpdates {
10485
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

0 commit comments

Comments
 (0)