1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-09-19 11:28:46 +00:00

Send message through WebSocket fro new conversation messages

This commit is contained in:
2021-02-06 09:41:56 +01:00
parent cf6063feef
commit de2448d496
6 changed files with 106 additions and 8 deletions

View File

@@ -4,9 +4,22 @@
use serde::{Deserialize, Serialize};
use crate::data::error::Res;
#[derive(Clone, Serialize, Deserialize)]
pub struct UserWsMessage {
pub id: Option<String>,
pub title: String,
pub data: serde_json::Value,
}
impl UserWsMessage {
/// Construct a new WebSocket message with no ID
pub fn no_id_message<T: Serialize>(title: &str, data: T) -> Res<Self> {
Ok(UserWsMessage {
id: None,
title: title.to_string(),
data: serde_json::to_value(data)?,
})
}
}