From f4281c70504bed1e0e07a5730c1c2548a089de17 Mon Sep 17 00:00:00 2001 From: Zomatree Date: Tue, 22 Apr 2025 18:54:26 +0100 Subject: [PATCH] fix: dont leak invisible presence to others --- crates/core/database/src/util/bridge/v0.rs | 34 +++++++++++++++------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/crates/core/database/src/util/bridge/v0.rs b/crates/core/database/src/util/bridge/v0.rs index c047b03d..776d21fe 100644 --- a/crates/core/database/src/util/bridge/v0.rs +++ b/crates/core/database/src/util/bridge/v0.rs @@ -1023,7 +1023,7 @@ impl crate::User { }) ), status: if can_see_profile { - self.status.map(|status| status.into()) + self.status.and_then(|status| status.into(true)) } else { None }, @@ -1085,7 +1085,7 @@ impl crate::User { }) ), status: if can_see_profile { - self.status.map(|status| status.into()) + self.status.and_then(|status| status.into(true)) } else { None }, @@ -1098,7 +1098,7 @@ impl crate::User { } /// Convert user object into user model without presence information - pub fn into_known_static<'a>(self, is_online: bool) -> User { + pub fn into_known_static(self, is_online: bool) -> User { User { username: self.username, discriminator: self.discriminator, @@ -1114,7 +1114,7 @@ impl crate::User { .. }) ), - status: self.status.map(|status| status.into()), + status: self.status.and_then(|status| status.into(true)), flags: self.flags.unwrap_or_default() as u32, privileged: self.privileged, bot: self.bot.map(|bot| bot.into()), @@ -1147,7 +1147,7 @@ impl crate::User { .. }) ), - status: self.status.map(|status| status.into()), + status: self.status.and_then(|status| status.into(true)), flags: self.flags.unwrap_or_default() as u32, privileged: self.privileged, bot: self.bot.map(|bot| bot.into()), @@ -1198,7 +1198,7 @@ impl From for PartialUser { .collect() }), badges: value.badges.map(|badges| badges as u32), - status: value.status.map(|status| status.into()), + status: value.status.and_then(|status| status.into(false)), flags: value.flags.map(|flags| flags as u32), privileged: value.privileged, bot: value.bot.map(|bot| bot.into()), @@ -1287,11 +1287,23 @@ impl From for crate::Presence { } } -impl From for UserStatus { - fn from(value: crate::UserStatus) -> Self { - UserStatus { - text: value.text, - presence: value.presence.map(|presence| presence.into()), +impl crate::UserStatus { + fn into(self, discard_invisible: bool) -> Option { + let status = UserStatus { + text: self.text, + presence: self.presence.and_then(|presence| { + if discard_invisible && presence == crate::Presence::Invisible { + None + } else { + Some(presence.into()) + } + }), + }; + + if status.text.is_none() && status.presence.is_none() { + None + } else { + Some(status) } } }