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 {
|
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 {
|
Ok(get_presence::v3::Response {
|
||||||
// TODO: Should ruma just use the presenceeventcontent type here?
|
// TODO: Should ruma just use the presenceeventcontent type here?
|
||||||
status_msg: presence.content.status_msg,
|
status_msg,
|
||||||
currently_active: presence.content.currently_active,
|
currently_active: presence.content.currently_active,
|
||||||
last_active_ago: presence
|
last_active_ago: presence
|
||||||
.content
|
.content
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use ruma::{events::presence::PresenceEvent, presence::PresenceState, OwnedUserId, UInt, UserId};
|
use ruma::{events::presence::PresenceEvent, presence::PresenceState, OwnedUserId, UInt, UserId};
|
||||||
use tracing::debug;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
database::KeyValueDatabase,
|
database::KeyValueDatabase,
|
||||||
|
debug_info,
|
||||||
service::{self, presence::Presence},
|
service::{self, presence::Presence},
|
||||||
services,
|
services,
|
||||||
utils::{self, user_id_from_bytes},
|
utils::{self, user_id_from_bytes},
|
||||||
|
@ -50,13 +50,21 @@ impl service::presence::Data for KeyValueDatabase {
|
||||||
|
|
||||||
// tighten for state flicker?
|
// tighten for state flicker?
|
||||||
if !state_changed && last_active_ts <= last_last_active_ts {
|
if !state_changed && last_active_ts <= last_last_active_ts {
|
||||||
debug!(
|
debug_info!(
|
||||||
"presence spam {:?} last_active_ts:{:?} <= {:?}",
|
"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(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let status_msg = if status_msg.as_ref().is_some_and(String::is_empty) {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
status_msg
|
||||||
|
};
|
||||||
|
|
||||||
let presence = Presence::new(
|
let presence = Presence::new(
|
||||||
presence_state.to_owned(),
|
presence_state.to_owned(),
|
||||||
currently_active.unwrap_or(false),
|
currently_active.unwrap_or(false),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue