diff options
author | Karen Konou <konoukaren@gmail.com> | 2019-02-09 17:47:57 +0100 |
---|---|---|
committer | Karen Konou <konoukaren@gmail.com> | 2019-02-09 17:47:57 +0100 |
commit | a0d732ec55fcbce8cf345344d1456dc77bb0f3bf (patch) | |
tree | 050d0bbae605b270005d6e8aac9f8de28baa00d4 /lib | |
parent | 4430a0ad127411b818d875dbbaf14369c109f331 (diff) | |
download | pleroma-a0d732ec55fcbce8cf345344d1456dc77bb0f3bf.tar.gz |
it works!!
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/notification.ex | 2 | ||||
-rw-r--r-- | lib/pleroma/web/thread_mute.ex | 28 |
2 files changed, 27 insertions, 3 deletions
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 2364d36da..d05708e41 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -6,6 +6,7 @@ defmodule Pleroma.Notification do use Ecto.Schema alias Pleroma.{User, Activity, Notification, Repo} alias Pleroma.Web.CommonAPI.Utils + alias Pleroma.Web.ThreadMute import Ecto.Query schema "notifications" do @@ -112,6 +113,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 + ThreadMute.muted?(user, activity) or user.ap_id == activity.data["actor"] or (activity.data["type"] == "Follow" and Enum.any?(Notification.for_user(user), fn notif -> diff --git a/lib/pleroma/web/thread_mute.ex b/lib/pleroma/web/thread_mute.ex index 3a950f474..146de0d80 100644 --- a/lib/pleroma/web/thread_mute.ex +++ b/lib/pleroma/web/thread_mute.ex @@ -4,6 +4,7 @@ defmodule Pleroma.Web.ThreadMute do use Ecto.Schema + alias Pleroma.Web.ThreadMute alias Pleroma.{Activity, Repo, User} require Ecto.Query @@ -13,16 +14,37 @@ defmodule Pleroma.Web.ThreadMute do end def add_mute(user, id) do - %{data: %{"context" => context}} = Activity.get_by_id(id) + activity = Activity.get_by_id(id) + context = activity.data["context"] mute = %Pleroma.Web.ThreadMute{user_id: user.id, context: context} Repo.insert(mute) + {:ok, activity} end def remove_mute(user, id) do user_id = Pleroma.FlakeId.from_string(user.id) - %{data: %{"context" => context}} = Activity.get_by_id(id) + activity = Activity.get_by_id(id) + context = activity.data["context"] - Ecto.Query.from(m in "thread_mutes", where: m.user_id == ^user_id and m.context == ^context) + Ecto.Query.from(m in ThreadMute, where: m.user_id == ^user_id and m.context == ^context) |> Repo.delete_all() + + {:ok, activity} + end + + def muted?(user, activity) do + user_id = Pleroma.FlakeId.from_string(user.id) + context = activity.data["context"] + + result = + Ecto.Query.from(m in ThreadMute, + where: m.user_id == ^user_id and m.context == ^context + ) + |> Repo.all() + + case result do + [] -> false + _ -> true + end end end |