mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-22 17:41:08 +00:00
Merge pull request #2923 from jderuiter/hashtag-naming
Remove '@' from the beginning of hashtag names in activity
This commit is contained in:
commit
30f025dbcd
2 changed files with 42 additions and 1 deletions
|
@ -368,10 +368,16 @@ class TagField(ManyToManyField):
|
|||
activity_type = item.__class__.__name__
|
||||
if activity_type == "User":
|
||||
activity_type = "Mention"
|
||||
|
||||
if activity_type == "Hashtag":
|
||||
name = item.name
|
||||
else:
|
||||
name = f"@{getattr(item, item.name_field)}"
|
||||
|
||||
tags.append(
|
||||
activitypub.Link(
|
||||
href=item.remote_id,
|
||||
name=f"@{getattr(item, item.name_field)}",
|
||||
name=name,
|
||||
type=activity_type,
|
||||
)
|
||||
)
|
||||
|
|
|
@ -135,6 +135,41 @@ class Status(TestCase):
|
|||
self.assertEqual(activity["content"], "<p>test content</p>")
|
||||
self.assertEqual(activity["sensitive"], False)
|
||||
|
||||
def test_status_with_hashtag_to_activity(self, *_):
|
||||
"""status with hashtag with a "pure" serializer"""
|
||||
tag = models.Hashtag.objects.create(name="#content")
|
||||
status = models.Status.objects.create(
|
||||
content="test #content", user=self.local_user
|
||||
)
|
||||
status.mention_hashtags.add(tag)
|
||||
|
||||
activity = status.to_activity(pure=True)
|
||||
self.assertEqual(activity["id"], status.remote_id)
|
||||
self.assertEqual(activity["type"], "Note")
|
||||
self.assertEqual(activity["content"], "<p>test #content</p>")
|
||||
self.assertEqual(activity["sensitive"], False)
|
||||
self.assertEqual(activity["tag"][0]["type"], "Hashtag")
|
||||
self.assertEqual(activity["tag"][0]["name"], "#content")
|
||||
self.assertEqual(
|
||||
activity["tag"][0]["href"], f"https://{settings.DOMAIN}/hashtag/{tag.id}"
|
||||
)
|
||||
|
||||
def test_status_with_mention_to_activity(self, *_):
|
||||
"""status with mention with a "pure" serializer"""
|
||||
status = models.Status.objects.create(
|
||||
content="test @rat@rat.com", user=self.local_user
|
||||
)
|
||||
status.mention_users.add(self.remote_user)
|
||||
|
||||
activity = status.to_activity(pure=True)
|
||||
self.assertEqual(activity["id"], status.remote_id)
|
||||
self.assertEqual(activity["type"], "Note")
|
||||
self.assertEqual(activity["content"], "<p>test @rat@rat.com</p>")
|
||||
self.assertEqual(activity["sensitive"], False)
|
||||
self.assertEqual(activity["tag"][0]["type"], "Mention")
|
||||
self.assertEqual(activity["tag"][0]["name"], f"@{self.remote_user.username}")
|
||||
self.assertEqual(activity["tag"][0]["href"], self.remote_user.remote_id)
|
||||
|
||||
def test_status_to_activity_tombstone(self, *_):
|
||||
"""subclass of the base model version with a "pure" serializer"""
|
||||
status = models.Status.objects.create(
|
||||
|
|
Loading…
Reference in a new issue