moved user status data validation from front to backend
This commit is contained in:
@@ -19,6 +19,20 @@ pub struct UserStatusPayload {
|
|||||||
pub state: UserStatusState,
|
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)]
|
#[derive(Clone, Serialize, Deserialize, Debug, Type)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct FriendUserStatusPayload {
|
pub struct FriendUserStatusPayload {
|
||||||
|
|||||||
@@ -122,6 +122,10 @@ pub fn on_friend_user_status(payload: Payload, _socket: RawClient) {
|
|||||||
if let Ok(data) =
|
if let Ok(data) =
|
||||||
utils::extract_and_parse::<FriendUserStatusPayload>(payload, "friend-user-status")
|
utils::extract_and_parse::<FriendUserStatusPayload>(payload, "friend-user-status")
|
||||||
{
|
{
|
||||||
|
if !data.status.has_presence_content() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
emitter::emit_to_frontend_typed(&FriendUserStatusChanged(data));
|
emitter::emit_to_frontend_typed(&FriendUserStatusChanged(data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use tauri_specta::Event as _;
|
|
||||||
use tauri::async_runtime::{self, JoinHandle};
|
use tauri::async_runtime::{self, JoinHandle};
|
||||||
|
use tauri_specta::Event as _;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use tokio::time::Duration;
|
use tokio::time::Duration;
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
@@ -24,6 +24,10 @@ pub async fn report_user_status(status: UserStatusPayload) {
|
|||||||
handle.abort();
|
handle.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !status.has_presence_content() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if let Err(e) = UserStatusChanged(status.clone()).emit(crate::get_app_handle()) {
|
if let Err(e) = UserStatusChanged(status.clone()).emit(crate::get_app_handle()) {
|
||||||
warn!("Failed to emit user-status-changed event: {e}");
|
warn!("Failed to emit user-status-changed event: {e}");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,13 +13,6 @@ export const { start: startUserStatus, stop: stopUserStatus } =
|
|||||||
await events.friendUserStatusChanged.listen((event) => {
|
await events.friendUserStatusChanged.listen((event) => {
|
||||||
const { userId, status } = event.payload;
|
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) => ({
|
friendsPresenceStates.update((current) => ({
|
||||||
...current,
|
...current,
|
||||||
[userId]: status,
|
[userId]: status,
|
||||||
|
|||||||
Reference in New Issue
Block a user