presence: set empty string status msg to None
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
b5c0c30a5e
commit
f8e1255994
2 changed files with 23 additions and 4 deletions
|
@ -49,9 +49,20 @@ pub(crate) async fn get_presence_route(body: Ruma<get_presence::v3::Request>) ->
|
|||
}
|
||||
|
||||
if let Some(presence) = presence_event {
|
||||
let status_msg = if presence
|
||||
.content
|
||||
.status_msg
|
||||
.as_ref()
|
||||
.is_some_and(String::is_empty)
|
||||
{
|
||||
None
|
||||
} else {
|
||||
presence.content.status_msg
|
||||
};
|
||||
|
||||
Ok(get_presence::v3::Response {
|
||||
// TODO: Should ruma just use the presenceeventcontent type here?
|
||||
status_msg: presence.content.status_msg,
|
||||
status_msg,
|
||||
currently_active: presence.content.currently_active,
|
||||
last_active_ago: presence
|
||||
.content
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use ruma::{events::presence::PresenceEvent, presence::PresenceState, OwnedUserId, UInt, UserId};
|
||||
use tracing::debug;
|
||||
|
||||
use crate::{
|
||||
database::KeyValueDatabase,
|
||||
debug_info,
|
||||
service::{self, presence::Presence},
|
||||
services,
|
||||
utils::{self, user_id_from_bytes},
|
||||
|
@ -50,13 +50,21 @@ impl service::presence::Data for KeyValueDatabase {
|
|||
|
||||
// tighten for state flicker?
|
||||
if !state_changed && last_active_ts <= last_last_active_ts {
|
||||
debug!(
|
||||
debug_info!(
|
||||
"presence spam {:?} last_active_ts:{:?} <= {:?}",
|
||||
user_id, last_active_ts, last_last_active_ts
|
||||
user_id,
|
||||
last_active_ts,
|
||||
last_last_active_ts
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let status_msg = if status_msg.as_ref().is_some_and(String::is_empty) {
|
||||
None
|
||||
} else {
|
||||
status_msg
|
||||
};
|
||||
|
||||
let presence = Presence::new(
|
||||
presence_state.to_owned(),
|
||||
currently_active.unwrap_or(false),
|
||||
|
|
Loading…
Add table
Reference in a new issue