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();
if let Some(list) = object.tag {
for tag in list {
if tag.tag_type != MENTION {
continue;
};
if let Some(href) = tag.href {
let profile = get_or_fetch_profile_by_actor_id(
db_client,
&instance,
&href,
&config.media_dir(),
).await?;
mentions.push(profile.id);
if tag.tag_type == MENTION {
if let Some(href) = tag.href {
let profile = get_or_fetch_profile_by_actor_id(
db_client,
&instance,
&href,
&config.media_dir(),
).await?;
if !mentions.contains(&profile.id) {
mentions.push(profile.id);
};
};
};
};
};

View file

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