diff --git a/src/database/entities/user.rs b/src/database/entities/user.rs index 26f6b77bbc8503e527069314de97afcfdaf5cc7b..ff69e933e3d0ccf9a74ab5df92bc966a1748da6f 100644 --- a/src/database/entities/user.rs +++ b/src/database/entities/user.rs @@ -43,6 +43,7 @@ impl User { return self; } + self.relations = None; if let Some(relations) = &user.relations { if let Some(relationship) = relations.iter().find(|x| self.id == x.id) { self.relationship = Some(relationship.status.clone()); @@ -55,10 +56,6 @@ impl User { /// Mutate the user object to appear as seen by user. pub fn with(mut self, permissions: UserPermissions<[u32; 1]>) -> User { - if !permissions.get_view_all() { - self.relations = None; - } - if permissions.get_view_profile() { self.online = Some(is_online(&self.id)); } diff --git a/src/database/permissions/user.rs b/src/database/permissions/user.rs index 1941453e00ea8eb734153cb37a0cce11e888adc0..07aa09379c997e815c97e52486b0fb9ad8a0aeb0 100644 --- a/src/database/permissions/user.rs +++ b/src/database/permissions/user.rs @@ -14,8 +14,6 @@ pub enum UserPermission { ViewProfile = 2, SendMessage = 4, Invite = 8, - - ViewAll = 2147483648, } bitfield! { @@ -25,13 +23,9 @@ bitfield! { pub get_view_profile, _: 30; pub get_send_message, _: 29; pub get_invite, _: 28; - - pub get_view_all, _: 0; } impl_op_ex!(+ |a: &UserPermission, b: &UserPermission| -> u32 { *a as u32 | *b as u32 }); -impl_op_ex!(-|a: &UserPermission, b: &UserPermission| -> u32 { *a as u32 & !(*b as u32) }); -impl_op_ex!(-|a: &u32, b: &UserPermission| -> u32 { *a & !(*b as u32) }); impl_op_ex_commutative!(+ |a: &u32, b: &UserPermission| -> u32 { *a | *b as u32 }); pub fn get_relationship(a: &User, b: &str) -> RelationshipStatus { @@ -56,7 +50,7 @@ impl<'a> PermissionCalculator<'a> { let mut permissions: u32 = 0; match get_relationship(&self.perspective, &target) { - RelationshipStatus::Friend => return Ok(u32::MAX - UserPermission::ViewAll), + RelationshipStatus::Friend => return Ok(u32::MAX), RelationshipStatus::Blocked | RelationshipStatus::BlockedOther => { return Ok(UserPermission::Access as u32) } @@ -74,7 +68,10 @@ impl<'a> PermissionCalculator<'a> { || get_collection("channels") .find_one( doc! { - "type": "Group", + "$or": [ + { "type": "Group" }, + { "type": "DirectMessage" }, + ], "$and": { "recipients": &self.perspective.id, "recipients": target