Fix hashtag extraction on post edit

This commit is contained in:
Andrew Godwin 2023-01-29 18:13:21 -07:00
parent a6922cb9d6
commit 1ffbb2e860
2 changed files with 15 additions and 1 deletions

View file

@ -507,7 +507,7 @@ class Post(StatorModel):
):
with transaction.atomic():
# Strip all HTML and apply linebreaks filter
parser = FediverseHtmlParser(linebreaks_filter(content))
parser = FediverseHtmlParser(linebreaks_filter(content), find_hashtags=True)
self.content = parser.html
self.hashtags = sorted(parser.hashtags) or None
self.summary = summary or None

View file

@ -42,6 +42,20 @@ def test_fetch_post(httpx_mock: HTTPXMock, config_system):
assert Post.by_object_uri("https://example.com/test-post").id == post.id
@pytest.mark.django_db
def test_post_create_edit(identity: Identity, config_system):
"""
Tests that creating/editing a post works, and extracts mentions and hashtags.
"""
post = Post.create_local(author=identity, content="Hello #world I am @test")
assert post.hashtags == ["world"]
assert list(post.mentions.all()) == [identity]
post.edit_local(content="Now I like #hashtags")
assert post.hashtags == ["hashtags"]
assert list(post.mentions.all()) == []
@pytest.mark.django_db
def test_linkify_mentions_remote(
identity, identity2, remote_identity, remote_identity2