From ef85394a1633fb599df2ec31b29707c26042ce30 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 10 Apr 2023 20:35:13 +1000 Subject: [PATCH] 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. --- bookwyrm/models/status.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 1fcc9ee75..bd2a98f35 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -136,10 +136,16 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): # keep notes if they mention local users if activity.tag == MISSING or activity.tag is None: 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) 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 return False return True