From b6db3af88284f3944838b98274b9dddbcb413e48 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Thu, 4 Apr 2024 17:23:20 +0200 Subject: [PATCH] room list service: always include the `m.room.create` state event in a room subscription --- .../src/room_list_service/room.rs | 18 ++++++++++++++++-- .../tests/integration/room_list_service.rs | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/matrix-sdk-ui/src/room_list_service/room.rs b/crates/matrix-sdk-ui/src/room_list_service/room.rs index 5113ec6a5..4a4162bdc 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/room.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/room.rs @@ -18,7 +18,7 @@ use std::{ops::Deref, sync::Arc}; use async_once_cell::OnceCell as AsyncOnceCell; use matrix_sdk::{event_cache, SlidingSync, SlidingSyncRoom}; -use ruma::{api::client::sync::sync_events::v4::RoomSubscription, RoomId}; +use ruma::{api::client::sync::sync_events::v4::RoomSubscription, events::StateEventType, RoomId}; use super::Error; use crate::{ @@ -98,7 +98,21 @@ impl Room { /// It means that all events from this room will be received every time, no /// matter how the `RoomList` is configured. pub fn subscribe(&self, settings: Option) { - self.inner.sliding_sync.subscribe_to_room(self.inner.room.room_id().to_owned(), settings) + let mut settings = settings.unwrap_or_default(); + + // Make sure to always include the room creation event in the required state + // events, to know what the room version is. + if !settings + .required_state + .iter() + .any(|(event_type, _state_key)| *event_type == StateEventType::RoomCreate) + { + settings.required_state.push((StateEventType::RoomCreate, "".to_owned())); + } + + self.inner + .sliding_sync + .subscribe_to_room(self.inner.room.room_id().to_owned(), Some(settings)) } /// Unsubscribe to this room. diff --git a/crates/matrix-sdk-ui/tests/integration/room_list_service.rs b/crates/matrix-sdk-ui/tests/integration/room_list_service.rs index f38be86a1..f3bcced29 100644 --- a/crates/matrix-sdk-ui/tests/integration/room_list_service.rs +++ b/crates/matrix-sdk-ui/tests/integration/room_list_service.rs @@ -2411,6 +2411,7 @@ async fn test_room_subscription() -> Result<(), Error> { ["m.room.topic", ""], ["m.room.avatar", ""], ["m.room.canonical_alias", ""], + ["m.room.create", ""], // Added even when it's not specified ], "timeline_limit": 30, },