Make "href" property optional on Tag object

This commit is contained in:
silverpill 2021-11-24 19:00:36 +00:00
parent 7c58e15123
commit 215aa5932e
2 changed files with 8 additions and 5 deletions

View file

@ -32,7 +32,7 @@ pub struct Tag {
#[serde(rename = "type")]
pub tag_type: String,
pub href: String,
pub href: Option<String>,
}
#[derive(Default, Deserialize, Serialize)]
@ -149,7 +149,7 @@ pub fn create_note(
Tag {
name: profile.actor_address(instance_host),
tag_type: MENTION.to_string(),
href: actor_id,
href: Some(actor_id),
}
}).collect();
let in_reply_to_object_id = match post.in_reply_to_id {
@ -419,7 +419,7 @@ mod tests {
let tags = note.tag.unwrap();
assert_eq!(tags.len(), 1);
assert_eq!(tags[0].name, parent_author_acct);
assert_eq!(tags[0].href, parent_author_actor_id);
assert_eq!(tags[0].href.as_ref().unwrap(), parent_author_actor_id);
assert_eq!(
note.to.unwrap(),
json!([AP_PUBLIC, parent_author_actor_id]),

View file

@ -200,11 +200,14 @@ pub async fn process_note(
let mut mentions: Vec<Uuid> = Vec::new();
if let Some(list) = object.tag {
for tag in list {
if tag.tag_type == MENTION {
if tag.tag_type != MENTION {
continue;
};
if let Some(href) = tag.href {
let profile = get_or_fetch_profile_by_actor_id(
db_client,
&instance,
&tag.href,
&href,
&config.media_dir(),
).await?;
mentions.push(profile.id);