Group member add and remove routes.

This commit is contained in:
Paul Makles
2021-01-19 09:02:18 +00:00
parent 901b29f49e
commit c21d7c4620
8 changed files with 185 additions and 59 deletions

View File

@@ -5,6 +5,7 @@ use crate::{
};
use mongodb::bson::{to_bson, DateTime};
use serde::{Deserialize, Serialize};
use ulid::Ulid;
/*#[derive(Serialize, Deserialize, Debug)]
pub struct PreviousEntry {
@@ -41,6 +42,18 @@ pub struct Message {
}
impl Message {
pub fn create(author: String, channel: String, content: String) -> Message {
Message {
id: Ulid::new().to_string(),
nonce: None,
channel,
author,
content,
edited: None,
}
}
pub async fn publish(self) -> Result<()> {
get_collection("messages")
.insert_one(to_bson(&self).unwrap().as_document().unwrap().clone(), None)

View File

@@ -49,6 +49,12 @@ pub async fn calculate(user: &User, target: &Channel) -> ChannelPermissions<[u32
ChannelPermissions([0])
}
_ => unreachable!(),
Channel::Group { recipients, .. } => {
if recipients.iter().find(|x| *x == &user.id).is_some() {
ChannelPermissions([ChannelPermission::View + ChannelPermission::SendMessage])
} else {
ChannelPermissions([0])
}
}
}
}