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,9 +229,7 @@ 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 { if let Some(href) = tag.href {
let profile = get_or_fetch_profile_by_actor_id( let profile = get_or_fetch_profile_by_actor_id(
db_client, db_client,
@ -239,10 +237,13 @@ pub async fn process_note(
&href, &href,
&config.media_dir(), &config.media_dir(),
).await?; ).await?;
if !mentions.contains(&profile.id) {
mentions.push(profile.id); mentions.push(profile.id);
}; };
}; };
}; };
};
};
let in_reply_to_id = match object.in_reply_to { let in_reply_to_id = match object.in_reply_to {
Some(object_id) => { Some(object_id) => {
match parse_object_id(&instance.url(), &object_id) { match parse_object_id(&instance.url(), &object_id) {

View file

@ -26,8 +26,10 @@ 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);
if !mentions.contains(&acct) {
mentions.push(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);