diff options
author | Egor Kislitsyn <egor@kislitsyn.com> | 2020-11-11 19:53:40 +0400 |
---|---|---|
committer | Egor Kislitsyn <egor@kislitsyn.com> | 2020-11-11 19:53:40 +0400 |
commit | 08cbd655d14c74ced77e7af2c0acecf554e0ed91 (patch) | |
tree | 4ffb3f3fa62e046e299df0378a56fb52a5b042cb /lib/pleroma/web/common_api.ex | |
parent | e46c95b826c3fb98efa15cf6fd5d6cf2fb9797af (diff) | |
parent | 3cd7ea693fa820c04257b893725100eccf1cc96c (diff) | |
download | pleroma-08cbd655d14c74ced77e7af2c0acecf554e0ed91.tar.gz |
Merge branch 'develop' into frontend-admin-api
Diffstat (limited to 'lib/pleroma/web/common_api.ex')
-rw-r--r-- | lib/pleroma/web/common_api.ex | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index 318ffc5d0..0ab1b115d 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -454,20 +454,46 @@ defmodule Pleroma.Web.CommonAPI do end end - def add_mute(user, activity) do + def add_mute(user, activity, params \\ %{}) do + expires_in = Map.get(params, :expires_in, 0) + with {:ok, _} <- ThreadMute.add_mute(user.id, activity.data["context"]), _ <- Pleroma.Notification.mark_context_as_read(user, activity.data["context"]) do + if expires_in > 0 do + Pleroma.Workers.MuteExpireWorker.enqueue( + "unmute_conversation", + %{"user_id" => user.id, "activity_id" => activity.id}, + schedule_in: expires_in + ) + end + {:ok, activity} else {:error, _} -> {:error, dgettext("errors", "conversation is already muted")} end end - def remove_mute(user, activity) do + def remove_mute(%User{} = user, %Activity{} = activity) do ThreadMute.remove_mute(user.id, activity.data["context"]) {:ok, activity} end + def remove_mute(user_id, activity_id) do + with {:user, %User{} = user} <- {:user, User.get_by_id(user_id)}, + {:activity, %Activity{} = activity} <- {:activity, Activity.get_by_id(activity_id)} do + remove_mute(user, activity) + else + {what, result} = error -> + Logger.warn( + "CommonAPI.remove_mute/2 failed. #{what}: #{result}, user_id: #{user_id}, activity_id: #{ + activity_id + }" + ) + + {:error, error} + end + end + def thread_muted?(%User{id: user_id}, %{data: %{"context" => context}}) when is_binary(context) do ThreadMute.exists?(user_id, context) |