mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-25 08:41:00 +00:00
Fix hashtag extraction on post edit
This commit is contained in:
parent
a6922cb9d6
commit
1ffbb2e860
2 changed files with 15 additions and 1 deletions
|
@ -507,7 +507,7 @@ class Post(StatorModel):
|
||||||
):
|
):
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
# Strip all HTML and apply linebreaks filter
|
# 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.content = parser.html
|
||||||
self.hashtags = sorted(parser.hashtags) or None
|
self.hashtags = sorted(parser.hashtags) or None
|
||||||
self.summary = summary or None
|
self.summary = summary or None
|
||||||
|
|
|
@ -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
|
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
|
@pytest.mark.django_db
|
||||||
def test_linkify_mentions_remote(
|
def test_linkify_mentions_remote(
|
||||||
identity, identity2, remote_identity, remote_identity2
|
identity, identity2, remote_identity, remote_identity2
|
||||||
|
|
Loading…
Reference in a new issue