Cache guilds.

This commit is contained in:
Paul Makles
2020-08-03 15:23:32 +02:00
parent fa6ed75ed8
commit 6a1912c27b
7 changed files with 327 additions and 221 deletions

View File

@@ -1,12 +1,15 @@
use super::get_collection;
use crate::notifications;
use crate::notifications::events::message::Create;
use crate::notifications::events::Notification;
use crate::database::channel::Channel;
use crate::routes::channel::ChannelType;
use crate::database::channel::Channel;
use super::get_collection;
use crate::notifications;
use bson::{doc, to_bson, UtcDateTime};
use serde::{Deserialize, Serialize};
use rocket::request::FromParam;
use bson::from_bson;
use rocket::http::RawStr;
#[derive(Serialize, Deserialize, Debug)]
pub struct PreviousEntry {
@@ -87,3 +90,20 @@ impl Message {
}
}
}
impl<'r> FromParam<'r> for Message {
type Error = &'r RawStr;
fn from_param(param: &'r RawStr) -> Result<Self, Self::Error> {
let col = get_collection("messages");
let result = col
.find_one(doc! { "_id": param.to_string() }, None)
.unwrap();
if let Some(message) = result {
Ok(from_bson(bson::Bson::Document(message)).expect("Failed to unwrap message."))
} else {
Err(param)
}
}
}