mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-02-04 05:12:22 +00:00
Import hashtags from activitypub statuses
This commit is contained in:
parent
ba0fcccfc5
commit
11640f986e
3 changed files with 25 additions and 7 deletions
|
@ -186,7 +186,7 @@ class ActivityObject:
|
||||||
|
|
||||||
# add many to many fields, which have to be set post-save
|
# add many to many fields, which have to be set post-save
|
||||||
for field in instance.many_to_many_fields:
|
for field in instance.many_to_many_fields:
|
||||||
# mention books/users, for example
|
# mention books/users/hashtags, for example
|
||||||
field.set_field_from_activity(
|
field.set_field_from_activity(
|
||||||
instance,
|
instance,
|
||||||
self,
|
self,
|
||||||
|
|
|
@ -389,13 +389,22 @@ class TagField(ManyToManyField):
|
||||||
if tag_type != self.related_model.activity_serializer.type:
|
if tag_type != self.related_model.activity_serializer.type:
|
||||||
# tags can contain multiple types
|
# tags can contain multiple types
|
||||||
continue
|
continue
|
||||||
items.append(
|
|
||||||
activitypub.resolve_remote_id(
|
if tag_type == "Hashtag":
|
||||||
link.href,
|
# we already have all data to create hashtags,
|
||||||
model=self.related_model,
|
# no need to fetch from remote
|
||||||
allow_external_connections=allow_external_connections,
|
item = self.related_model.activity_serializer(**link_json)
|
||||||
|
hashtag = item.to_model(model=self.related_model, save=True)
|
||||||
|
items.append(hashtag)
|
||||||
|
else:
|
||||||
|
# for other tag types we fetch them remotely
|
||||||
|
items.append(
|
||||||
|
activitypub.resolve_remote_id(
|
||||||
|
link.href,
|
||||||
|
model=self.related_model,
|
||||||
|
allow_external_connections=allow_external_connections,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -183,12 +183,21 @@ class BaseActivity(TestCase):
|
||||||
"name": "gerald j. books",
|
"name": "gerald j. books",
|
||||||
"href": "http://book.com/book",
|
"href": "http://book.com/book",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "Hashtag",
|
||||||
|
"name": "#BookClub",
|
||||||
|
"href": "http://example.com/tags/BookClub",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
update_data.to_model(model=models.Status, instance=status)
|
update_data.to_model(model=models.Status, instance=status)
|
||||||
self.assertEqual(status.mention_users.first(), self.user)
|
self.assertEqual(status.mention_users.first(), self.user)
|
||||||
self.assertEqual(status.mention_books.first(), book)
|
self.assertEqual(status.mention_books.first(), book)
|
||||||
|
|
||||||
|
hashtag = models.Hashtag.objects.filter(name="#BookClub").first()
|
||||||
|
self.assertIsNotNone(hashtag)
|
||||||
|
self.assertEqual(status.mention_hashtags.first(), hashtag)
|
||||||
|
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_to_model_one_to_many(self, *_):
|
def test_to_model_one_to_many(self, *_):
|
||||||
"""these are reversed relationships, where the secondary object
|
"""these are reversed relationships, where the secondary object
|
||||||
|
|
Loading…
Reference in a new issue