Refactor mutes removing in CommonAPI and User
This commit is contained in:
parent
4987ee6256
commit
28d0986f83
@ -1385,6 +1385,20 @@ defmodule Pleroma.User do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def unmute(muter_id, mutee_id) do
|
||||||
|
with {:muter, %User{} = muter} <- {:muter, User.get_by_id(muter_id)},
|
||||||
|
{:mutee, %User{} = mutee} <- {:mutee, User.get_by_id(mutee_id)} do
|
||||||
|
unmute(muter, mutee)
|
||||||
|
else
|
||||||
|
{who, result} = error ->
|
||||||
|
Logger.warn(
|
||||||
|
"User.unmute/2 failed. #{who}: #{result}, muter_id: #{muter_id}, mutee_id: #{mutee_id}"
|
||||||
|
)
|
||||||
|
|
||||||
|
{:error, error}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def subscribe(%User{} = subscriber, %User{} = target) do
|
def subscribe(%User{} = subscriber, %User{} = target) do
|
||||||
deny_follow_blocked = Config.get([:user, :deny_follow_blocked])
|
deny_follow_blocked = Config.get([:user, :deny_follow_blocked])
|
||||||
|
|
||||||
|
@ -472,11 +472,27 @@ defmodule Pleroma.Web.CommonAPI do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_mute(user, activity) do
|
def remove_mute(%User{} = user, %Activity{} = activity) do
|
||||||
ThreadMute.remove_mute(user.id, activity.data["context"])
|
ThreadMute.remove_mute(user.id, activity.data["context"])
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def remove_mute(user_id, activity_id) do
|
||||||
|
with {:user, %User{} = user} <- {:user, User.get_by_id(user_id)},
|
||||||
|
{:activity, %Activity{} = activity} <- {:activity, Activity.get_by_id(activity_id)} do
|
||||||
|
remove_mute(user, activity)
|
||||||
|
else
|
||||||
|
{what, result} = error ->
|
||||||
|
Logger.warn(
|
||||||
|
"CommonAPI.remove_mute/2 failed. #{what}: #{result}, user_id: #{user_id}, activity_id: #{
|
||||||
|
activity_id
|
||||||
|
}"
|
||||||
|
)
|
||||||
|
|
||||||
|
{:error, error}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def thread_muted?(%User{id: user_id}, %{data: %{"context" => context}})
|
def thread_muted?(%User{id: user_id}, %{data: %{"context" => context}})
|
||||||
when is_binary(context) do
|
when is_binary(context) do
|
||||||
ThreadMute.exists?(user_id, context)
|
ThreadMute.exists?(user_id, context)
|
||||||
|
@ -7,18 +7,14 @@ defmodule Pleroma.Workers.MuteExpireWorker do
|
|||||||
|
|
||||||
@impl Oban.Worker
|
@impl Oban.Worker
|
||||||
def perform(%Job{args: %{"op" => "unmute_user", "muter_id" => muter_id, "mutee_id" => mutee_id}}) do
|
def perform(%Job{args: %{"op" => "unmute_user", "muter_id" => muter_id, "mutee_id" => mutee_id}}) do
|
||||||
muter = Pleroma.User.get_by_id(muter_id)
|
Pleroma.User.unmute(muter_id, mutee_id)
|
||||||
mutee = Pleroma.User.get_by_id(mutee_id)
|
|
||||||
Pleroma.User.unmute(muter, mutee)
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform(%Job{
|
def perform(%Job{
|
||||||
args: %{"op" => "unmute_conversation", "user_id" => user_id, "activity_id" => activity_id}
|
args: %{"op" => "unmute_conversation", "user_id" => user_id, "activity_id" => activity_id}
|
||||||
}) do
|
}) do
|
||||||
user = Pleroma.User.get_by_id(user_id)
|
Pleroma.Web.CommonAPI.remove_mute(user_id, activity_id)
|
||||||
activity = Pleroma.Activity.get_by_id(activity_id)
|
|
||||||
Pleroma.Web.CommonAPI.remove_mute(user, activity)
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1034,6 +1034,17 @@ defmodule Pleroma.UserTest do
|
|||||||
refute User.muted_notifications?(user, muted_user)
|
refute User.muted_notifications?(user, muted_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it unmutes users by id" do
|
||||||
|
user = insert(:user)
|
||||||
|
muted_user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, _user_relationships} = User.mute(user, muted_user)
|
||||||
|
{:ok, _user_mute} = User.unmute(user.id, muted_user.id)
|
||||||
|
|
||||||
|
refute User.mutes?(user, muted_user)
|
||||||
|
refute User.muted_notifications?(user, muted_user)
|
||||||
|
end
|
||||||
|
|
||||||
test "it mutes user without notifications" do
|
test "it mutes user without notifications" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
muted_user = insert(:user)
|
muted_user = insert(:user)
|
||||||
|
@ -913,6 +913,12 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||||||
refute CommonAPI.thread_muted?(user, activity)
|
refute CommonAPI.thread_muted?(user, activity)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "remove mute by ids", %{user: user, activity: activity} do
|
||||||
|
CommonAPI.add_mute(user, activity)
|
||||||
|
{:ok, _} = CommonAPI.remove_mute(user.id, activity.id)
|
||||||
|
refute CommonAPI.thread_muted?(user, activity)
|
||||||
|
end
|
||||||
|
|
||||||
test "check that mutes can't be duplicate", %{user: user, activity: activity} do
|
test "check that mutes can't be duplicate", %{user: user, activity: activity} do
|
||||||
CommonAPI.add_mute(user, activity)
|
CommonAPI.add_mute(user, activity)
|
||||||
{:error, _} = CommonAPI.add_mute(user, activity)
|
{:error, _} = CommonAPI.add_mute(user, activity)
|
||||||
|
Loading…
Reference in New Issue
Block a user