From a7ef06e9476624af0cc1192a66a777e7b6d3e0ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Sat, 31 Aug 2024 20:52:44 +0200 Subject: [PATCH] Actually notify of bites MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- lib/pleroma/web/activity_pub/side_effects.ex | 49 ++++++++++---------- lib/pleroma/web/push/impl.ex | 2 +- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/lib/pleroma/web/activity_pub/side_effects.ex b/lib/pleroma/web/activity_pub/side_effects.ex index 6e41798321..9b5ad17c8b 100644 --- a/lib/pleroma/web/activity_pub/side_effects.ex +++ b/lib/pleroma/web/activity_pub/side_effects.ex @@ -473,35 +473,36 @@ def handle( } = object, meta ) do - with %User{} = biting <- User.get_cached_by_ap_id(biting_user), - %User{} = bitten <- User.get_cached_by_ap_id(bitten_user), - {:previous_bite, previous_bite} <- - {:previous_bite, Utils.fetch_latest_bite(biting, bitten, object)}, - {:reverse_bite, reverse_bite} <- - {:reverse_bite, Utils.fetch_latest_bite(bitten, biting)}, - {:can_bite, true, _} <- {:can_bite, can_bite?(previous_bite, reverse_bite), bitten} do - if bitten.local do - {:ok, accept_data, _} = Builder.accept(bitten, object) - {:ok, _activity, _} = Pipeline.common_pipeline(accept_data, local: true) - end + meta = + with %User{} = biting <- User.get_cached_by_ap_id(biting_user), + %User{} = bitten <- User.get_cached_by_ap_id(bitten_user), + {:previous_bite, previous_bite} <- + {:previous_bite, Utils.fetch_latest_bite(biting, bitten, object)}, + {:reverse_bite, reverse_bite} <- + {:reverse_bite, Utils.fetch_latest_bite(bitten, biting)}, + {:can_bite, true, _} <- {:can_bite, can_bite?(previous_bite, reverse_bite), bitten} do + if bitten.local do + {:ok, accept_data, _} = Builder.accept(bitten, object) + {:ok, _activity, _} = Pipeline.common_pipeline(accept_data, local: true) + end - if reverse_bite do - Notification.dismiss(reverse_bite) - end + if reverse_bite do + Notification.dismiss(reverse_bite) + end - {:ok, notifications} = Notification.create_notifications(object) + {:ok, notifications} = Notification.create_notifications(object) - meta - |> add_notifications(notifications) - else - {:can_bite, false, bitten} -> - {:ok, reject_data, _} = Builder.reject(bitten, object) - {:ok, _activity, _} = Pipeline.common_pipeline(reject_data, local: true) meta + |> add_notifications(notifications) + else + {:can_bite, false, bitten} -> + {:ok, reject_data, _} = Builder.reject(bitten, object) + {:ok, _activity, _} = Pipeline.common_pipeline(reject_data, local: true) + meta - _ -> - meta - end + _ -> + meta + end updated_object = Activity.get_by_ap_id(bite_id) diff --git a/lib/pleroma/web/push/impl.ex b/lib/pleroma/web/push/impl.ex index e8e4ea1c0a..fbd7b9f1bd 100644 --- a/lib/pleroma/web/push/impl.ex +++ b/lib/pleroma/web/push/impl.ex @@ -17,7 +17,7 @@ defmodule Pleroma.Web.Push.Impl do import Ecto.Query @body_chars 140 - @types ["Create", "Follow", "Announce", "Like", "Move", "EmojiReact", "Update"] + @types ["Create", "Follow", "Announce", "Like", "Move", "EmojiReact", "Update", "Bite"] @doc "Builds webpush notification payloads for the subscriptions enabled by the receiving user" @spec build(Notification.t()) ::