|
|
@ -20,40 +20,42 @@ defmodule Pleroma.Web.ThreadMute do
|
|
|
|
|> Ecto.Changeset.unique_constraint(:user_id, name: :unique_index)
|
|
|
|
|> Ecto.Changeset.unique_constraint(:user_id, name: :unique_index)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def query(user, context) do
|
|
|
|
|
|
|
|
user_id = Pleroma.FlakeId.from_string(user.id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ThreadMute
|
|
|
|
|
|
|
|
|> Ecto.Query.where(user_id: ^user_id)
|
|
|
|
|
|
|
|
|> Ecto.Query.where(context: ^context)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def add_mute(user, id) do
|
|
|
|
def add_mute(user, id) do
|
|
|
|
activity = Activity.get_by_id(id)
|
|
|
|
activity = Activity.get_by_id(id)
|
|
|
|
context = activity.data["context"]
|
|
|
|
|
|
|
|
changeset = changeset(%Pleroma.Web.ThreadMute{}, %{user_id: user.id, context: context})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case Repo.insert(changeset) do
|
|
|
|
with changeset <-
|
|
|
|
{:ok, _} -> {:ok, activity}
|
|
|
|
changeset(%ThreadMute{}, %{user_id: user.id, context: activity.data["context"]}),
|
|
|
|
|
|
|
|
{:ok, _} <- Repo.insert(changeset) do
|
|
|
|
|
|
|
|
{:ok, activity}
|
|
|
|
|
|
|
|
else
|
|
|
|
{:error, _} -> {:error, "conversation is already muted"}
|
|
|
|
{:error, _} -> {:error, "conversation is already muted"}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def remove_mute(user, id) do
|
|
|
|
def remove_mute(user, id) do
|
|
|
|
user_id = Pleroma.FlakeId.from_string(user.id)
|
|
|
|
|
|
|
|
activity = Activity.get_by_id(id)
|
|
|
|
activity = Activity.get_by_id(id)
|
|
|
|
context = activity.data["context"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ecto.Query.from(m in ThreadMute, where: m.user_id == ^user_id and m.context == ^context)
|
|
|
|
query(user, activity.data["context"])
|
|
|
|
|> Repo.delete_all()
|
|
|
|
|> Repo.delete_all()
|
|
|
|
|
|
|
|
|
|
|
|
{:ok, activity}
|
|
|
|
{:ok, activity}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def muted?(user, activity) do
|
|
|
|
def muted?(%{id: nil} = _user, _), do: false
|
|
|
|
user_id = Pleroma.FlakeId.from_string(user.id)
|
|
|
|
|
|
|
|
context = activity.data["context"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result =
|
|
|
|
def muted?(user, activity) do
|
|
|
|
Ecto.Query.from(m in ThreadMute,
|
|
|
|
with query <- query(user, activity.data["context"]),
|
|
|
|
where: m.user_id == ^user_id and m.context == ^context
|
|
|
|
[] <- Repo.all(query) do
|
|
|
|
)
|
|
|
|
false
|
|
|
|
|> Repo.all()
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
|
|
case result do
|
|
|
|
|
|
|
|
[] -> false
|
|
|
|
|
|
|
|
_ -> true
|
|
|
|
_ -> true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|