aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/thread_mute.ex16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/pleroma/web/thread_mute.ex b/lib/pleroma/web/thread_mute.ex
index 146de0d80..b5bff86be 100644
--- a/lib/pleroma/web/thread_mute.ex
+++ b/lib/pleroma/web/thread_mute.ex
@@ -13,12 +13,22 @@ defmodule Pleroma.Web.ThreadMute do
field(:context, :string)
end
+ def changeset(mute, params \\ %{}) do
+ mute
+ |> Ecto.Changeset.cast(params, [:user_id, :context])
+ |> Ecto.Changeset.foreign_key_constraint(:user_id)
+ |> Ecto.Changeset.unique_constraint(:user_id, name: :unique_index)
+ end
+
def add_mute(user, id) do
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}
+ changeset = changeset(%Pleroma.Web.ThreadMute{}, %{user_id: user.id, context: context})
+
+ case Repo.insert(changeset) do
+ {:ok, _} -> {:ok, activity}
+ {:error, _} -> {:error, "conversation is already muted"}
+ end
end
def remove_mute(user, id) do