fix incoming GTS mentions and DMs

GoToSocial sends 'tag' values as a single object if there is only one
user mentioned, rather than an array with an object inside it.

This causes Bookwyrm to reject the tag since it comes through as a
dict rather than a list.

This commit fixes this at the point the incoming AP object is transformed
so that "mention" tags are turned into a mention_user.
This commit is contained in:
Hugh Rundle 2023-04-13 13:21:05 +10:00
parent c450947eee
commit e3261c6b88
2 changed files with 9 additions and 5 deletions

View file

@ -379,7 +379,12 @@ class TagField(ManyToManyField):
def field_from_activity(self, value, allow_external_connections=True):
if not isinstance(value, list):
return None
# GoToSocial DMs and single-user mentions are
# sent as objects, not as an array of objects
if isinstance(value, dict):
value = [value]
else:
return None
items = []
for link_json in value:
link = activitypub.Link(**link_json)

View file

@ -136,10 +136,9 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
# keep notes if they mention local users
if activity.tag == MISSING or activity.tag is None:
return True
# BUG: this fixes the TypeError but if there is only one user mentioned
# we still don't get any notifs and DMs are dropped.
tags = activity.tag if type(activity.tag) == list else [ activity.tag ]
# GoToSocial sends single tags as objects
# not wrapped in a list
tags = activity.tag if isinstance(activity.tag, list) else [ activity.tag ]
user_model = apps.get_model("bookwyrm.User", require_ready=True)
for tag in tags:
if (