forked from jmug/stoatchat
Add utility function for including relationship on User.
This commit is contained in:
@@ -5,7 +5,7 @@ use rocket_contrib::json::JsonValue;
|
||||
|
||||
#[get("/<target>")]
|
||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
let mut target = target.fetch_user().await?;
|
||||
let target = target.fetch_user().await?;
|
||||
|
||||
let perm = permissions::PermissionCalculator::new(&user)
|
||||
.with_user(&target)
|
||||
@@ -16,19 +16,9 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
Err(Error::LabelMe)?
|
||||
}
|
||||
|
||||
if user.id != target.id {
|
||||
if let Some(relationships) = &user.relations {
|
||||
target.relationship = relationships
|
||||
.iter()
|
||||
.find(|x| x.id == user.id)
|
||||
.map(|x| x.status.clone())
|
||||
.or_else(|| Some(RelationshipStatus::None));
|
||||
} else {
|
||||
target.relationship = Some(RelationshipStatus::None);
|
||||
}
|
||||
} else {
|
||||
target.relationship = Some(RelationshipStatus::User);
|
||||
}
|
||||
|
||||
Ok(json!(target.with(perm)))
|
||||
Ok(json!(
|
||||
target
|
||||
.from(&user)
|
||||
.with(perm)
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user