From cec04e8ddb8b550b6ac04414a2e84db521715d9f Mon Sep 17 00:00:00 2001 From: Christof Dorner Date: Mon, 15 May 2023 17:36:33 +0000 Subject: [PATCH] Fixes various issues with pinned posts - continued (#581) --- users/models/identity.py | 2 +- users/services/identity.py | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/users/models/identity.py b/users/models/identity.py index 575dee0..9f19305 100644 --- a/users/models/identity.py +++ b/users/models/identity.py @@ -771,7 +771,7 @@ class Identity(StatorModel): if not isinstance(item, dict): continue post_obj: dict | None = item - if item["type"] == "Create": + if item["type"] in ["Create", "Update"]: post_obj = item.get("object") if post_obj: ids.append(post_obj["id"]) diff --git a/users/services/identity.py b/users/services/identity.py index 2b3427b..71b0a4f 100644 --- a/users/services/identity.py +++ b/users/services/identity.py @@ -190,13 +190,17 @@ class IdentityService: with transaction.atomic(): for object_uri in object_uris: - post = Post.by_object_uri(object_uri, fetch=True) - PostInteraction.objects.get_or_create( - type=PostInteraction.Types.pin, - identity=self.identity, - post=post, - state__in=PostInteractionStates.group_active(), - ) + try: + post = Post.by_object_uri(object_uri, fetch=True) + PostInteraction.objects.get_or_create( + type=PostInteraction.Types.pin, + identity=self.identity, + post=post, + state__in=PostInteractionStates.group_active(), + ) + except Post.DoesNotExist: + # ignore 404s... + pass for removed in PostInteraction.objects.filter( type=PostInteraction.Types.pin, identity=self.identity,