Make "to" property optional on Activity object

This commit is contained in:
silverpill 2021-11-20 21:15:56 +00:00
parent ec36dea0c9
commit 22fa619a16
3 changed files with 5 additions and 6 deletions

View file

@ -87,7 +87,7 @@ pub struct Activity {
pub actor: String,
pub object: Value,
pub to: Value,
pub to: Option<Value>,
}
fn create_activity(
@ -112,7 +112,7 @@ fn create_activity(
activity_type: activity_type.to_string(),
actor: actor_id,
object: serde_json::to_value(object).unwrap(),
to: json!([recipient_id]),
to: Some(json!([recipient_id])),
}
}
@ -455,6 +455,6 @@ mod tests {
assert_eq!(activity.object["actor"], Value::Null);
assert_eq!(activity.object["object"], Value::Null);
assert_eq!(activity.object["content"], Value::Null);
assert_eq!(activity.to, json!([target_actor_id]));
assert_eq!(activity.to.unwrap(), json!([target_actor_id]));
}
}

View file

@ -84,7 +84,7 @@ fn parse_array(value: &Value) -> Result<Vec<String>, ValidationError> {
let result = match value {
Value::String(string) => vec![string.to_string()],
Value::Array(array) => {
array.into_iter()
array.iter()
.filter_map(|val| val.as_str().map(|s| s.to_string()))
.collect()
},

View file

@ -38,8 +38,7 @@ pub fn can_view_post(user: Option<&User>, post: &Post) -> bool {
if let Some(user) = user {
// Returns true if user is mentioned
post.mentions.iter()
.find(|profile| profile.id == user.profile.id)
.is_some()
.any(|profile| profile.id == user.profile.id)
} else {
false
}