moved user status data validation from front to backend
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -122,6 +122,10 @@ pub fn on_friend_user_status(payload: Payload, _socket: RawClient) {
|
||||
if let Ok(data) =
|
||||
utils::extract_and_parse::<FriendUserStatusPayload>(payload, "friend-user-status")
|
||||
{
|
||||
if !data.status.has_presence_content() {
|
||||
return;
|
||||
}
|
||||
|
||||
emitter::emit_to_frontend_typed(&FriendUserStatusChanged(data));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user