Skip to content

Commit 648d527

Browse files
jmartinespHywan
authored andcommitted
fix(room_preview): Return room preview info based on local data for banned rooms too
Any remote endpoint would just return a `403` status code so we have no other choice than trusting the local room info we already have.
1 parent 8513547 commit 648d527

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

crates/matrix-sdk/src/client/mod.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -1155,16 +1155,20 @@ impl Client {
11551155
};
11561156

11571157
if let Some(room) = self.get_room(&room_id) {
1158-
// The cached data can only be trusted if the room is joined: for invite and
1159-
// knock rooms, no updates will be received for the rooms after the invite/knock
1160-
// action took place so we may have very out to date data for important fields
1161-
// such as `join_rule`
1162-
if room.state() == RoomState::Joined {
1163-
return Ok(RoomPreview::from_joined(&room).await);
1158+
// The cached data can only be trusted if the room state is joined or
1159+
// banned: for invite and knock rooms, no updates will be received
1160+
// for the rooms after the invite/knock action took place so we may
1161+
// have very out to date data for important fields such as
1162+
// `join_rule`. For left rooms, the homeserver should return the latest info.
1163+
match room.state() {
1164+
RoomState::Joined | RoomState::Banned => {
1165+
return Ok(RoomPreview::from_known_room(&room).await);
1166+
}
1167+
RoomState::Left | RoomState::Invited | RoomState::Knocked => {}
11641168
}
11651169
}
11661170

1167-
RoomPreview::from_not_joined(self, room_id, room_or_alias_id, via).await
1171+
RoomPreview::from_remote_room(self, room_id, room_or_alias_id, via).await
11681172
}
11691173

11701174
/// Resolve a room alias to a room id and a list of servers which know

crates/matrix-sdk/src/room_preview.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,12 @@ impl RoomPreview {
126126
}
127127
}
128128

129-
/// Create a room preview from a known room we've joined.
130-
pub(crate) async fn from_joined(room: &Room) -> Self {
129+
/// Create a room preview from a known room.
130+
///
131+
/// Note this shouldn't be used with invited or knocked rooms, since the
132+
/// local info may be out of date and no longer represent the latest room
133+
/// state.
134+
pub(crate) async fn from_known_room(room: &Room) -> Self {
131135
let is_direct = room.is_direct().await.ok();
132136

133137
let display_name = room.display_name().await.ok().map(|name| name.to_string());
@@ -143,7 +147,7 @@ impl RoomPreview {
143147
}
144148

145149
#[instrument(skip(client))]
146-
pub(crate) async fn from_not_joined(
150+
pub(crate) async fn from_remote_room(
147151
client: &Client,
148152
room_id: OwnedRoomId,
149153
room_or_alias_id: &RoomOrAliasId,

0 commit comments

Comments
 (0)