Start work on notifications from client, cargo fmt
This commit is contained in:
@@ -1,20 +1,23 @@
|
||||
use crate::{database::entities::RelationshipStatus, database::guards::reference::Ref, database::entities::User, database::permissions::get_relationship, util::result::Error, database::get_collection};
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use crate::util::result::Result;
|
||||
use mongodb::bson::doc;
|
||||
use crate::{
|
||||
database::entities::RelationshipStatus, database::entities::User, database::get_collection,
|
||||
database::guards::reference::Ref, database::permissions::get_relationship, util::result::Error,
|
||||
};
|
||||
use futures::try_join;
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::JsonValue;
|
||||
|
||||
#[delete("/<target>/block")]
|
||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
let col = get_collection("users");
|
||||
|
||||
match get_relationship(&user, &target) {
|
||||
RelationshipStatus::None |
|
||||
RelationshipStatus::User |
|
||||
RelationshipStatus::BlockedOther |
|
||||
RelationshipStatus::Incoming |
|
||||
RelationshipStatus::Outgoing |
|
||||
RelationshipStatus::Friend => Err(Error::NoEffect),
|
||||
RelationshipStatus::None
|
||||
| RelationshipStatus::User
|
||||
| RelationshipStatus::BlockedOther
|
||||
| RelationshipStatus::Incoming
|
||||
| RelationshipStatus::Outgoing
|
||||
| RelationshipStatus::Friend => Err(Error::NoEffect),
|
||||
RelationshipStatus::Blocked => {
|
||||
match get_relationship(&target.fetch_user().await?, &user.as_ref()) {
|
||||
RelationshipStatus::Blocked => {
|
||||
@@ -28,13 +31,16 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
"relations.$.status": "BlockedOther"
|
||||
}
|
||||
},
|
||||
None
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError { operation: "update_one", with: "user" })?;
|
||||
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "user",
|
||||
})?;
|
||||
|
||||
Ok(json!({ "status": "BlockedOther" }))
|
||||
},
|
||||
}
|
||||
RelationshipStatus::BlockedOther => {
|
||||
match try_join!(
|
||||
col.update_one(
|
||||
@@ -65,10 +71,13 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
)
|
||||
) {
|
||||
Ok(_) => Ok(json!({ "status": "None" })),
|
||||
Err(_) => Err(Error::DatabaseError { operation: "update_one", with: "user" })
|
||||
Err(_) => Err(Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "user",
|
||||
}),
|
||||
}
|
||||
},
|
||||
_ => Err(Error::InternalError)
|
||||
}
|
||||
_ => Err(Error::InternalError),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user