Migration and some boilerplate stuff

This commit is contained in:
Karen Konou 2019-02-05 13:35:24 +01:00
parent 03991e7bc5
commit f4ff4ffba2
4 changed files with 56 additions and 0 deletions

View file

@ -445,6 +445,22 @@ def unbookmark_status(%{assigns: %{user: user}} = conn, %{"id" => id}) 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)

View 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)

View file

@ -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

View file

@ -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