matrix_sdk_base/response_processors/room/display_name.rs
1// Copyright 2025 The Matrix.org Foundation C.I.C.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use super::super::Context;
16use crate::{
17 room::UpdatedRoomDisplayName, store::BaseStateStore, sync::RoomUpdates,
18 RoomInfoNotableUpdateReasons,
19};
20
21pub async fn update_for_rooms(
22 context: &mut Context,
23 room_updates: &RoomUpdates,
24 state_store: &BaseStateStore,
25) {
26 for room in room_updates.iter_all_room_ids().filter_map(|room_id| state_store.room(room_id)) {
27 // Compute the display name. If it's different, let's register the `RoomInfo` in
28 // the `StateChanges`.
29 if let Ok(UpdatedRoomDisplayName::New(_)) = room.compute_display_name().await {
30 let room_id = room.room_id().to_owned();
31
32 context.state_changes.room_infos.insert(room_id.clone(), room.clone_info());
33 context
34 .room_info_notable_updates
35 .entry(room_id)
36 .or_default()
37 .insert(RoomInfoNotableUpdateReasons::DISPLAY_NAME);
38 }
39 }
40}