diff options
author | Sadposter <hannah+pleroma@coffee-and-dreams.uk> | 2019-04-10 10:44:54 +0100 |
---|---|---|
committer | Sadposter <hannah+pleroma@coffee-and-dreams.uk> | 2019-04-10 10:44:54 +0100 |
commit | be8350baa2f8c9cf9be3f53ee4a0041dada1386f (patch) | |
tree | 8414fc2108941ccadd9b9fd4dd37c9d3cf731399 /lib/pleroma/notification.ex | |
parent | 589629cf3e1bee9a4f6e92b8456d8614eff73c89 (diff) | |
parent | c8440b5e0c97c5d5c03e4b99e30a61df6ab95319 (diff) | |
download | pleroma-be8350baa2f8c9cf9be3f53ee4a0041dada1386f.tar.gz |
Merge branch 'develop' into feature/user-status-subscriptions
Diffstat (limited to 'lib/pleroma/notification.ex')
-rw-r--r-- | lib/pleroma/notification.ex | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 7c5856438..15789907a 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -122,13 +122,7 @@ defmodule Pleroma.Notification do # TODO move to sql, too. def create_notification(%Activity{} = activity, %User{} = user) do - unless User.blocks?(user, %{ap_id: activity.data["actor"]}) or - CommonAPI.thread_muted?(user, activity) or user.ap_id == activity.data["actor"] or - (activity.data["type"] == "Follow" and - Enum.any?(Notification.for_user(user), fn notif -> - notif.activity.data["type"] == "Follow" and - notif.activity.data["actor"] == activity.data["actor"] - end)) do + unless skip?(activity, user) do notification = %Notification{user_id: user.id, activity: activity} {:ok, notification} = Repo.insert(notification) Pleroma.Web.Streamer.stream("user", notification) @@ -155,4 +149,59 @@ defmodule Pleroma.Notification do end def get_notified_from_activity(_, _local_only), do: [] + + def skip?(activity, user) do + [:self, :blocked, :local, :muted, :followers, :follows, :recently_followed] + |> Enum.any?(&skip?(&1, activity, user)) + end + + def skip?(:self, activity, user) do + activity.data["actor"] == user.ap_id + end + + def skip?(:blocked, activity, user) do + actor = activity.data["actor"] + User.blocks?(user, %{ap_id: actor}) + end + + def skip?(:local, %{local: true}, %{info: %{notification_settings: %{"local" => false}}}), + do: true + + def skip?(:local, %{local: false}, %{info: %{notification_settings: %{"remote" => false}}}), + do: true + + def skip?(:muted, activity, user) do + actor = activity.data["actor"] + + User.mutes?(user, %{ap_id: actor}) or + CommonAPI.thread_muted?(user, activity) + end + + def skip?( + :followers, + activity, + %{info: %{notification_settings: %{"followers" => false}}} = user + ) do + actor = activity.data["actor"] + follower = User.get_cached_by_ap_id(actor) + User.following?(follower, user) + end + + def skip?(:follows, activity, %{info: %{notification_settings: %{"follows" => false}}} = user) do + actor = activity.data["actor"] + followed = User.get_by_ap_id(actor) + User.following?(user, followed) + end + + def skip?(:recently_followed, %{data: %{"type" => "Follow"}} = activity, user) do + actor = activity.data["actor"] + + Notification.for_user(user) + |> Enum.any?(fn + %{activity: %{data: %{"type" => "Follow", "actor" => ^actor}}} -> true + _ -> false + end) + end + + def skip?(_, _, _), do: false end |