crypto: Make it clearer that the deleted flag can only be set to true

master
Damir Jelić 2021-03-01 20:33:28 +01:00
parent 1799721a5f
commit 2e659afd26
1 changed files with 9 additions and 7 deletions

View File

@ -250,7 +250,7 @@ impl GroupSessionManager {
let user_devices = self.store.get_user_devices(&user_id).await?; let user_devices = self.store.get_user_devices(&user_id).await?;
// If no device got deleted or blacklisted until now and no user // If no device got deleted or blacklisted until now and no user
// left check if one got deleted or blacklisted for this user. // left, check if one got deleted or blacklisted for this user.
if !(device_got_deleted_or_blacklisted || user_left || visiblity_changed) { if !(device_got_deleted_or_blacklisted || user_left || visiblity_changed) {
// Devices that should receive this session // Devices that should receive this session
let device_ids: HashSet<&DeviceId> = user_devices let device_ids: HashSet<&DeviceId> = user_devices
@ -264,9 +264,7 @@ impl GroupSessionManager {
.map(|d| d.as_ref()) .map(|d| d.as_ref())
.collect(); .collect();
device_got_deleted_or_blacklisted = if let Some(shared) = if let Some(shared) = outbound.shared_with_set.get(user_id) {
outbound.shared_with_set.get(user_id)
{
#[allow(clippy::map_clone)] #[allow(clippy::map_clone)]
// Devices that received this session // Devices that received this session
let shared: HashSet<DeviceIdBox> = let shared: HashSet<DeviceIdBox> =
@ -276,12 +274,16 @@ impl GroupSessionManager {
// The difference between the devices that received the // The difference between the devices that received the
// session and devices that should receive the session are // session and devices that should receive the session are
// our deleted or newly blacklisted devices // our deleted or newly blacklisted devices
!shared //
// If the set isn't empty, a device got blacklisted or
// deleted, so remember it.
if !shared
.difference(&device_ids) .difference(&device_ids)
.collect::<HashSet<_>>() .collect::<HashSet<_>>()
.is_empty() .is_empty()
} else { {
false device_got_deleted_or_blacklisted = true;
}
}; };
} }