Channel subscription, message sending, channel delete.

This commit is contained in:
Paul Makles
2021-01-18 14:50:17 +00:00
parent 15357008d6
commit 3d3db80e61
7 changed files with 139 additions and 4 deletions

View File

@@ -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(())
}
}