Run cargo fmt.
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use mongodb::{
|
||||
bson::{doc},
|
||||
options::FindOneOptions,
|
||||
};
|
||||
use mongodb::{bson::doc, options::FindOneOptions};
|
||||
use rocket_contrib::json::{Json, JsonValue};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ulid::Ulid;
|
||||
|
||||
@@ -67,8 +67,12 @@ pub async fn req(user: User, username: String) -> Result<JsonValue> {
|
||||
)
|
||||
) {
|
||||
Ok(_) => {
|
||||
let target_user = target_user.from_override(&user, RelationshipStatus::Friend).await?;
|
||||
let user = user.from_override(&target_user, RelationshipStatus::Friend).await?;
|
||||
let target_user = target_user
|
||||
.from_override(&user, RelationshipStatus::Friend)
|
||||
.await?;
|
||||
let user = user
|
||||
.from_override(&target_user, RelationshipStatus::Friend)
|
||||
.await?;
|
||||
|
||||
try_join!(
|
||||
ClientboundNotification::UserRelationship {
|
||||
@@ -126,8 +130,12 @@ pub async fn req(user: User, username: String) -> Result<JsonValue> {
|
||||
)
|
||||
) {
|
||||
Ok(_) => {
|
||||
let target_user = target_user.from_override(&user, RelationshipStatus::Outgoing).await?;
|
||||
let user = user.from_override(&target_user, RelationshipStatus::Incoming).await?;
|
||||
let target_user = target_user
|
||||
.from_override(&user, RelationshipStatus::Outgoing)
|
||||
.await?;
|
||||
let user = user
|
||||
.from_override(&target_user, RelationshipStatus::Incoming)
|
||||
.await?;
|
||||
try_join!(
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
|
||||
@@ -76,8 +76,12 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
)
|
||||
) {
|
||||
Ok(_) => {
|
||||
let target = target.from_override(&user, RelationshipStatus::Friend).await?;
|
||||
let user = user.from_override(&target, RelationshipStatus::Friend).await?;
|
||||
let target = target
|
||||
.from_override(&user, RelationshipStatus::Friend)
|
||||
.await?;
|
||||
let user = user
|
||||
.from_override(&target, RelationshipStatus::Friend)
|
||||
.await?;
|
||||
let target_id = target.id.clone();
|
||||
|
||||
try_join!(
|
||||
@@ -134,8 +138,12 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
)
|
||||
) {
|
||||
Ok(_) => {
|
||||
let target = target.from_override(&user, RelationshipStatus::Blocked).await?;
|
||||
let user = user.from_override(&target, RelationshipStatus::BlockedOther).await?;
|
||||
let target = target
|
||||
.from_override(&user, RelationshipStatus::Blocked)
|
||||
.await?;
|
||||
let user = user
|
||||
.from_override(&target, RelationshipStatus::BlockedOther)
|
||||
.await?;
|
||||
let target_id = target.id.clone();
|
||||
|
||||
try_join!(
|
||||
|
||||
@@ -23,31 +23,39 @@ pub struct Data {
|
||||
#[patch("/<_ignore_id>", data = "<data>")]
|
||||
pub async fn req(user: User, mut data: Json<Data>, _ignore_id: String) -> Result<()> {
|
||||
if data.0.status.is_none() && data.0.profile.is_none() && data.0.avatar.is_none() {
|
||||
return Ok(())
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
data.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
let mut set = to_document(&data.0).map_err(|_| Error::DatabaseError { operation: "to_document", with: "data" })?;
|
||||
let mut set = to_document(&data.0).map_err(|_| Error::DatabaseError {
|
||||
operation: "to_document",
|
||||
with: "data",
|
||||
})?;
|
||||
|
||||
let avatar = std::mem::replace(&mut data.0.avatar, None);
|
||||
let attachment = if let Some(attachment_id) = avatar {
|
||||
let attachment = File::find_and_use(&attachment_id, "avatars", "user", &user.id).await?;
|
||||
set.insert("avatar", to_document(&attachment).map_err(|_| Error::DatabaseError { operation: "to_document", with: "attachment" })?);
|
||||
set.insert(
|
||||
"avatar",
|
||||
to_document(&attachment).map_err(|_| Error::DatabaseError {
|
||||
operation: "to_document",
|
||||
with: "attachment",
|
||||
})?,
|
||||
);
|
||||
Some(attachment)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
get_collection("users")
|
||||
.update_one(
|
||||
doc! { "_id": &user.id },
|
||||
doc! { "$set": set },
|
||||
None
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError { operation: "update_one", with: "user" })?;
|
||||
.update_one(doc! { "_id": &user.id }, doc! { "$set": set }, None)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "user",
|
||||
})?;
|
||||
|
||||
if let Some(status) = data.0.status {
|
||||
ClientboundNotification::UserUpdate {
|
||||
|
||||
@@ -45,8 +45,12 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
)
|
||||
) {
|
||||
Ok(_) => {
|
||||
let target = target.from_override(&user, RelationshipStatus::None).await?;
|
||||
let user = user.from_override(&target, RelationshipStatus::None).await?;
|
||||
let target = target
|
||||
.from_override(&user, RelationshipStatus::None)
|
||||
.await?;
|
||||
let user = user
|
||||
.from_override(&target, RelationshipStatus::None)
|
||||
.await?;
|
||||
let target_id = target.id.clone();
|
||||
|
||||
try_join!(
|
||||
|
||||
@@ -12,100 +12,104 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
let target = target.fetch_user().await?;
|
||||
|
||||
match get_relationship(&user, &target.id) {
|
||||
RelationshipStatus::Blocked => {
|
||||
match get_relationship(&target, &user.id) {
|
||||
RelationshipStatus::Blocked => {
|
||||
RelationshipStatus::Blocked => match get_relationship(&target, &user.id) {
|
||||
RelationshipStatus::Blocked => {
|
||||
col.update_one(
|
||||
doc! {
|
||||
"_id": &user.id,
|
||||
"relations._id": &target.id
|
||||
},
|
||||
doc! {
|
||||
"$set": {
|
||||
"relations.$.status": "BlockedOther"
|
||||
}
|
||||
},
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "user",
|
||||
})?;
|
||||
|
||||
let target = target
|
||||
.from_override(&user, RelationshipStatus::BlockedOther)
|
||||
.await?;
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
user: target,
|
||||
status: RelationshipStatus::BlockedOther,
|
||||
}
|
||||
.publish(user.id.clone())
|
||||
.await
|
||||
.ok();
|
||||
|
||||
Ok(json!({ "status": "BlockedOther" }))
|
||||
}
|
||||
RelationshipStatus::BlockedOther => {
|
||||
match try_join!(
|
||||
col.update_one(
|
||||
doc! {
|
||||
"_id": &user.id,
|
||||
"relations._id": &target.id
|
||||
"_id": &user.id
|
||||
},
|
||||
doc! {
|
||||
"$set": {
|
||||
"relations.$.status": "BlockedOther"
|
||||
"$pull": {
|
||||
"relations": {
|
||||
"_id": &target.id
|
||||
}
|
||||
}
|
||||
},
|
||||
None,
|
||||
None
|
||||
),
|
||||
col.update_one(
|
||||
doc! {
|
||||
"_id": &target.id
|
||||
},
|
||||
doc! {
|
||||
"$pull": {
|
||||
"relations": {
|
||||
"_id": &user.id
|
||||
}
|
||||
}
|
||||
},
|
||||
None
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
) {
|
||||
Ok(_) => {
|
||||
let target = target
|
||||
.from_override(&user, RelationshipStatus::None)
|
||||
.await?;
|
||||
let user = user
|
||||
.from_override(&target, RelationshipStatus::None)
|
||||
.await?;
|
||||
let target_id = target.id.clone();
|
||||
|
||||
try_join!(
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
user: target,
|
||||
status: RelationshipStatus::None
|
||||
}
|
||||
.publish(user.id.clone()),
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: target_id.clone(),
|
||||
user: user,
|
||||
status: RelationshipStatus::None
|
||||
}
|
||||
.publish(target_id)
|
||||
)
|
||||
.ok();
|
||||
|
||||
Ok(json!({ "status": "None" }))
|
||||
}
|
||||
Err(_) => Err(Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "user",
|
||||
})?;
|
||||
|
||||
let target = target.from_override(&user, RelationshipStatus::BlockedOther).await?;
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
user: target,
|
||||
status: RelationshipStatus::BlockedOther,
|
||||
}
|
||||
.publish(user.id.clone())
|
||||
.await
|
||||
.ok();
|
||||
|
||||
Ok(json!({ "status": "BlockedOther" }))
|
||||
}),
|
||||
}
|
||||
RelationshipStatus::BlockedOther => {
|
||||
match try_join!(
|
||||
col.update_one(
|
||||
doc! {
|
||||
"_id": &user.id
|
||||
},
|
||||
doc! {
|
||||
"$pull": {
|
||||
"relations": {
|
||||
"_id": &target.id
|
||||
}
|
||||
}
|
||||
},
|
||||
None
|
||||
),
|
||||
col.update_one(
|
||||
doc! {
|
||||
"_id": &target.id
|
||||
},
|
||||
doc! {
|
||||
"$pull": {
|
||||
"relations": {
|
||||
"_id": &user.id
|
||||
}
|
||||
}
|
||||
},
|
||||
None
|
||||
)
|
||||
) {
|
||||
Ok(_) => {
|
||||
let target = target.from_override(&user, RelationshipStatus::None).await?;
|
||||
let user = user.from_override(&target, RelationshipStatus::None).await?;
|
||||
let target_id = target.id.clone();
|
||||
|
||||
try_join!(
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
user: target,
|
||||
status: RelationshipStatus::None
|
||||
}
|
||||
.publish(user.id.clone()),
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: target_id.clone(),
|
||||
user: user,
|
||||
status: RelationshipStatus::None
|
||||
}
|
||||
.publish(target_id)
|
||||
)
|
||||
.ok();
|
||||
|
||||
Ok(json!({ "status": "None" }))
|
||||
}
|
||||
Err(_) => Err(Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "user",
|
||||
}),
|
||||
}
|
||||
}
|
||||
_ => Err(Error::InternalError),
|
||||
}
|
||||
}
|
||||
_ => Err(Error::InternalError),
|
||||
},
|
||||
_ => Err(Error::NoEffect),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user