From 28dc67bf5c0d5bfb24dba3ed6a6fc958afc7a036 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 24 Mar 2021 12:37:42 -0700 Subject: [PATCH] Fixes ignore test for valid remote statuses --- bookwyrm/activitypub/base_activity.py | 7 ++++++- bookwyrm/models/status.py | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/bookwyrm/activitypub/base_activity.py b/bookwyrm/activitypub/base_activity.py index 791502d0..c1f81bb0 100644 --- a/bookwyrm/activitypub/base_activity.py +++ b/bookwyrm/activitypub/base_activity.py @@ -248,7 +248,9 @@ def get_model_from_type(activity_type): return model[0] -def resolve_remote_id(remote_id, model=None, refresh=False, save=True): +def resolve_remote_id( + remote_id, model=None, refresh=False, save=True, get_activity=False +): """ take a remote_id and return an instance, creating if necessary """ if model: # a bonus check we can do if we already know the model result = model.find_existing_by_remote_id(remote_id) @@ -272,5 +274,8 @@ def resolve_remote_id(remote_id, model=None, refresh=False, save=True): return result item = model.activity_serializer(**data) + if get_activity: + return item + # if we're refreshing, "result" will be set and we'll update it return item.to_model(model=model, instance=result, save=save) diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index c5ba7993..c471a4d9 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -123,12 +123,14 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): """ keep notes if they are replies to existing statuses """ if activity.type == "Announce": try: - boosted = activitypub.resolve_remote_id(activity.object, save=False) + boosted = activitypub.resolve_remote_id( + activity.object, get_activity=True + ) except activitypub.ActivitySerializerError: # if we can't load the status, definitely ignore it return True # keep the boost if we would keep the status - return cls.ignore_activity(boosted.to_activity_dataclass()) + return cls.ignore_activity(boosted) # keep if it if it's a custom type if activity.type != "Note":