Remove repeated mention tags when processing activities

This commit is contained in:
silverpill 2021-12-08 00:03:12 +00:00
parent be2201f7b6
commit 82fe25d458
2 changed files with 16 additions and 12 deletions

View file

@ -229,17 +229,18 @@ pub async fn process_note(
let mut mentions: Vec<Uuid> = Vec::new(); let mut mentions: Vec<Uuid> = Vec::new();
if let Some(list) = object.tag { if let Some(list) = object.tag {
for tag in list { 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(
if let Some(href) = tag.href { db_client,
let profile = get_or_fetch_profile_by_actor_id( &instance,
db_client, &href,
&instance, &config.media_dir(),
&href, ).await?;
&config.media_dir(), if !mentions.contains(&profile.id) {
).await?; mentions.push(profile.id);
mentions.push(profile.id); };
};
}; };
}; };
}; };

View file

@ -26,7 +26,9 @@ fn find_mentions(
let mut mentions = vec![]; let mut mentions = vec![];
for caps in mention_re.captures_iter(text) { for caps in mention_re.captures_iter(text) {
let acct = pattern_to_acct(&caps, instance_host); let acct = pattern_to_acct(&caps, instance_host);
mentions.push(acct); if !mentions.contains(&acct) {
mentions.push(acct);
};
}; };
mentions mentions
} }
@ -87,6 +89,7 @@ mod tests {
"@@invalid@server2.com ", "@@invalid@server2.com ",
"@test@server3.com@nospace@server4.com ", "@test@server3.com@nospace@server4.com ",
"@notmention ", "@notmention ",
"@user2@server2.com copy ",
"some text", "some text",
); );
let results = find_mentions(INSTANCE_HOST, text); let results = find_mentions(INSTANCE_HOST, text);