Guard Post mentions processing from unfetched Identities (#272)

This commit is contained in:
Michael Manfre 2022-12-25 16:37:31 -05:00 committed by GitHub
parent d2766860c5
commit 50c07f491e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 9 deletions

View File

@ -139,8 +139,11 @@ class ContentRenderer:
url = str(mention.urls.view) url = str(mention.urls.view)
else: else:
url = mention.absolute_profile_uri() url = mention.absolute_profile_uri()
possible_matches[mention.username.lower()] = url # Might not have fetched it (yet)
possible_matches[f"{mention.username.lower()}@{mention.domain_id}"] = url if mention.username:
username = mention.username.lower()
possible_matches[username] = url
possible_matches[f"{username}@{mention.domain_id}"] = url
collapse_name: dict[str, str] = {} collapse_name: dict[str, str] = {}

View File

@ -75,15 +75,27 @@ def test_link_mixcase_mentions():
fake_mention2.username = "manfre" fake_mention2.username = "manfre"
fake_mention2.domain_id = "takahe.social" fake_mention2.domain_id = "takahe.social"
fake_mention2.urls.view = "https://takahe.social/@manfre@takahe.social/" fake_mention2.urls.view = "https://takahe.social/@manfre@takahe.social/"
unfetched_mention = Mock()
unfetched_mention.username = None
unfetched_mention.domain_id = None
unfetched_mention.urls.view = "/None@None/"
fake_post = Mock() fake_post = Mock()
fake_post.mentions.all.return_value = [fake_mention, fake_mention2] fake_post.mentions.all.return_value = [
fake_mention,
fake_mention2,
unfetched_mention,
]
fake_post.author.domain.uri_domain = "example.com" fake_post.author.domain.uri_domain = "example.com"
fake_post.emojis.all.return_value = [] fake_post.emojis.all.return_value = []
assert ( assert renderer.render_post(
renderer.render_post( "@Manfre@manfre.net @mAnFrE@takahe.social @manfre@manfre.net @unfetched@manfre.net",
"@Manfre@manfre.net @mAnFrE@takahe.social @manfre@manfre.net", fake_post,
fake_post, ) == (
) '<a href="/@Manfre@manfre.net/">@Manfre</a> '
== '<a href="/@Manfre@manfre.net/">@Manfre</a> <a href="https://takahe.social/@manfre@takahe.social/">@mAnFrE@takahe.social</a> <a href="/@Manfre@manfre.net/">@manfre</a>' '<a href="https://takahe.social/@manfre@takahe.social/">@mAnFrE@takahe.social</a> '
'<a href="/@Manfre@manfre.net/">@manfre</a> '
"@unfetched@manfre.net"
) )