diff --git a/crates/matrix-sdk-base/src/client.rs b/crates/matrix-sdk-base/src/client.rs index 982768ff2..49a345d06 100644 --- a/crates/matrix-sdk-base/src/client.rs +++ b/crates/matrix-sdk-base/src/client.rs @@ -57,8 +57,8 @@ use crate::{ event_cache::store::EventCacheStoreLock, response_processors::{self as processors, Context}, rooms::{ - normal::{RoomInfoNotableUpdate, RoomInfoNotableUpdateReasons, RoomMembersUpdate}, - Room, RoomState, + normal::RoomMembersUpdate, Room, RoomInfoNotableUpdate, RoomInfoNotableUpdateReasons, + RoomState, }, store::{ ambiguity_map::AmbiguityCache, BaseStateStore, DynStateStore, MemoryStore, diff --git a/crates/matrix-sdk-base/src/response_processors/latest_event.rs b/crates/matrix-sdk-base/src/response_processors/latest_event.rs index 475d45cbc..f45c2157b 100644 --- a/crates/matrix-sdk-base/src/response_processors/latest_event.rs +++ b/crates/matrix-sdk-base/src/response_processors/latest_event.rs @@ -144,7 +144,7 @@ mod tests { use ruma::{event_id, events::room::member::MembershipState, room_id, user_id}; use super::{decrypt_from_rooms, Context, E2EE}; - use crate::{rooms::normal::RoomInfoNotableUpdateReasons, test_utils::logged_in_base_client}; + use crate::{rooms::RoomInfoNotableUpdateReasons, test_utils::logged_in_base_client}; #[async_test] async fn test_when_there_are_no_latest_encrypted_events_decrypting_them_does_nothing() { diff --git a/crates/matrix-sdk-base/src/rooms/mod.rs b/crates/matrix-sdk-base/src/rooms/mod.rs index 51ddb4475..f052e41a4 100644 --- a/crates/matrix-sdk-base/src/rooms/mod.rs +++ b/crates/matrix-sdk-base/src/rooms/mod.rs @@ -22,13 +22,12 @@ use std::{fmt, hash::Hash}; use bitflags::bitflags; pub use members::RoomMember; -pub use normal::{ - EncryptionState, Room, RoomHero, RoomInfoNotableUpdate, RoomInfoNotableUpdateReasons, - RoomMembersUpdate, RoomState, RoomStateFilter, -}; +pub use normal::{EncryptionState, Room, RoomHero, RoomMembersUpdate, RoomState, RoomStateFilter}; use regex::Regex; pub(crate) use room_info::SyncInfo; -pub use room_info::{apply_redaction, BaseRoomInfo, RoomInfo}; +pub use room_info::{ + apply_redaction, BaseRoomInfo, RoomInfo, RoomInfoNotableUpdate, RoomInfoNotableUpdateReasons, +}; use ruma::{ assign, events::{ diff --git a/crates/matrix-sdk-base/src/rooms/normal.rs b/crates/matrix-sdk-base/src/rooms/normal.rs index e0a500cef..d49f8349f 100644 --- a/crates/matrix-sdk-base/src/rooms/normal.rs +++ b/crates/matrix-sdk-base/src/rooms/normal.rs @@ -56,7 +56,8 @@ use tracing::{debug, info, instrument, trace, warn}; use super::{ members::MemberRoomInfo, RoomCreateWithCreatorEventContent, RoomDisplayName, RoomInfo, - RoomMember, RoomNotableTags, SyncInfo, UpdatedRoomDisplayName, + RoomInfoNotableUpdate, RoomInfoNotableUpdateReasons, RoomMember, RoomNotableTags, SyncInfo, + UpdatedRoomDisplayName, }; use crate::{ deserialized_responses::{DisplayName, MemberEvent, RawMemberEvent, SyncOrStrippedState}, @@ -68,66 +69,6 @@ use crate::{ Error, MinimalStateEvent, RoomMemberships, StateStoreDataKey, StateStoreDataValue, StoreError, }; -/// Indicates that a notable update of `RoomInfo` has been applied, and why. -/// -/// A room info notable update is an update that can be interested for other -/// parts of the code. This mechanism is used in coordination with -/// [`BaseClient::room_info_notable_update_receiver`][baseclient] (and -/// `Room::inner` plus `Room::room_info_notable_update_sender`) where `RoomInfo` -/// can be observed and some of its updates can be spread to listeners. -/// -/// [baseclient]: crate::BaseClient::room_info_notable_update_receiver -#[derive(Debug, Clone)] -pub struct RoomInfoNotableUpdate { - /// The room which was updated. - pub room_id: OwnedRoomId, - - /// The reason for this update. - pub reasons: RoomInfoNotableUpdateReasons, -} - -bitflags! { - /// The reason why a [`RoomInfoNotableUpdate`] is emitted. - #[derive(Clone, Copy, Debug, Eq, PartialEq)] - pub struct RoomInfoNotableUpdateReasons: u8 { - /// The recency stamp of the `Room` has changed. - const RECENCY_STAMP = 0b0000_0001; - - /// The latest event of the `Room` has changed. - const LATEST_EVENT = 0b0000_0010; - - /// A read receipt has changed. - const READ_RECEIPT = 0b0000_0100; - - /// The user-controlled unread marker value has changed. - const UNREAD_MARKER = 0b0000_1000; - - /// A membership change happened for the current user. - const MEMBERSHIP = 0b0001_0000; - - /// The display name has changed. - const DISPLAY_NAME = 0b0010_0000; - - /// This is a temporary hack. - /// - /// So here is the thing. Ideally, we DO NOT want to emit this reason. It does not - /// makes sense. However, all notable update reasons are not clearly identified - /// so far. Why is it a problem? The `matrix_sdk_ui::room_list_service::RoomList` - /// is listening this stream of [`RoomInfoNotableUpdate`], and emits an update on a - /// room item if it receives a notable reason. Because all reasons are not - /// identified, we are likely to miss particular updates, and it can feel broken. - /// Ultimately, we want to clearly identify all the notable update reasons, and - /// remove this one. - const NONE = 0b1000_0000; - } -} - -impl Default for RoomInfoNotableUpdateReasons { - fn default() -> Self { - Self::empty() - } -} - /// The result of a room summary computation. /// /// If the homeserver does not provide a room summary, we perform a best-effort diff --git a/crates/matrix-sdk-base/src/rooms/room_info.rs b/crates/matrix-sdk-base/src/rooms/room_info.rs index c5f52d642..106f0ba9a 100644 --- a/crates/matrix-sdk-base/src/rooms/room_info.rs +++ b/crates/matrix-sdk-base/src/rooms/room_info.rs @@ -17,6 +17,7 @@ use std::{ sync::{atomic::AtomicBool, Arc}, }; +use bitflags::bitflags; use matrix_sdk_common::deserialized_responses::TimelineEventKind; use ruma::{ api::client::sync::sync_events::v3::RoomSummary as RumaSummary, @@ -1053,3 +1054,63 @@ pub fn apply_redaction( let raw = Raw::new(&event_json).expect("CanonicalJsonObject must be serializable"); Some(raw.cast()) } + +/// Indicates that a notable update of `RoomInfo` has been applied, and why. +/// +/// A room info notable update is an update that can be interested for other +/// parts of the code. This mechanism is used in coordination with +/// [`BaseClient::room_info_notable_update_receiver`][baseclient] (and +/// `Room::inner` plus `Room::room_info_notable_update_sender`) where `RoomInfo` +/// can be observed and some of its updates can be spread to listeners. +/// +/// [baseclient]: crate::BaseClient::room_info_notable_update_receiver +#[derive(Debug, Clone)] +pub struct RoomInfoNotableUpdate { + /// The room which was updated. + pub room_id: OwnedRoomId, + + /// The reason for this update. + pub reasons: RoomInfoNotableUpdateReasons, +} + +bitflags! { + /// The reason why a [`RoomInfoNotableUpdate`] is emitted. + #[derive(Clone, Copy, Debug, Eq, PartialEq)] + pub struct RoomInfoNotableUpdateReasons: u8 { + /// The recency stamp of the `Room` has changed. + const RECENCY_STAMP = 0b0000_0001; + + /// The latest event of the `Room` has changed. + const LATEST_EVENT = 0b0000_0010; + + /// A read receipt has changed. + const READ_RECEIPT = 0b0000_0100; + + /// The user-controlled unread marker value has changed. + const UNREAD_MARKER = 0b0000_1000; + + /// A membership change happened for the current user. + const MEMBERSHIP = 0b0001_0000; + + /// The display name has changed. + const DISPLAY_NAME = 0b0010_0000; + + /// This is a temporary hack. + /// + /// So here is the thing. Ideally, we DO NOT want to emit this reason. It does not + /// makes sense. However, all notable update reasons are not clearly identified + /// so far. Why is it a problem? The `matrix_sdk_ui::room_list_service::RoomList` + /// is listening this stream of [`RoomInfoNotableUpdate`], and emits an update on a + /// room item if it receives a notable reason. Because all reasons are not + /// identified, we are likely to miss particular updates, and it can feel broken. + /// Ultimately, we want to clearly identify all the notable update reasons, and + /// remove this one. + const NONE = 0b1000_0000; + } +} + +impl Default for RoomInfoNotableUpdateReasons { + fn default() -> Self { + Self::empty() + } +} diff --git a/crates/matrix-sdk-base/src/sliding_sync.rs b/crates/matrix-sdk-base/src/sliding_sync.rs index 18c3fd69b..09886fdce 100644 --- a/crates/matrix-sdk-base/src/sliding_sync.rs +++ b/crates/matrix-sdk-base/src/sliding_sync.rs @@ -25,7 +25,7 @@ use crate::{ error::Result, read_receipts::compute_unread_counts, response_processors as processors, - rooms::normal::RoomInfoNotableUpdateReasons, + rooms::RoomInfoNotableUpdateReasons, store::ambiguity_map::AmbiguityCache, sync::{RoomUpdates, SyncResponse}, RequestedRequiredStates, @@ -348,7 +348,7 @@ mod tests { #[cfg(feature = "e2e-encryption")] use super::processors::room::msc4186::cache_latest_events; use crate::{ - rooms::normal::{RoomHero, RoomInfoNotableUpdateReasons}, + rooms::{normal::RoomHero, RoomInfoNotableUpdateReasons}, store::{RoomLoadSettings, StoreConfig}, test_utils::logged_in_base_client, BaseClient, EncryptionState, RequestedRequiredStates, RoomInfoNotableUpdate, RoomState, diff --git a/crates/matrix-sdk-base/src/store/mod.rs b/crates/matrix-sdk-base/src/store/mod.rs index df1c867bd..d12085d83 100644 --- a/crates/matrix-sdk-base/src/store/mod.rs +++ b/crates/matrix-sdk-base/src/store/mod.rs @@ -60,7 +60,7 @@ use tracing::warn; use crate::{ deserialized_responses::DisplayName, event_cache::store as event_cache_store, - rooms::{normal::RoomInfoNotableUpdate, RoomInfo, RoomState}, + rooms::{RoomInfo, RoomInfoNotableUpdate, RoomState}, MinimalRoomMemberEvent, Room, RoomStateFilter, SessionMeta, };