Use actor ID for href field in mention tag
Mastodon also does this in latest version.
This commit is contained in:
parent
ffdda2ac51
commit
0715b7d64f
|
@ -206,11 +206,11 @@ pub fn create_note(
|
|||
for profile in &post.mentions {
|
||||
let actor_id = profile.actor_id(instance_url);
|
||||
primary_audience.push(actor_id);
|
||||
let actor_url = profile.actor_url(instance_url);
|
||||
let actor_id = profile.actor_id(instance_url);
|
||||
let tag = Tag {
|
||||
name: format!("@{}", profile.actor_address(instance_host)),
|
||||
tag_type: MENTION.to_string(),
|
||||
href: Some(actor_url),
|
||||
href: Some(actor_id),
|
||||
};
|
||||
tags.push(tag);
|
||||
};
|
||||
|
@ -594,7 +594,7 @@ mod tests {
|
|||
let tags = note.tag;
|
||||
assert_eq!(tags.len(), 1);
|
||||
assert_eq!(tags[0].name, format!("@{}", parent_author_acct));
|
||||
assert_eq!(tags[0].href.as_ref().unwrap(), parent_author_actor_url);
|
||||
assert_eq!(tags[0].href.as_ref().unwrap(), parent_author_actor_id);
|
||||
assert_eq!(note.to, vec![AP_PUBLIC, parent_author_actor_id]);
|
||||
}
|
||||
|
||||
|
|
|
@ -308,19 +308,19 @@ pub async fn import_post(
|
|||
tags.push(tag_name);
|
||||
};
|
||||
} else if tag.tag_type == MENTION {
|
||||
// href attribute is not an actor ID but is a link to profile
|
||||
// Try to find profile by actor ID.
|
||||
if let Some(href) = tag.href {
|
||||
// TODO: use actor_url
|
||||
match parse_actor_id(&config.instance_url(), &href) {
|
||||
Ok(username) => {
|
||||
let user = get_user_by_name(db_client, &username).await?;
|
||||
if !mentions.contains(&user.id) {
|
||||
mentions.push(user.id);
|
||||
};
|
||||
continue;
|
||||
},
|
||||
Err(_) => (), // remote profile
|
||||
if let Ok(username) = parse_actor_id(&config.instance_url(), &href) {
|
||||
let user = get_user_by_name(db_client, &username).await?;
|
||||
if !mentions.contains(&user.id) {
|
||||
mentions.push(user.id);
|
||||
};
|
||||
continue;
|
||||
};
|
||||
// WARNING: `href` attribute is usually actor ID
|
||||
// but also can be actor URL (profile link).
|
||||
// This may lead to failed import due to
|
||||
// unique constraint violation on DB insert.
|
||||
match get_or_import_profile_by_actor_id(
|
||||
db_client,
|
||||
&instance,
|
||||
|
@ -335,10 +335,10 @@ pub async fn import_post(
|
|||
},
|
||||
Err(error) => {
|
||||
log::warn!("failed to find mentioned profile {}: {}", href, error);
|
||||
// Try to parse tag name
|
||||
},
|
||||
};
|
||||
};
|
||||
// Try to find profile by actor address
|
||||
if let Ok(actor_address) = mention_to_address(
|
||||
&instance.host(),
|
||||
&tag.name,
|
||||
|
|
Loading…
Reference in a new issue