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 matrix_sdk_common::timer;
16
17use super::super::Context;
18use crate::{
19    RoomInfoNotableUpdateReasons, room::UpdatedRoomDisplayName, store::BaseStateStore,
20    sync::RoomUpdates,
21};
22
23pub async fn update_for_rooms(
24    context: &mut Context,
25    room_updates: &RoomUpdates,
26    state_store: &BaseStateStore,
27) {
28    let _timer = timer!(tracing::Level::TRACE, "display_name::update_for_rooms");
29
30    for room in room_updates.iter_all_room_ids().filter_map(|room_id| state_store.room(room_id)) {
31        // Compute the display name. If it's different, let's register the `RoomInfo` in
32        // the `StateChanges`.
33        if let Ok(UpdatedRoomDisplayName::New(_)) = room.compute_display_name().await {
34            let room_id = room.room_id().to_owned();
35
36            context.state_changes.room_infos.insert(room_id.clone(), room.clone_info());
37            context
38                .room_info_notable_updates
39                .entry(room_id)
40                .or_default()
41                .insert(RoomInfoNotableUpdateReasons::DISPLAY_NAME);
42        }
43    }
44}