Channel subscription, message sending, channel delete.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// use mongodb::bson::DateTime;
|
||||
// use serde::{Deserialize, Serialize};
|
||||
use crate::{database::*, notifications::events::ClientboundNotification, util::result::Result};
|
||||
use mongodb::bson::{DateTime, to_bson};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/*#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct PreviousEntry {
|
||||
@@ -20,3 +21,36 @@ pub struct Message {
|
||||
|
||||
pub previous_content: Vec<PreviousEntry>,
|
||||
}*/
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Message {
|
||||
#[serde(rename = "_id")]
|
||||
pub id: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub nonce: Option<String>,
|
||||
pub channel: String,
|
||||
pub author: String,
|
||||
|
||||
pub content: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub edited: Option<DateTime>,
|
||||
}
|
||||
|
||||
impl Message {
|
||||
pub async fn send(self) -> Result<()> {
|
||||
get_collection("messages")
|
||||
.insert_one(
|
||||
to_bson(&self).unwrap().as_document().unwrap().clone(),
|
||||
None
|
||||
)
|
||||
.await;
|
||||
|
||||
let channel = self.channel.clone();
|
||||
ClientboundNotification::Message(self)
|
||||
.publish(channel)
|
||||
.await
|
||||
.ok();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user