base: Respect the history visiblity setting when sharing group sessions

master
Damir Jelić 2021-02-03 13:56:31 +01:00
parent bdaed6237e
commit 347f79d08c
3 changed files with 37 additions and 3 deletions

View File

@ -31,7 +31,10 @@ use matrix_sdk_common::{
},
events::{
presence::PresenceEvent,
room::member::{MemberEventContent, MembershipState},
room::{
history_visibility::HistoryVisibility,
member::{MemberEventContent, MembershipState},
},
AnyBasicEvent, AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent,
AnyToDeviceEvent, EventContent, StateEvent,
},
@ -1154,9 +1157,21 @@ impl BaseClient {
match &*olm {
Some(o) => {
let history_visiblity = self
.get_room(room_id)
.map(|r| r.history_visiblity())
.unwrap_or(HistoryVisibility::Joined);
let joined = self.store.get_joined_user_ids(room_id).await?;
let invited = self.store.get_invited_user_ids(room_id).await?;
let members = joined.iter().chain(&invited);
// Don't share the group session with members that are invited
// if the history visiblity is set to `Joined`
let members = if history_visiblity == HistoryVisibility::Joined {
joined.iter().chain(&[])
} else {
joined.iter().chain(&invited)
};
Ok(
o.share_group_session(room_id, members, EncryptionSettings::default())
.await?,

View File

@ -80,6 +80,15 @@ impl RoomState {
}
}
/// Get the history visiblity policy of this room.
pub fn history_visiblity(&self) -> HistoryVisibility {
match self {
RoomState::Joined(r) => r.inner.history_visibility(),
RoomState::Left(r) => r.inner.history_visibility(),
RoomState::Invited(r) => r.inner.history_visibility(),
}
}
/// Are the members for this room synced.
pub fn are_members_synced(&self) -> bool {
if let RoomState::Joined(r) = self {

View File

@ -15,7 +15,7 @@
use std::sync::{Arc, Mutex as SyncMutex};
use matrix_sdk_common::{
events::AnyStrippedStateEvent,
events::{room::history_visibility::HistoryVisibility, AnyStrippedStateEvent},
identifiers::{RoomId, UserId},
};
use serde::{Deserialize, Serialize};
@ -96,6 +96,16 @@ impl StrippedRoom {
self.inner.lock().unwrap().base_info.encryption.is_some()
}
/// Get the history visiblity policy of this room.
pub fn history_visibility(&self) -> HistoryVisibility {
self.inner
.lock()
.unwrap()
.base_info
.history_visibility
.clone()
}
/// Calculate the canonical display name of the room, taking into account
/// its name, aliases and members.
///