Run cargo fmt.

This commit is contained in:
Paul
2021-05-01 17:29:31 +01:00
parent 59b18fd376
commit 8cfa5d7091
12 changed files with 166 additions and 119 deletions

View File

@@ -1,8 +1,8 @@
use mongodb::bson::{doc, from_document};
use serde::{Deserialize, Serialize};
use crate::util::result::{Error, Result};
use crate::database::*;
use crate::util::result::{Error, Result};
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "type")]
@@ -23,7 +23,7 @@ pub struct File {
metadata: Metadata,
content_type: String,
size: isize,
#[serde(skip_serializing_if = "Option::is_none")]
deleted: Option<bool>,
@@ -38,7 +38,12 @@ pub struct File {
}
impl File {
pub async fn find_and_use(attachment_id: &str, tag: &str, parent_type: &str, parent_id: &str) -> Result<File> {
pub async fn find_and_use(
attachment_id: &str,
tag: &str,
parent_type: &str,
parent_id: &str,
) -> Result<File> {
let attachments = get_collection("attachments");
let key = format!("{}_id", parent_type);
if let Some(doc) = attachments

View File

@@ -1,10 +1,13 @@
use crate::database::*;
use crate::notifications::events::ClientboundNotification;
use crate::util::result::{Error, Result};
use mongodb::{bson::{Document, doc, from_document, to_document}, options::FindOptions};
use futures::StreamExt;
use mongodb::{
bson::{doc, from_document, to_document, Document},
options::FindOptions,
};
use rocket_contrib::json::JsonValue;
use serde::{Deserialize, Serialize};
use futures::StreamExt;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct LastMessage {
@@ -132,7 +135,7 @@ impl Channel {
.into_iter()
.filter_map(|x| x.get_str("_id").ok().map(|x| x.to_string()))
.collect::<Vec<String>>();
// If we found any, mark them as deleted.
if message_ids.len() > 0 {
get_collection("attachments")
@@ -147,7 +150,7 @@ impl Channel {
"deleted": true
}
},
None
None,
)
.await
.map_err(|_| Error::DatabaseError {

View File

@@ -271,7 +271,7 @@ impl Message {
"deleted": true
}
},
None
None,
)
.await
.map_err(|_| Error::DatabaseError {

View File

@@ -116,10 +116,15 @@ impl User {
/// Mutate the user object to appear as seen by user.
/// Also overrides the relationship status.
pub async fn from_override(mut self, user: &User, relationship: RelationshipStatus) -> Result<User> {
pub async fn from_override(
mut self,
user: &User,
relationship: RelationshipStatus,
) -> Result<User> {
let permissions = PermissionCalculator::new(&user)
.with_relationship(&relationship)
.for_user(&self.id).await?;
.for_user(&self.id)
.await?;
self.relations = None;
self.relationship = Some(relationship);

View File

@@ -49,7 +49,12 @@ impl<'a> PermissionCalculator<'a> {
}
let mut permissions: u32 = 0;
match self.relationship.clone().map(|v| v.to_owned()).unwrap_or_else(|| get_relationship(&self.perspective, &target)) {
match self
.relationship
.clone()
.map(|v| v.to_owned())
.unwrap_or_else(|| get_relationship(&self.perspective, &target))
{
RelationshipStatus::Friend => return Ok(u32::MAX),
RelationshipStatus::Blocked | RelationshipStatus::BlockedOther => {
return Ok(UserPermission::Access as u32)