diff --git a/src-tauri/src/models/event_payloads.rs b/src-tauri/src/models/event_payloads.rs index 5762383..bedf1a3 100644 --- a/src-tauri/src/models/event_payloads.rs +++ b/src-tauri/src/models/event_payloads.rs @@ -19,6 +19,20 @@ pub struct UserStatusPayload { pub state: UserStatusState, } +impl UserStatusPayload { + pub fn has_presence_content(&self) -> bool { + self.presence_status + .title + .as_ref() + .is_some_and(|title| !title.trim().is_empty()) + || self + .presence_status + .subtitle + .as_ref() + .is_some_and(|subtitle| !subtitle.trim().is_empty()) + } +} + #[derive(Clone, Serialize, Deserialize, Debug, Type)] #[serde(rename_all = "camelCase")] pub struct FriendUserStatusPayload { diff --git a/src-tauri/src/services/ws/friend.rs b/src-tauri/src/services/ws/friend.rs index f865c23..e0eacc0 100644 --- a/src-tauri/src/services/ws/friend.rs +++ b/src-tauri/src/services/ws/friend.rs @@ -122,6 +122,10 @@ pub fn on_friend_user_status(payload: Payload, _socket: RawClient) { if let Ok(data) = utils::extract_and_parse::(payload, "friend-user-status") { + if !data.status.has_presence_content() { + return; + } + emitter::emit_to_frontend_typed(&FriendUserStatusChanged(data)); } } diff --git a/src-tauri/src/services/ws/user_status.rs b/src-tauri/src/services/ws/user_status.rs index 32a6360..dc25ceb 100644 --- a/src-tauri/src/services/ws/user_status.rs +++ b/src-tauri/src/services/ws/user_status.rs @@ -1,6 +1,6 @@ use once_cell::sync::Lazy; -use tauri_specta::Event as _; use tauri::async_runtime::{self, JoinHandle}; +use tauri_specta::Event as _; use tokio::sync::Mutex; use tokio::time::Duration; use tracing::warn; @@ -24,6 +24,10 @@ pub async fn report_user_status(status: UserStatusPayload) { handle.abort(); } + if !status.has_presence_content() { + return; + } + if let Err(e) = UserStatusChanged(status.clone()).emit(crate::get_app_handle()) { warn!("Failed to emit user-status-changed event: {e}"); } diff --git a/src/events/user-status.ts b/src/events/user-status.ts index 0ccd3cc..3fcc5f9 100644 --- a/src/events/user-status.ts +++ b/src/events/user-status.ts @@ -13,13 +13,6 @@ export const { start: startUserStatus, stop: stopUserStatus } = await events.friendUserStatusChanged.listen((event) => { const { userId, status } = event.payload; - const hasValidName = - (typeof status.presenceStatus.title === "string" && - status.presenceStatus.title.trim() !== "") || - (typeof status.presenceStatus.subtitle === "string" && - status.presenceStatus.subtitle.trim() !== ""); - if (!hasValidName) return; - friendsPresenceStates.update((current) => ({ ...current, [userId]: status,