forked from jmug/stoatchat
fix: dont leak invisible presence to others
This commit is contained in:
@@ -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<crate::PartialUser> 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<Presence> for crate::Presence {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<crate::UserStatus> 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<UserStatus> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user