Migration and some boilerplate stuff
authorKaren Konou <konoukaren@gmail.com>
Tue, 5 Feb 2019 12:35:24 +0000 (13:35 +0100)
committerKaren Konou <konoukaren@gmail.com>
Thu, 7 Feb 2019 16:36:14 +0000 (17:36 +0100)
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
lib/pleroma/web/router.ex
lib/pleroma/web/thread_mute.ex [new file with mode: 0644]
priv/repo/migrations/20190205114625_create_thread_mutes.exs [new file with mode: 0644]

index 7f3fbff4aad9aa93e299de55345f5f220dafb125..00b39d76b2fd051fed0d41c0dc4fae4744bce9b8 100644 (file)
@@ -445,6 +445,22 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
     end
   end
 
+  def mute_conversation(%{assigns: %{user: user}} = conn, %{"id" => id}) do
+    with {:ok, activity} <- Pleroma.Web.ThreadMute.add_mute(user, id) do
+      conn
+      |> put_view(StatusView)
+      |> try_render("status.json", %{activity: activity, for: user, as: :activity})
+    end
+  end
+
+  def unmute_conversation(%{assigns: %{user: user}} = conn, %{"id" => id}) do
+    with {:ok, activity} <- Pleroma.Web.ThreadMute.remove_mute(user, id) 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)
 
index c6b4d37ab8eddb24c442c7530498218d3b8a177d..3f9759ca915c8a24ad04746351bac3d0b9f70b8a 100644 (file)
@@ -198,6 +198,8 @@ defmodule Pleroma.Web.Router do
     post("/statuses/:id/unpin", MastodonAPIController, :unpin_status)
     post("/statuses/:id/bookmark", MastodonAPIController, :bookmark_status)
     post("/statuses/:id/unbookmark", MastodonAPIController, :unbookmark_status)
+    post("/statuses/:id/mute", MastodonAPIController, :mute_conversation)
+    post("/statuses/:id/unmute", MastodonAPIController, :unmute_conversation)
 
     post("/notifications/clear", MastodonAPIController, :clear_notifications)
     post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
diff --git a/lib/pleroma/web/thread_mute.ex b/lib/pleroma/web/thread_mute.ex
new file mode 100644 (file)
index 0000000..8892155
--- /dev/null
@@ -0,0 +1,26 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ThreadMute do
+  use Ecto.Schema
+
+  alias Pleroma.{Activity, Notification, User}
+
+  schema "thread_mutes" do
+    field(:user_id, :string)
+    field(:context, :string)
+  end
+
+  def add_mute(user, id) do
+    %{id: user_id} = user
+    %{data: %{"context" => context}} = Activity.get_by_id(id)
+    Pleroma.Repo.insert(%Pleroma.Web.ThreadMute{user_id: user_id, context: context})
+  end
+
+  def remove_mute(user, id) do
+  end
+
+  def mute_thread() do
+  end
+end
diff --git a/priv/repo/migrations/20190205114625_create_thread_mutes.exs b/priv/repo/migrations/20190205114625_create_thread_mutes.exs
new file mode 100644 (file)
index 0000000..b16f557
--- /dev/null
@@ -0,0 +1,12 @@
+defmodule Pleroma.Repo.Migrations.CreateThreadMutes do
+  use Ecto.Migration
+
+  def change do
+    create table(:thread_mutes) do
+      add :user_id, references(:users, type: :uuid, on_delete: :delete_all)
+      add :context, :string
+    end
+    
+    create index(:thread_mutes, [:user_id])
+  end
+end