Re-write notifications system.

This commit is contained in:
Paul Makles
2020-04-13 16:04:41 +01:00
parent 4fbd6c816d
commit 577f25642e
10 changed files with 506 additions and 211 deletions

View File

@@ -1,6 +1,9 @@
use super::get_collection;
use crate::guards::channel::ChannelRef;
use crate::routes::channel::ChannelType;
use crate::notifications;
use crate::notifications::events::Notification::MessageCreate;
use crate::notifications::events::message::Create;
use bson::{doc, to_bson, UtcDateTime};
use serde::{Deserialize, Serialize};
@@ -34,6 +37,22 @@ impl Message {
.insert_one(to_bson(&self).unwrap().as_document().unwrap().clone(), None)
.is_ok()
{
let data = MessageCreate(
Create {
id: self.id.clone(),
nonce: self.nonce.clone(),
channel: self.channel.clone(),
author: self.author.clone(),
content: self.content.clone(),
}
);
match target.channel_type {
0..=1 => notifications::send_message(target.recipients.clone(), None, data),
2 => notifications::send_message(target.recipients.clone(), None, data),
_ => unreachable!()
};
let short_content: String = self.content.chars().take(24).collect();
// !! this stuff can be async
@@ -68,21 +87,6 @@ impl Message {
} else {
true
}
/*websocket::queue_message(
get_recipients(&target),
json!({
"type": "message",
"data": {
"id": id.clone(),
"nonce": nonce,
"channel": target.id,
"author": user.id,
"content": content,
},
})
.to_string(),
);*/
} else {
false
}