[#1364] Improved control over generation / sending of notifications. Fixed blocking / muting users notifications issue. Added tests.
This commit is contained in:
parent
d84670b9e1
commit
7c8003c3fc
7 changed files with 292 additions and 63 deletions
|
|
@ -9,7 +9,8 @@ defmodule Pleroma.ThreadMute do
|
|||
alias Pleroma.ThreadMute
|
||||
alias Pleroma.User
|
||||
|
||||
require Ecto.Query
|
||||
import Ecto.Changeset
|
||||
import Ecto.Query
|
||||
|
||||
schema "thread_mutes" do
|
||||
belongs_to(:user, User, type: FlakeId.Ecto.CompatType)
|
||||
|
|
@ -18,19 +19,43 @@ defmodule Pleroma.ThreadMute do
|
|||
|
||||
def changeset(mute, params \\ %{}) do
|
||||
mute
|
||||
|> Ecto.Changeset.cast(params, [:user_id, :context])
|
||||
|> Ecto.Changeset.foreign_key_constraint(:user_id)
|
||||
|> Ecto.Changeset.unique_constraint(:user_id, name: :unique_index)
|
||||
|> cast(params, [:user_id, :context])
|
||||
|> foreign_key_constraint(:user_id)
|
||||
|> unique_constraint(:user_id, name: :unique_index)
|
||||
end
|
||||
|
||||
def query(user_id, context) do
|
||||
{:ok, user_id} = FlakeId.Ecto.CompatType.dump(user_id)
|
||||
|
||||
ThreadMute
|
||||
|> Ecto.Query.where(user_id: ^user_id)
|
||||
|> Ecto.Query.where(context: ^context)
|
||||
|> where(user_id: ^user_id)
|
||||
|> where(context: ^context)
|
||||
end
|
||||
|
||||
def muters_query(context) do
|
||||
ThreadMute
|
||||
|> join(:inner, [tm], u in assoc(tm, :user))
|
||||
|> where([tm], tm.context == ^context)
|
||||
|> select([tm, u], u.ap_id)
|
||||
end
|
||||
|
||||
def muter_ap_ids(context, ap_ids \\ nil)
|
||||
|
||||
def muter_ap_ids(context, ap_ids) when context not in [nil, ""] do
|
||||
context
|
||||
|> muters_query()
|
||||
|> maybe_filter_on_ap_id(ap_ids)
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
def muter_ap_ids(_context, _ap_ids), do: []
|
||||
|
||||
defp maybe_filter_on_ap_id(query, ap_ids) when is_list(ap_ids) do
|
||||
where(query, [tm, u], u.ap_id in ^ap_ids)
|
||||
end
|
||||
|
||||
defp maybe_filter_on_ap_id(query, _ap_ids), do: query
|
||||
|
||||
def add_mute(user_id, context) do
|
||||
%ThreadMute{}
|
||||
|> changeset(%{user_id: user_id, context: context})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue