From: Karen Konou Date: Mon, 11 Feb 2019 11:10:10 +0000 (+0100) Subject: Merge branch 'develop' into feature/thread-muting X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=ac72b578da673282b927b945bfe03cd3012444b6;p=akkoma Merge branch 'develop' into feature/thread-muting --- ac72b578da673282b927b945bfe03cd3012444b6 diff --cc lib/pleroma/notification.ex index 9ebfd5cb0,c7c925c89..c88512567 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@@ -4,9 -4,13 +4,14 @@@ defmodule Pleroma.Notification do use Ecto.Schema - alias Pleroma.{User, Activity, Notification, Repo} + + alias Pleroma.User + alias Pleroma.Activity + alias Pleroma.Notification + alias Pleroma.Repo alias Pleroma.Web.CommonAPI.Utils + alias Pleroma.Web.CommonAPI + import Ecto.Query schema "notifications" do diff --cc lib/pleroma/web/common_api/common_api.ex index 7782c64dd,c0d6fb5c4..86f249c54 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@@ -3,7 -3,10 +3,11 @@@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.CommonAPI do - alias Pleroma.{User, Repo, Activity, Object, ThreadMute} + alias Pleroma.User + alias Pleroma.Repo + alias Pleroma.Activity + alias Pleroma.Object ++ alias Pleroma.ThreadMute alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Formatter diff --cc lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 18fa16b03,06f870393..dcaeccac6 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@@ -445,29 -456,6 +456,31 @@@ defmodule Pleroma.Web.MastodonAPI.Masto end end + def mute_conversation(%{assigns: %{user: user}} = conn, %{"id" => id}) do + activity = Activity.get_by_id(id) ++ + with {:ok, activity} <- CommonAPI.add_mute(user, activity) do + conn + |> put_view(StatusView) + |> try_render("status.json", %{activity: activity, for: user, as: :activity}) + else + {:error, reason} -> + conn + |> put_resp_content_type("application/json") + |> send_resp(:bad_request, Jason.encode!(%{"error" => reason})) + end + end + + def unmute_conversation(%{assigns: %{user: user}} = conn, %{"id" => id}) do + activity = Activity.get_by_id(id) ++ + with {:ok, activity} <- CommonAPI.remove_mute(user, activity) do + conn + |> put_view(StatusView) + |> try_render("status.json", %{activity: activity, for: user, as: :activity}) + end + end + def notifications(%{assigns: %{user: user}} = conn, params) do notifications = Notification.for_user(user, params) diff --cc lib/pleroma/web/mastodon_api/views/status_view.ex index 368b79ea7,f51a2ebb0..69f5f992c --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@@ -9,11 -9,10 +9,11 @@@ defmodule Pleroma.Web.MastodonAPI.Statu alias Pleroma.HTML alias Pleroma.Repo alias Pleroma.User + alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI.Utils - alias Pleroma.Web.MediaProxy alias Pleroma.Web.MastodonAPI.AccountView alias Pleroma.Web.MastodonAPI.StatusView + alias Pleroma.Web.MediaProxy # TODO: Add cached version. defp get_replied_to_activities(activities) do diff --cc test/web/mastodon_api/mastodon_api_controller_test.exs index f7c059663,f8da86004..1a60ad8e6 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@@ -1749,37 -1749,4 +1749,36 @@@ defmodule Pleroma.Web.MastodonAPI.Masto assert [json_response(response2, 200)] == json_response(bookmarks, 200) end + + describe "conversation muting" do + setup do - + user = insert(:user) + {:ok, activity} = CommonAPI.post(user, %{"status" => "HIE"}) + + [user: user, activity: activity] + end + + test "mute conversation", %{conn: conn, user: user, activity: activity} do + id_str = to_string(activity.id) + + assert %{"id" => ^id_str, "muted" => true} = + conn + |> assign(:user, user) + |> post("/api/v1/statuses/#{activity.id}/mute") + |> json_response(200) + end + + test "unmute conversation", %{conn: conn, user: user, activity: activity} do + {:ok, _} = CommonAPI.add_mute(user, activity) + + id_str = to_string(activity.id) + user = refresh_record(user) + + assert %{"id" => ^id_str, "muted" => false} = + conn + |> assign(:user, user) + |> post("/api/v1/statuses/#{activity.id}/unmute") + |> json_response(200) + end + end end