room list service: always include the m.room.create state event in a room subscription

This commit is contained in:
Benjamin Bouvier
2024-04-04 17:23:20 +02:00
parent 8a8ad22961
commit b6db3af882
2 changed files with 17 additions and 2 deletions

View File

@@ -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<RoomSubscription>) {
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.

View File

@@ -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,
},