diff options
author | lain <lain@soykaf.club> | 2020-06-05 16:47:02 +0200 |
---|---|---|
committer | lain <lain@soykaf.club> | 2020-06-05 16:47:02 +0200 |
commit | 115d08a7542b92c5e1d889da41c0ee6837a1235e (patch) | |
tree | 9f1d3aa8a65f53d5a42b9ab64013c2d9a3296a19 /lib/pleroma/notification.ex | |
parent | 65689ba9bd44e291fc626cce2bd5136b93a5da90 (diff) | |
download | pleroma-115d08a7542b92c5e1d889da41c0ee6837a1235e.tar.gz |
Pipeline: Add a side effects step after the transaction finishes
This is to run things like streaming notifications out, which will
sometimes need data that is created by the transaction, but is
streamed out asynchronously.
Diffstat (limited to 'lib/pleroma/notification.ex')
-rw-r--r-- | lib/pleroma/notification.ex | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index e5b880b10..49e27c05a 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -334,30 +334,34 @@ defmodule Pleroma.Notification do end end - def create_notifications(%Activity{data: %{"to" => _, "type" => "Create"}} = activity) do + def create_notifications(activity, options \\ []) + + def create_notifications(%Activity{data: %{"to" => _, "type" => "Create"}} = activity, options) do object = Object.normalize(activity, false) if object && object.data["type"] == "Answer" do {:ok, []} else - do_create_notifications(activity) + do_create_notifications(activity, options) end end - def create_notifications(%Activity{data: %{"type" => type}} = activity) + def create_notifications(%Activity{data: %{"type" => type}} = activity, options) when type in ["Follow", "Like", "Announce", "Move", "EmojiReact"] do - do_create_notifications(activity) + do_create_notifications(activity, options) end - def create_notifications(_), do: {:ok, []} + def create_notifications(_, _), do: {:ok, []} + + defp do_create_notifications(%Activity{} = activity, options) do + do_send = Keyword.get(options, :do_send, true) - defp do_create_notifications(%Activity{} = activity) do {enabled_receivers, disabled_receivers} = get_notified_from_activity(activity) potential_receivers = enabled_receivers ++ disabled_receivers notifications = Enum.map(potential_receivers, fn user -> - do_send = user in enabled_receivers + do_send = do_send && user in enabled_receivers create_notification(activity, user, do_send) end) @@ -623,4 +627,12 @@ defmodule Pleroma.Notification do end def skip?(_, _, _), do: false + + def for_user_and_activity(user, activity) do + from(n in __MODULE__, + where: n.user_id == ^user.id, + where: n.activity_id == ^activity.id + ) + |> Repo.one() + end end |