forked from jmug/stoatchat
Re-write notifications system.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user