Actually notify of bites

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-08-31 20:52:44 +02:00
parent d47447afae
commit a7ef06e947
2 changed files with 26 additions and 25 deletions

View file

@ -473,35 +473,36 @@ def handle(
} = object, } = object,
meta meta
) do ) do
with %User{} = biting <- User.get_cached_by_ap_id(biting_user), meta =
%User{} = bitten <- User.get_cached_by_ap_id(bitten_user), with %User{} = biting <- User.get_cached_by_ap_id(biting_user),
{:previous_bite, previous_bite} <- %User{} = bitten <- User.get_cached_by_ap_id(bitten_user),
{:previous_bite, Utils.fetch_latest_bite(biting, bitten, object)}, {:previous_bite, previous_bite} <-
{:reverse_bite, reverse_bite} <- {:previous_bite, Utils.fetch_latest_bite(biting, bitten, object)},
{:reverse_bite, Utils.fetch_latest_bite(bitten, biting)}, {:reverse_bite, reverse_bite} <-
{:can_bite, true, _} <- {:can_bite, can_bite?(previous_bite, reverse_bite), bitten} do {:reverse_bite, Utils.fetch_latest_bite(bitten, biting)},
if bitten.local do {:can_bite, true, _} <- {:can_bite, can_bite?(previous_bite, reverse_bite), bitten} do
{:ok, accept_data, _} = Builder.accept(bitten, object) if bitten.local do
{:ok, _activity, _} = Pipeline.common_pipeline(accept_data, local: true) {:ok, accept_data, _} = Builder.accept(bitten, object)
end {:ok, _activity, _} = Pipeline.common_pipeline(accept_data, local: true)
end
if reverse_bite do if reverse_bite do
Notification.dismiss(reverse_bite) Notification.dismiss(reverse_bite)
end 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 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 meta
end end
updated_object = Activity.get_by_ap_id(bite_id) updated_object = Activity.get_by_ap_id(bite_id)

View file

@ -17,7 +17,7 @@ defmodule Pleroma.Web.Push.Impl do
import Ecto.Query import Ecto.Query
@body_chars 140 @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" @doc "Builds webpush notification payloads for the subscriptions enabled by the receiving user"
@spec build(Notification.t()) :: @spec build(Notification.t()) ::