Update the mute implementation to the current codebase
Make it part of the info thing (and do a migration to ensure it's there)
This commit is contained in:
parent
465b547c90
commit
5a46d37af9
6 changed files with 64 additions and 20 deletions
|
|
@ -577,7 +577,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
defp restrict_reblogs(query, _), do: query
|
||||
|
||||
defp restrict_muted(query, %{"muting_user" => %User{info: info}}) do
|
||||
mutes = info["mutes"] || []
|
||||
mutes = info.mutes
|
||||
|
||||
from(
|
||||
activity in query,
|
||||
|
|
|
|||
|
|
@ -769,22 +769,34 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
|||
def mute(%{assigns: %{user: muter}} = conn, %{"id" => id}) do
|
||||
with %User{} = muted <- Repo.get(User, id),
|
||||
{:ok, muter} <- User.mute(muter, muted) do
|
||||
render(conn, AccountView, "relationship.json", %{user: muter, target: muted})
|
||||
conn
|
||||
|> put_view(AccountView)
|
||||
|> render("relationship.json", %{user: muter, target: muted})
|
||||
else
|
||||
{:error, message} ->
|
||||
conn
|
||||
|> put_resp_content_type("application/json")
|
||||
|> send_resp(403, Jason.encode!(%{"error" => message}))
|
||||
end
|
||||
end
|
||||
|
||||
def unmute(%{assigns: %{user: muter}} = conn, %{"id" => id}) do
|
||||
with %User{} = muted <- Repo.get(User, id),
|
||||
{:ok, muter} <- User.unmute(muter, muted) do
|
||||
render(conn, AccountView, "relationship.json", %{user: muter, target: muted})
|
||||
conn
|
||||
|> put_view(AccountView)
|
||||
|> render("relationship.json", %{user: muter, target: muted})
|
||||
else
|
||||
{:error, message} ->
|
||||
conn
|
||||
|> put_resp_content_type("application/json")
|
||||
|> send_resp(403, Jason.encode!(%{"error" => message}))
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: Use proper query
|
||||
def mutes(%{assigns: %{user: user}} = conn, _) do
|
||||
with muted_users <- user.info["mutes"] || [],
|
||||
accounts <- Enum.map(muted_users, fn ap_id -> User.get_cached_by_ap_id(ap_id) end) do
|
||||
res = AccountView.render("accounts.json", users: accounts, for: user, as: :user)
|
||||
with muted_accounts <- User.muted_users(user) do
|
||||
res = AccountView.render("accounts.json", users: muted_accounts, for: user, as: :user)
|
||||
json(conn, res)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
followed_by: User.following?(target, user),
|
||||
blocking: User.blocks?(user, target),
|
||||
muting: User.mutes?(user, target),
|
||||
muting: false,
|
||||
muting_notifications: false,
|
||||
requested: requested,
|
||||
domain_blocking: false,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue