diff options
author | Karen Konou <konoukaren@gmail.com> | 2019-02-11 11:59:51 +0100 |
---|---|---|
committer | Karen Konou <konoukaren@gmail.com> | 2019-02-11 12:04:02 +0100 |
commit | c01ef574c192488c2643a20b4064439757613449 (patch) | |
tree | aab1f1142133e1d789c71092061a9c97a73bee67 /lib/pleroma/web/common_api/common_api.ex | |
parent | cc21fc5f537510416a088adff085b675de1be58e (diff) | |
download | pleroma-c01ef574c192488c2643a20b4064439757613449.tar.gz |
Refactor as per Rin's suggestions, add endpoint tests
Diffstat (limited to 'lib/pleroma/web/common_api/common_api.ex')
-rw-r--r-- | lib/pleroma/web/common_api/common_api.ex | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 7084da6de..7782c64dd 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.CommonAPI do - alias Pleroma.{User, Repo, Activity, Object} + alias Pleroma.{User, Repo, Activity, Object, ThreadMute} alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Formatter @@ -216,4 +216,27 @@ defmodule Pleroma.Web.CommonAPI do {:error, "Could not unpin"} end end + + def add_mute(user, activity) do + with {:ok, _} <- ThreadMute.add_mute(user.id, activity.data["context"]) do + {:ok, activity} + else + {:error, _} -> {:error, "conversation is already muted"} + end + end + + def remove_mute(user, activity) do + ThreadMute.remove_mute(user.id, activity.data["context"]) + {:ok, activity} + end + + def thread_muted?(%{id: nil} = _user, _activity), do: false + + def thread_muted?(user, activity) do + with [] <- ThreadMute.check_muted(user.id, activity.data["context"]) do + false + else + _ -> true + end + end end |