Skip to content

Commit 35e5cca

Browse files
Hywanstefanceriu
authored andcommitted
fix(base): room::display_name emits a RoomInfoNotableUpdateReasons::DISPLAY_NAME.
This patch updates the `room::display_name` response processor to emits a `RoomInfoNotableUpdateReasons::DISPLAY_NAME`.
1 parent 80a7aad commit 35e5cca

File tree

3 files changed

+57
-8
lines changed

3 files changed

+57
-8
lines changed

crates/matrix-sdk-base/src/response_processors/room/display_name.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
// limitations under the License.
1414

1515
use super::super::Context;
16-
use crate::{rooms::UpdatedRoomDisplayName, store::BaseStateStore, sync::RoomUpdates};
16+
use crate::{
17+
rooms::UpdatedRoomDisplayName, store::BaseStateStore, sync::RoomUpdates,
18+
RoomInfoNotableUpdateReasons,
19+
};
1720

1821
pub async fn update_for_rooms(
1922
context: &mut Context,
@@ -31,7 +34,14 @@ pub async fn update_for_rooms(
3134
// Compute the display name. If it's different, let's register the `RoomInfo` in
3235
// the `StateChanges`.
3336
if let Ok(UpdatedRoomDisplayName::New(_)) = room.compute_display_name().await {
34-
context.state_changes.room_infos.insert(room.room_id().to_owned(), room.clone_info());
37+
let room_id = room.room_id().to_owned();
38+
39+
context.state_changes.room_infos.insert(room_id.clone(), room.clone_info());
40+
context
41+
.room_info_notable_updates
42+
.entry(room_id)
43+
.or_default()
44+
.insert(RoomInfoNotableUpdateReasons::DISPLAY_NAME);
3545
}
3646
}
3747
}

crates/matrix-sdk-base/src/rooms/normal.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ bitflags! {
113113

114114
/// A membership change happened for the current user.
115115
const MEMBERSHIP = 0b0001_0000;
116+
117+
/// The display name has changed.
118+
const DISPLAY_NAME = 0b0010_0000;
119+
}
120+
}
121+
122+
impl Default for RoomInfoNotableUpdateReasons {
123+
fn default() -> Self {
124+
Self::empty()
116125
}
117126
}
118127

@@ -133,12 +142,6 @@ struct ComputedSummary {
133142
num_joined_invited_guess: u64,
134143
}
135144

136-
impl Default for RoomInfoNotableUpdateReasons {
137-
fn default() -> Self {
138-
Self::empty()
139-
}
140-
}
141-
142145
/// The underlying room data structure collecting state for joined, left and
143146
/// invited rooms.
144147
#[derive(Debug, Clone)]

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,42 @@ mod tests {
10891089
assert!(client_room.name().is_none());
10901090
}
10911091

1092+
#[async_test]
1093+
async fn test_display_name_is_cached_and_emits_a_notable_update_reason() {
1094+
let client = logged_in_base_client(None).await;
1095+
let user_id = user_id!("@u:e.uk");
1096+
let room_id = room_id!("!r:e.uk");
1097+
1098+
let mut room_info_notable_update = client.room_info_notable_update_receiver();
1099+
1100+
let room = room_with_name("Hello World", user_id);
1101+
let response = response_with_room(room_id, room);
1102+
client
1103+
.process_sliding_sync(&response, &(), &RequestedRequiredStates::default())
1104+
.await
1105+
.expect("Failed to process sync");
1106+
1107+
let room = client.get_room(room_id).expect("No room found");
1108+
assert_eq!(room.cached_display_name().unwrap().to_string(), "Hello World");
1109+
1110+
assert_matches!(
1111+
room_info_notable_update.recv().await,
1112+
Ok(RoomInfoNotableUpdate { room_id: received_room_id, reasons }) => {
1113+
assert_eq!(received_room_id, room_id);
1114+
// Not the reason we are looking for.
1115+
assert!(!reasons.contains(RoomInfoNotableUpdateReasons::DISPLAY_NAME));
1116+
}
1117+
);
1118+
assert_matches!(
1119+
room_info_notable_update.recv().await,
1120+
Ok(RoomInfoNotableUpdate { room_id: received_room_id, reasons }) => {
1121+
assert_eq!(received_room_id, room_id);
1122+
// The reason we are looking for :-].
1123+
assert!(reasons.contains(RoomInfoNotableUpdateReasons::DISPLAY_NAME));
1124+
}
1125+
);
1126+
}
1127+
10921128
#[async_test]
10931129
async fn test_display_name_is_persisted_from_sliding_sync() {
10941130
let user_id = user_id!("@u:e.uk");

0 commit comments

Comments
 (0)