Allow for tag value to be object

Previously the 'tag' value in an activitypub object was assumed to be a List (array).
Some AP software sends 'tag' as a Dict (object) if there is only a single tag value.
It's somewhat debatable whether this is spec compliant but we should aim to be robust.
This commit puts an individual mention tag inside a list if necessary.
This commit is contained in:
Hugh Rundle 2023-04-10 20:35:13 +10:00
parent e112718d2d
commit ef85394a16

View file

@ -136,10 +136,16 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
# keep notes if they mention local users # keep notes if they mention local users
if activity.tag == MISSING or activity.tag is None: if activity.tag == MISSING or activity.tag is None:
return True return True
tags = [l["href"] for l in activity.tag if l["type"] == "Mention"]
tags = activity.tag if type(activity.tag) == list else [activity.tag]
user_model = apps.get_model("bookwyrm.User", require_ready=True) user_model = apps.get_model("bookwyrm.User", require_ready=True)
for tag in tags: for tag in tags:
if user_model.objects.filter(remote_id=tag, local=True).exists(): if (
tag["type"] == "Mention"
and user_model.objects.filter(
remote_id=tag["href"], local=True
).exists()
):
# we found a mention of a known use boost # we found a mention of a known use boost
return False return False
return True return True