diff --git a/activities/models/post.py b/activities/models/post.py index 88e53af..b3e22a0 100644 --- a/activities/models/post.py +++ b/activities/models/post.py @@ -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 diff --git a/tests/activities/models/test_post.py b/tests/activities/models/test_post.py index e37e42d..0b9578b 100644 --- a/tests/activities/models/test_post.py +++ b/tests/activities/models/test_post.py @@ -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