atagen

matrix-rust-sdk

public
Star0
Watch0

Commit 9467d8fde596

tarball

atagen <boss@atagen.co>2026-10-22 12:30 UTC

2 files changed+40-2
room_list_service: let callers request extra required state
Modified file: crates/matrix-sdk-ui/src/room_list_service/mod.rs+21 additions−1 deletions
@@ -129,6 +129,10 @@ pub struct RoomListService {
129129 ///
130130 /// `RoomListService` is a simple state-machine.
131131 state_machine: StateMachine,
132+
133+ /// State events requested on top of [`DEFAULT_REQUIRED_STATE`], for the
134+ /// list and for room subscriptions alike.
135+ extra_required_state: Vec<(StateEventType, String)>,
132136 }
133137
134138 impl RoomListService {
@@ -158,6 +162,20 @@ impl RoomListService {
158162 connection_id: &str,
159163 timeline_limit: u32,
160164 ) -> Result<Self, Error> {
165+ Self::new_with_required_state(client, share_pos, connection_id, timeline_limit, Vec::new())
166+ .await
167+ }
168+
169+ /// Like [`RoomListService::new_with`], also requesting
170+ /// `extra_required_state` for every room in the list and every room
171+ /// subscription, on top of the defaults.
172+ pub async fn new_with_required_state(
173+ client: Client,
174+ share_pos: bool,
175+ connection_id: &str,
176+ timeline_limit: u32,
177+ extra_required_state: Vec<(StateEventType, String)>,
178+ ) -> Result<Self, Error> {
161179 let mut builder = client
162180 .sliding_sync(connection_id)
163181 .map_err(Error::SlidingSync)?
@@ -222,6 +240,7 @@ impl RoomListService {
222240 DEFAULT_REQUIRED_STATE
223241 .iter()
224242 .map(|(state_event, value)| (state_event.clone(), (*value).to_owned()))
243+ .chain(extra_required_state.iter().cloned())
225244 .collect(),
226245 )
227246 .filters(Some(assign!(http::request::ListFilters::default(), {
@@ -265,7 +284,7 @@ impl RoomListService {
265284 // Eagerly subscribe the event cache to sync responses.
266285 client.event_cache().subscribe()?;
267286
268- Ok(Self { client, sliding_sync, state_machine })
287+ Ok(Self { client, sliding_sync, state_machine, extra_required_state })
269288 }
270289
271290 /// Start to sync the room list.
@@ -489,6 +508,7 @@ impl RoomListService {
489508 (state_event.clone(), (*value).to_owned())
490509 })
491510 )
511+ .chain(self.extra_required_state.iter().cloned())
492512 .collect(),
493513 timeline_limit: UInt::from(DEFAULT_ROOM_SUBSCRIPTION_TIMELINE_LIMIT),
494514 });
Modified file: crates/matrix-sdk-ui/src/sync_service.rs+19 additions−1 deletions
@@ -36,6 +36,7 @@ use matrix_sdk::{
3636 Client,
3737 config::RequestConfig,
3838 executor::{JoinHandle, spawn},
39+ ruma::events::StateEventType,
3940 sleep::sleep,
4041 };
4142 use thiserror::Error;
@@ -785,6 +786,9 @@ pub struct SyncServiceBuilder {
785786 /// [`room_list_service::DEFAULT_LIST_TIMELINE_LIMIT`].
786787 room_list_timeline_limit: u32,
787788
789+ /// State events the room list service requests on top of its defaults.
790+ room_list_extra_required_state: Vec<(StateEventType, String)>,
791+
788792 /// The parent tracing span to use for the tasks within this service.
789793 ///
790794 /// Normally this will be [`Span::none`], but it may be useful to assign a
@@ -801,6 +805,7 @@ impl SyncServiceBuilder {
801805 with_share_pos: true,
802806 room_list_conn_id: DEFAULT_CONNECTION_ID.to_owned(),
803807 room_list_timeline_limit: DEFAULT_LIST_TIMELINE_LIMIT,
808+ room_list_extra_required_state: Vec::new(),
804809 parent_span: Span::none(),
805810 }
806811 }
@@ -834,6 +839,17 @@ impl SyncServiceBuilder {
834839 self
835840 }
836841
842+ /// Request these state events for every room the room list service
843+ /// syncs, on top of its defaults. Use it for state the sdk doesn't know
844+ /// about, so it lands in the state store like the rest.
845+ pub fn with_room_list_extra_required_state(
846+ mut self,
847+ required_state: Vec<(StateEventType, String)>,
848+ ) -> Self {
849+ self.room_list_extra_required_state = required_state;
850+ self
851+ }
852+
837853 /// Set the parent tracing span to be used for the tasks within this
838854 /// service.
839855 pub fn with_parent_span(mut self, parent_span: Span) -> Self {
@@ -853,16 +869,18 @@ impl SyncServiceBuilder {
853869 with_share_pos,
854870 room_list_conn_id,
855871 room_list_timeline_limit,
872+ room_list_extra_required_state,
856873 parent_span,
857874 } = self;
858875
859876 let encryption_sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new()));
860877
861- let room_list = RoomListService::new_with(
878+ let room_list = RoomListService::new_with_required_state(
862879 client.clone(),
863880 with_share_pos,
864881 &room_list_conn_id,
865882 room_list_timeline_limit,
883+ room_list_extra_required_state,
866884 )
867885 .await?;