[#1335] Implemented notification mutes and reblog mutes as UserRelationships. User to UserRelationship relations and functions refactoring.
This commit is contained in:
parent
3aaf3aa2c2
commit
ba5cc30165
21 changed files with 203 additions and 229 deletions
|
@ -60,7 +60,7 @@ def for_user_query(user, opts \\ []) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp exclude_blocked(query, user) do
|
defp exclude_blocked(query, user) do
|
||||||
blocked_ap_ids = User.blocked_ap_ids(user)
|
blocked_ap_ids = User.blocked_users_ap_ids(user)
|
||||||
|
|
||||||
query
|
query
|
||||||
|> where([n, a], a.actor not in ^blocked_ap_ids)
|
|> where([n, a], a.actor not in ^blocked_ap_ids)
|
||||||
|
@ -75,8 +75,10 @@ defp exclude_muted(query, _, %{with_muted: true}) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp exclude_muted(query, user, _opts) do
|
defp exclude_muted(query, user, _opts) do
|
||||||
|
notification_muted_ap_ids = User.notification_muted_users_ap_ids(user)
|
||||||
|
|
||||||
query
|
query
|
||||||
|> where([n, a], a.actor not in ^user.muted_notifications)
|
|> where([n, a], a.actor not in ^notification_muted_ap_ids)
|
||||||
|> join(:left, [n, a], tm in Pleroma.ThreadMute,
|
|> join(:left, [n, a], tm in Pleroma.ThreadMute,
|
||||||
on: tm.user_id == ^user.id and tm.context == fragment("?->>'context'", a.data)
|
on: tm.user_id == ^user.id and tm.context == fragment("?->>'context'", a.data)
|
||||||
)
|
)
|
||||||
|
|
|
@ -44,6 +44,20 @@ defmodule Pleroma.User do
|
||||||
@strict_local_nickname_regex ~r/^[a-zA-Z\d]+$/
|
@strict_local_nickname_regex ~r/^[a-zA-Z\d]+$/
|
||||||
@extended_local_nickname_regex ~r/^[a-zA-Z\d_-]+$/
|
@extended_local_nickname_regex ~r/^[a-zA-Z\d_-]+$/
|
||||||
|
|
||||||
|
# Format: [rel_type: [outgoing_rel: :outgoing_rel_target, incoming_rel: :incoming_rel_source]]
|
||||||
|
@user_relationships_config [
|
||||||
|
block: [blocker_blocks: :blocked_users, blockee_blocks: :blocker_users],
|
||||||
|
mute: [muter_mutes: :muted_users, mutee_mutes: :muter_users],
|
||||||
|
reblog_mute: [
|
||||||
|
reblog_muter_mutes: :reblog_muted_users,
|
||||||
|
reblog_mutee_mutes: :reblog_muter_users
|
||||||
|
],
|
||||||
|
notification_mute: [
|
||||||
|
notification_muter_mutes: :notification_muted_users,
|
||||||
|
notification_mutee_mutes: :notification_muter_users
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
schema "users" do
|
schema "users" do
|
||||||
field(:bio, :string)
|
field(:bio, :string)
|
||||||
field(:email, :string)
|
field(:email, :string)
|
||||||
|
@ -63,7 +77,6 @@ defmodule Pleroma.User do
|
||||||
field(:tags, {:array, :string}, default: [])
|
field(:tags, {:array, :string}, default: [])
|
||||||
field(:last_refreshed_at, :naive_datetime_usec)
|
field(:last_refreshed_at, :naive_datetime_usec)
|
||||||
field(:last_digest_emailed_at, :naive_datetime)
|
field(:last_digest_emailed_at, :naive_datetime)
|
||||||
|
|
||||||
field(:banner, :map, default: %{})
|
field(:banner, :map, default: %{})
|
||||||
field(:background, :map, default: %{})
|
field(:background, :map, default: %{})
|
||||||
field(:source_data, :map, default: %{})
|
field(:source_data, :map, default: %{})
|
||||||
|
@ -77,8 +90,6 @@ defmodule Pleroma.User do
|
||||||
field(:confirmation_token, :string, default: nil)
|
field(:confirmation_token, :string, default: nil)
|
||||||
field(:default_scope, :string, default: "public")
|
field(:default_scope, :string, default: "public")
|
||||||
field(:domain_blocks, {:array, :string}, default: [])
|
field(:domain_blocks, {:array, :string}, default: [])
|
||||||
field(:muted_reblogs, {:array, :string}, default: [])
|
|
||||||
field(:muted_notifications, {:array, :string}, default: [])
|
|
||||||
field(:subscribers, {:array, :string}, default: [])
|
field(:subscribers, {:array, :string}, default: [])
|
||||||
field(:deactivated, :boolean, default: false)
|
field(:deactivated, :boolean, default: false)
|
||||||
field(:no_rich_text, :boolean, default: false)
|
field(:no_rich_text, :boolean, default: false)
|
||||||
|
@ -122,31 +133,29 @@ defmodule Pleroma.User do
|
||||||
has_many(:outgoing_relationships, UserRelationship, foreign_key: :source_id)
|
has_many(:outgoing_relationships, UserRelationship, foreign_key: :source_id)
|
||||||
has_many(:incoming_relationships, UserRelationship, foreign_key: :target_id)
|
has_many(:incoming_relationships, UserRelationship, foreign_key: :target_id)
|
||||||
|
|
||||||
has_many(:blocker_blocks, UserRelationship,
|
for {relationship_type,
|
||||||
|
[
|
||||||
|
{outgoing_relation, outgoing_relation_target},
|
||||||
|
{incoming_relation, incoming_relation_source}
|
||||||
|
]} <- @user_relationships_config do
|
||||||
|
# Definitions of `has_many :blocker_blocks`, `has_many :muter_mutes` etc.
|
||||||
|
has_many(outgoing_relation, UserRelationship,
|
||||||
foreign_key: :source_id,
|
foreign_key: :source_id,
|
||||||
where: [relationship_type: :block]
|
where: [relationship_type: relationship_type]
|
||||||
)
|
)
|
||||||
|
|
||||||
has_many(:blockee_blocks, UserRelationship,
|
# Definitions of `has_many :blockee_blocks`, `has_many :mutee_mutes` etc.
|
||||||
|
has_many(incoming_relation, UserRelationship,
|
||||||
foreign_key: :target_id,
|
foreign_key: :target_id,
|
||||||
where: [relationship_type: :block]
|
where: [relationship_type: relationship_type]
|
||||||
)
|
)
|
||||||
|
|
||||||
has_many(:blocked_users, through: [:blocker_blocks, :target])
|
# Definitions of `has_many :blocked_users`, `has_many :muted_users` etc.
|
||||||
has_many(:blocker_users, through: [:blockee_blocks, :source])
|
has_many(outgoing_relation_target, through: [outgoing_relation, :target])
|
||||||
|
|
||||||
has_many(:muter_mutes, UserRelationship,
|
# Definitions of `has_many :blocker_users`, `has_many :muter_users` etc.
|
||||||
foreign_key: :source_id,
|
has_many(incoming_relation_source, through: [incoming_relation, :source])
|
||||||
where: [relationship_type: :mute]
|
end
|
||||||
)
|
|
||||||
|
|
||||||
has_many(:mutee_mutes, UserRelationship,
|
|
||||||
foreign_key: :target_id,
|
|
||||||
where: [relationship_type: :mute]
|
|
||||||
)
|
|
||||||
|
|
||||||
has_many(:muted_users, through: [:muter_mutes, :target])
|
|
||||||
has_many(:muter_users, through: [:mutee_mutes, :source])
|
|
||||||
|
|
||||||
field(:info, :map, default: %{})
|
field(:info, :map, default: %{})
|
||||||
|
|
||||||
|
@ -154,10 +163,49 @@ defmodule Pleroma.User do
|
||||||
field(:blocks, {:array, :string}, default: [])
|
field(:blocks, {:array, :string}, default: [])
|
||||||
# `:mutes` is deprecated (replaced with `muted_users` relation)
|
# `:mutes` is deprecated (replaced with `muted_users` relation)
|
||||||
field(:mutes, {:array, :string}, default: [])
|
field(:mutes, {:array, :string}, default: [])
|
||||||
|
# `:muted_reblogs` is deprecated (replaced with `reblog_muted_users` relation)
|
||||||
|
field(:muted_reblogs, {:array, :string}, default: [])
|
||||||
|
# `:muted_notifications` is deprecated (replaced with `notification_muted_users` relation)
|
||||||
|
field(:muted_notifications, {:array, :string}, default: [])
|
||||||
|
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for {_relationship_type, [{_outgoing_relation, outgoing_relation_target}, _]} <-
|
||||||
|
@user_relationships_config do
|
||||||
|
# Definitions of `blocked_users_relation/1`, `muted_users_relation/1`, etc.
|
||||||
|
def unquote(:"#{outgoing_relation_target}_relation")(user, restrict_deactivated? \\ false) do
|
||||||
|
target_users_query = assoc(user, unquote(outgoing_relation_target))
|
||||||
|
|
||||||
|
if restrict_deactivated? do
|
||||||
|
restrict_deactivated(target_users_query)
|
||||||
|
else
|
||||||
|
target_users_query
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Definitions of `blocked_users/1`, `muted_users/1`, etc.
|
||||||
|
def unquote(outgoing_relation_target)(user, restrict_deactivated? \\ false) do
|
||||||
|
__MODULE__
|
||||||
|
|> apply(unquote(:"#{outgoing_relation_target}_relation"), [
|
||||||
|
user,
|
||||||
|
restrict_deactivated?
|
||||||
|
])
|
||||||
|
|> Repo.all()
|
||||||
|
end
|
||||||
|
|
||||||
|
# Definitions of `blocked_users_ap_ids/1`, `muted_users_ap_ids/1`, etc.
|
||||||
|
def unquote(:"#{outgoing_relation_target}_ap_ids")(user, restrict_deactivated? \\ false) do
|
||||||
|
__MODULE__
|
||||||
|
|> apply(unquote(:"#{outgoing_relation_target}_relation"), [
|
||||||
|
user,
|
||||||
|
restrict_deactivated?
|
||||||
|
])
|
||||||
|
|> select([u], u.ap_id)
|
||||||
|
|> Repo.all()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@doc "Returns if the user should be allowed to authenticate"
|
@doc "Returns if the user should be allowed to authenticate"
|
||||||
def auth_active?(%User{deactivated: true}), do: false
|
def auth_active?(%User{deactivated: true}), do: false
|
||||||
|
|
||||||
|
@ -996,7 +1044,8 @@ def get_recipients_from_activity(%Activity{recipients: to}) do
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec mute(User.t(), User.t(), boolean()) :: {:ok, User.t()} | {:error, String.t()}
|
@spec mute(User.t(), User.t(), boolean()) ::
|
||||||
|
{:ok, list(UserRelationship.t())} | {:error, String.t()}
|
||||||
def mute(muter, %User{} = mutee, notifications? \\ true) do
|
def mute(muter, %User{} = mutee, notifications? \\ true) do
|
||||||
add_to_mutes(muter, mutee, notifications?)
|
add_to_mutes(muter, mutee, notifications?)
|
||||||
end
|
end
|
||||||
|
@ -1079,8 +1128,8 @@ def mutes_user?(%User{} = user, %User{} = target) do
|
||||||
@spec muted_notifications?(User.t() | nil, User.t() | map()) :: boolean()
|
@spec muted_notifications?(User.t() | nil, User.t() | map()) :: boolean()
|
||||||
def muted_notifications?(nil, _), do: false
|
def muted_notifications?(nil, _), do: false
|
||||||
|
|
||||||
def muted_notifications?(user, %{ap_id: ap_id}),
|
def muted_notifications?(user, %User{} = target),
|
||||||
do: Enum.member?(user.muted_notifications, ap_id)
|
do: UserRelationship.notification_mute_exists?(user, target)
|
||||||
|
|
||||||
def blocks?(nil, _), do: false
|
def blocks?(nil, _), do: false
|
||||||
|
|
||||||
|
@ -1108,42 +1157,13 @@ def subscribed_to?(user, %{ap_id: ap_id}) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec muted_users(User.t()) :: [User.t()]
|
|
||||||
def muted_users(user) do
|
|
||||||
user
|
|
||||||
|> assoc(:muted_users)
|
|
||||||
|> restrict_deactivated()
|
|
||||||
|> Repo.all()
|
|
||||||
end
|
|
||||||
|
|
||||||
def muted_ap_ids(user) do
|
|
||||||
user
|
|
||||||
|> assoc(:muted_users)
|
|
||||||
|> select([u], u.ap_id)
|
|
||||||
|> Repo.all()
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec blocked_users(User.t()) :: [User.t()]
|
|
||||||
def blocked_users(user) do
|
|
||||||
user
|
|
||||||
|> assoc(:blocked_users)
|
|
||||||
|> restrict_deactivated()
|
|
||||||
|> Repo.all()
|
|
||||||
end
|
|
||||||
|
|
||||||
def blocked_ap_ids(user) do
|
|
||||||
user
|
|
||||||
|> assoc(:blocked_users)
|
|
||||||
|> select([u], u.ap_id)
|
|
||||||
|> Repo.all()
|
|
||||||
end
|
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Returns map of related AP IDs list by relation type.
|
Returns map of related AP IDs list by relation type.
|
||||||
E.g. `related_ap_ids(user, [:blocks])` -> `%{blocks: ["https://some.site/users/userapid"]}`
|
E.g. `related_ap_ids(user, [:block])` -> `%{block: ["https://some.site/users/userapid"]}`
|
||||||
"""
|
"""
|
||||||
@spec related_ap_ids(User.t(), list(atom())) :: %{atom() => list(String.t())}
|
@spec related_ap_ids(User.t(), list(atom())) :: %{atom() => list(String.t())}
|
||||||
def related_ap_ids(%User{} = user, relationship_types) when is_list(relationship_types) do
|
def related_ap_ids(%User{} = user, relationship_types) when is_list(relationship_types) do
|
||||||
|
db_result =
|
||||||
user
|
user
|
||||||
|> assoc(:outgoing_relationships)
|
|> assoc(:outgoing_relationships)
|
||||||
|> join(:inner, [user_rel], u in assoc(user_rel, :target))
|
|> join(:inner, [user_rel], u in assoc(user_rel, :target))
|
||||||
|
@ -1152,6 +1172,12 @@ def related_ap_ids(%User{} = user, relationship_types) when is_list(relationship
|
||||||
|> group_by([user_rel, u], user_rel.relationship_type)
|
|> group_by([user_rel, u], user_rel.relationship_type)
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|> Enum.into(%{}, fn [k, v] -> {k, v} end)
|
|> Enum.into(%{}, fn [k, v] -> {k, v} end)
|
||||||
|
|
||||||
|
Enum.into(
|
||||||
|
relationship_types,
|
||||||
|
%{},
|
||||||
|
fn rel_type -> {rel_type, db_result[rel_type] || []} end
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec subscribers(User.t()) :: [User.t()]
|
@spec subscribers(User.t()) :: [User.t()]
|
||||||
|
@ -1572,7 +1598,7 @@ def all_superusers do
|
||||||
end
|
end
|
||||||
|
|
||||||
def showing_reblogs?(%User{} = user, %User{} = target) do
|
def showing_reblogs?(%User{} = user, %User{} = target) do
|
||||||
target.ap_id not in user.muted_reblogs
|
not UserRelationship.reblog_mute_exists?(user, target)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
@ -1936,59 +1962,23 @@ defp remove_from_block(%User{} = user, %User{} = blocked) do
|
||||||
UserRelationship.delete_block(user, blocked)
|
UserRelationship.delete_block(user, blocked)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp add_to_mutes(%User{} = user, %User{ap_id: ap_id} = muted_user, notifications?) do
|
defp add_to_mutes(%User{} = user, %User{} = muted_user, notifications?) do
|
||||||
with {:ok, user_mute} <- UserRelationship.create_mute(user, muted_user),
|
with {:ok, user_mute} <- UserRelationship.create_mute(user, muted_user),
|
||||||
{:ok, _user} <-
|
{:ok, user_notification_mute} <-
|
||||||
set_notification_mutes(
|
(notifications? && UserRelationship.create_notification_mute(user, muted_user)) ||
|
||||||
user,
|
{:ok, nil} do
|
||||||
Enum.uniq([ap_id | user.muted_notifications]),
|
{:ok, Enum.filter([user_mute, user_notification_mute], & &1)}
|
||||||
notifications?
|
|
||||||
) do
|
|
||||||
{:ok, user_mute}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp remove_from_mutes(user, %User{ap_id: ap_id} = muted_user) do
|
defp remove_from_mutes(user, %User{} = muted_user) do
|
||||||
with {:ok, user_mute} <- UserRelationship.delete_mute(user, muted_user),
|
with {:ok, user_mute} <- UserRelationship.delete_mute(user, muted_user),
|
||||||
{:ok, _user} <-
|
{:ok, user_notification_mute} <-
|
||||||
set_notification_mutes(
|
UserRelationship.delete_notification_mute(user, muted_user) do
|
||||||
user,
|
{:ok, [user_mute, user_notification_mute]}
|
||||||
List.delete(user.muted_notifications, ap_id),
|
|
||||||
true
|
|
||||||
) do
|
|
||||||
{:ok, user_mute}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp set_notification_mutes(user, _muted_notifications, false = _notifications?) do
|
|
||||||
{:ok, user}
|
|
||||||
end
|
|
||||||
|
|
||||||
defp set_notification_mutes(user, muted_notifications, true = _notifications?) do
|
|
||||||
params = %{muted_notifications: muted_notifications}
|
|
||||||
|
|
||||||
user
|
|
||||||
|> cast(params, [:muted_notifications])
|
|
||||||
|> validate_required([:muted_notifications])
|
|
||||||
|> update_and_set_cache()
|
|
||||||
end
|
|
||||||
|
|
||||||
def add_reblog_mute(user, ap_id) do
|
|
||||||
params = %{muted_reblogs: user.muted_reblogs ++ [ap_id]}
|
|
||||||
|
|
||||||
user
|
|
||||||
|> cast(params, [:muted_reblogs])
|
|
||||||
|> update_and_set_cache()
|
|
||||||
end
|
|
||||||
|
|
||||||
def remove_reblog_mute(user, ap_id) do
|
|
||||||
params = %{muted_reblogs: List.delete(user.muted_reblogs, ap_id)}
|
|
||||||
|
|
||||||
user
|
|
||||||
|> cast(params, [:muted_reblogs])
|
|
||||||
|> update_and_set_cache()
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_invisible(user, invisible) do
|
def set_invisible(user, invisible) do
|
||||||
params = %{invisible: invisible}
|
params = %{invisible: invisible}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,20 @@ defmodule Pleroma.UserRelationship do
|
||||||
timestamps(updated_at: false)
|
timestamps(updated_at: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for relationship_type <- Keyword.keys(UserRelationshipTypeEnum.__enum_map__()) do
|
||||||
|
# Definitions of `create_block/2`, `create_mute/2` etc.
|
||||||
|
def unquote(:"create_#{relationship_type}")(source, target),
|
||||||
|
do: create(unquote(relationship_type), source, target)
|
||||||
|
|
||||||
|
# Definitions of `delete_block/2`, `delete_mute/2` etc.
|
||||||
|
def unquote(:"delete_#{relationship_type}")(source, target),
|
||||||
|
do: delete(unquote(relationship_type), source, target)
|
||||||
|
|
||||||
|
# Definitions of `block_exists?/2`, `mute_exists?/2` etc.
|
||||||
|
def unquote(:"#{relationship_type}_exists?")(source, target),
|
||||||
|
do: exists?(unquote(relationship_type), source, target)
|
||||||
|
end
|
||||||
|
|
||||||
def changeset(%UserRelationship{} = user_relationship, params \\ %{}) do
|
def changeset(%UserRelationship{} = user_relationship, params \\ %{}) do
|
||||||
user_relationship
|
user_relationship
|
||||||
|> cast(params, [:relationship_type, :source_id, :target_id])
|
|> cast(params, [:relationship_type, :source_id, :target_id])
|
||||||
|
@ -36,10 +50,6 @@ def exists?(relationship_type, %User{} = source, %User{} = target) do
|
||||||
|> Repo.exists?()
|
|> Repo.exists?()
|
||||||
end
|
end
|
||||||
|
|
||||||
def block_exists?(%User{} = blocker, %User{} = blockee), do: exists?(:block, blocker, blockee)
|
|
||||||
|
|
||||||
def mute_exists?(%User{} = muter, %User{} = mutee), do: exists?(:mute, muter, mutee)
|
|
||||||
|
|
||||||
def create(relationship_type, %User{} = source, %User{} = target) do
|
def create(relationship_type, %User{} = source, %User{} = target) do
|
||||||
%UserRelationship{}
|
%UserRelationship{}
|
||||||
|> changeset(%{
|
|> changeset(%{
|
||||||
|
@ -53,10 +63,6 @@ def create(relationship_type, %User{} = source, %User{} = target) do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_block(%User{} = blocker, %User{} = blockee), do: create(:block, blocker, blockee)
|
|
||||||
|
|
||||||
def create_mute(%User{} = muter, %User{} = mutee), do: create(:mute, muter, mutee)
|
|
||||||
|
|
||||||
def delete(relationship_type, %User{} = source, %User{} = target) do
|
def delete(relationship_type, %User{} = source, %User{} = target) do
|
||||||
attrs = %{relationship_type: relationship_type, source_id: source.id, target_id: target.id}
|
attrs = %{relationship_type: relationship_type, source_id: source.id, target_id: target.id}
|
||||||
|
|
||||||
|
@ -66,10 +72,6 @@ def delete(relationship_type, %User{} = source, %User{} = target) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_block(%User{} = blocker, %User{} = blockee), do: delete(:block, blocker, blockee)
|
|
||||||
|
|
||||||
def delete_mute(%User{} = muter, %User{} = mutee), do: delete(:mute, muter, mutee)
|
|
||||||
|
|
||||||
defp validate_not_self_relationship(%Ecto.Changeset{} = changeset) do
|
defp validate_not_self_relationship(%Ecto.Changeset{} = changeset) do
|
||||||
changeset
|
changeset
|
||||||
|> validate_change(:target_id, fn _, target_id ->
|
|> validate_change(:target_id, fn _, target_id ->
|
||||||
|
|
|
@ -884,7 +884,7 @@ defp restrict_reblogs(query, _), do: query
|
||||||
defp restrict_muted(query, %{"with_muted" => val}) when val in [true, "true", "1"], do: query
|
defp restrict_muted(query, %{"with_muted" => val}) when val in [true, "true", "1"], do: query
|
||||||
|
|
||||||
defp restrict_muted(query, %{"muting_user" => %User{} = user} = opts) do
|
defp restrict_muted(query, %{"muting_user" => %User{} = user} = opts) do
|
||||||
mutes = opts["muted_ap_ids"] || User.muted_ap_ids(user)
|
mutes = opts["muted_ap_ids"] || User.muted_users_ap_ids(user)
|
||||||
|
|
||||||
query =
|
query =
|
||||||
from([activity] in query,
|
from([activity] in query,
|
||||||
|
@ -902,7 +902,7 @@ defp restrict_muted(query, %{"muting_user" => %User{} = user} = opts) do
|
||||||
defp restrict_muted(query, _), do: query
|
defp restrict_muted(query, _), do: query
|
||||||
|
|
||||||
defp restrict_blocked(query, %{"blocking_user" => %User{} = user} = opts) do
|
defp restrict_blocked(query, %{"blocking_user" => %User{} = user} = opts) do
|
||||||
blocked_ap_ids = opts["blocked_ap_ids"] || User.blocked_ap_ids(user)
|
blocked_ap_ids = opts["blocked_ap_ids"] || User.blocked_users_ap_ids(user)
|
||||||
domain_blocks = user.domain_blocks || []
|
domain_blocks = user.domain_blocks || []
|
||||||
|
|
||||||
query =
|
query =
|
||||||
|
@ -945,7 +945,7 @@ defp restrict_pinned(query, %{"pinned" => "true", "pinned_activity_ids" => ids})
|
||||||
defp restrict_pinned(query, _), do: query
|
defp restrict_pinned(query, _), do: query
|
||||||
|
|
||||||
defp restrict_muted_reblogs(query, %{"muting_user" => %User{} = user}) do
|
defp restrict_muted_reblogs(query, %{"muting_user" => %User{} = user}) do
|
||||||
muted_reblogs = user.muted_reblogs || []
|
muted_reblogs = User.reblog_muted_users_ap_ids(user)
|
||||||
|
|
||||||
from(
|
from(
|
||||||
activity in query,
|
activity in query,
|
||||||
|
|
|
@ -10,6 +10,7 @@ defmodule Pleroma.Web.CommonAPI do
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.ThreadMute
|
alias Pleroma.ThreadMute
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
alias Pleroma.UserRelationship
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
alias Pleroma.Web.ActivityPub.Visibility
|
alias Pleroma.Web.ActivityPub.Visibility
|
||||||
|
@ -420,15 +421,11 @@ defp set_visibility(activity, %{"visibility" => visibility}) do
|
||||||
|
|
||||||
defp set_visibility(activity, _), do: {:ok, activity}
|
defp set_visibility(activity, _), do: {:ok, activity}
|
||||||
|
|
||||||
def hide_reblogs(user, %{ap_id: ap_id} = _muted) do
|
def hide_reblogs(%User{} = user, %User{} = target) do
|
||||||
if ap_id not in user.muted_reblogs do
|
UserRelationship.create_reblog_mute(user, target)
|
||||||
User.add_reblog_mute(user, ap_id)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def show_reblogs(user, %{ap_id: ap_id} = _muted) do
|
def show_reblogs(%User{} = user, %User{} = target) do
|
||||||
if ap_id in user.muted_reblogs do
|
UserRelationship.delete_reblog_mute(user, target)
|
||||||
User.remove_reblog_mute(user, ap_id)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -323,9 +323,7 @@ def unfollow(%{assigns: %{user: follower, account: followed}} = conn, _params) d
|
||||||
def mute(%{assigns: %{user: muter, account: muted}} = conn, params) do
|
def mute(%{assigns: %{user: muter, account: muted}} = conn, params) do
|
||||||
notifications? = params |> Map.get("notifications", true) |> truthy_param?()
|
notifications? = params |> Map.get("notifications", true) |> truthy_param?()
|
||||||
|
|
||||||
with {:ok, _user_mute} <- User.mute(muter, muted, notifications?) do
|
with {:ok, _user_relationships} <- User.mute(muter, muted, notifications?) do
|
||||||
# TODO: remove `muter` refresh once `muted_notifications` field is deprecated
|
|
||||||
muter = User.get_cached_by_id(muter.id)
|
|
||||||
render(conn, "relationship.json", user: muter, target: muted)
|
render(conn, "relationship.json", user: muter, target: muted)
|
||||||
else
|
else
|
||||||
{:error, message} -> json_response(conn, :forbidden, %{error: message})
|
{:error, message} -> json_response(conn, :forbidden, %{error: message})
|
||||||
|
@ -334,9 +332,7 @@ def mute(%{assigns: %{user: muter, account: muted}} = conn, params) do
|
||||||
|
|
||||||
@doc "POST /api/v1/accounts/:id/unmute"
|
@doc "POST /api/v1/accounts/:id/unmute"
|
||||||
def unmute(%{assigns: %{user: muter, account: muted}} = conn, _params) do
|
def unmute(%{assigns: %{user: muter, account: muted}} = conn, _params) do
|
||||||
with {:ok, _user_mute} <- User.unmute(muter, muted) do
|
with {:ok, _user_relationships} <- User.unmute(muter, muted) do
|
||||||
# TODO: remove `muter` refresh once `muted_notifications` field is deprecated
|
|
||||||
muter = User.get_cached_by_id(muter.id)
|
|
||||||
render(conn, "relationship.json", user: muter, target: muted)
|
render(conn, "relationship.json", user: muter, target: muted)
|
||||||
else
|
else
|
||||||
{:error, message} -> json_response(conn, :forbidden, %{error: message})
|
{:error, message} -> json_response(conn, :forbidden, %{error: message})
|
||||||
|
@ -377,12 +373,14 @@ def follows(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do
|
||||||
|
|
||||||
@doc "GET /api/v1/mutes"
|
@doc "GET /api/v1/mutes"
|
||||||
def mutes(%{assigns: %{user: user}} = conn, _) do
|
def mutes(%{assigns: %{user: user}} = conn, _) do
|
||||||
render(conn, "index.json", users: User.muted_users(user), for: user, as: :user)
|
users = User.muted_users(user, _restrict_deactivated = true)
|
||||||
|
render(conn, "index.json", users: users, for: user, as: :user)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc "GET /api/v1/blocks"
|
@doc "GET /api/v1/blocks"
|
||||||
def blocks(%{assigns: %{user: user}} = conn, _) do
|
def blocks(%{assigns: %{user: user}} = conn, _) do
|
||||||
render(conn, "index.json", users: User.blocked_users(user), for: user, as: :user)
|
users = User.blocked_users(user, _restrict_deactivated = true)
|
||||||
|
render(conn, "index.json", users: users, for: user, as: :user)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc "GET /api/v1/endorsements"
|
@doc "GET /api/v1/endorsements"
|
||||||
|
|
|
@ -24,19 +24,16 @@ def follow(follower, followed, params \\ %{}) do
|
||||||
|
|
||||||
with {:ok, follower, _followed, _} <- result do
|
with {:ok, follower, _followed, _} <- result do
|
||||||
options = cast_params(params)
|
options = cast_params(params)
|
||||||
|
set_reblogs_visibility(options[:reblogs], result)
|
||||||
case reblogs_visibility(options[:reblogs], result) do
|
{:ok, follower}
|
||||||
{:ok, follower} -> {:ok, follower}
|
|
||||||
_ -> {:ok, follower}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp reblogs_visibility(false, {:ok, follower, followed, _}) do
|
defp set_reblogs_visibility(false, {:ok, follower, followed, _}) do
|
||||||
CommonAPI.hide_reblogs(follower, followed)
|
CommonAPI.hide_reblogs(follower, followed)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp reblogs_visibility(_, {:ok, follower, followed, _}) do
|
defp set_reblogs_visibility(_, {:ok, follower, followed, _}) do
|
||||||
CommonAPI.show_reblogs(follower, followed)
|
CommonAPI.show_reblogs(follower, followed)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -129,17 +129,17 @@ defp do_stream(%{topic: topic, item: item}) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp should_send?(%User{} = user, %Activity{} = item) do
|
defp should_send?(%User{} = user, %Activity{} = item) do
|
||||||
related_ap_ids = User.related_ap_ids(user, [:block, :mute])
|
%{block: blocked_ap_ids, mute: muted_ap_ids, reblog_mute: reblog_muted_ap_ids} =
|
||||||
blocks = related_ap_ids[:block] || []
|
User.related_ap_ids(user, [:block, :mute, :reblog_mute])
|
||||||
mutes = related_ap_ids[:mute] || []
|
|
||||||
reblog_mutes = user.muted_reblogs || []
|
recipient_blocks = MapSet.new(blocked_ap_ids ++ muted_ap_ids)
|
||||||
recipient_blocks = MapSet.new(blocks ++ mutes)
|
|
||||||
recipients = MapSet.new(item.recipients)
|
recipients = MapSet.new(item.recipients)
|
||||||
domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.domain_blocks)
|
domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.domain_blocks)
|
||||||
|
|
||||||
with parent <- Object.normalize(item) || item,
|
with parent <- Object.normalize(item) || item,
|
||||||
true <- Enum.all?([blocks, mutes, reblog_mutes], &(item.actor not in &1)),
|
true <-
|
||||||
true <- Enum.all?([blocks, mutes], &(parent.data["actor"] not in &1)),
|
Enum.all?([blocked_ap_ids, muted_ap_ids, reblog_muted_ap_ids], &(item.actor not in &1)),
|
||||||
|
true <- Enum.all?([blocked_ap_ids, muted_ap_ids], &(parent.data["actor"] not in &1)),
|
||||||
true <- MapSet.disjoint?(recipients, recipient_blocks),
|
true <- MapSet.disjoint?(recipients, recipient_blocks),
|
||||||
%{host: item_host} <- URI.parse(item.actor),
|
%{host: item_host} <- URI.parse(item.actor),
|
||||||
%{host: parent_host} <- URI.parse(parent.data["actor"]),
|
%{host: parent_host} <- URI.parse(parent.data["actor"]),
|
||||||
|
|
|
@ -252,7 +252,7 @@ test "when the user blocks a recipient, the existing conversations with them are
|
||||||
|
|
||||||
assert User.get_cached_by_id(blocker.id).unread_conversation_count == 4
|
assert User.get_cached_by_id(blocker.id).unread_conversation_count == 4
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(blocker, blocked)
|
{:ok, _user_relationship} = User.block(blocker, blocked)
|
||||||
|
|
||||||
# The conversations with the blocked user are marked as read
|
# The conversations with the blocked user are marked as read
|
||||||
assert [%{read: true}, %{read: true}, %{read: true}, %{read: false}] =
|
assert [%{read: true}, %{read: true}, %{read: true}, %{read: false}] =
|
||||||
|
@ -274,7 +274,7 @@ test "the new conversation with the blocked user is not marked as unread " do
|
||||||
blocked = insert(:user)
|
blocked = insert(:user)
|
||||||
third_user = insert(:user)
|
third_user = insert(:user)
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(blocker, blocked)
|
{:ok, _user_relationship} = User.block(blocker, blocked)
|
||||||
|
|
||||||
# When the blocked user is the author
|
# When the blocked user is the author
|
||||||
{:ok, _direct1} =
|
{:ok, _direct1} =
|
||||||
|
@ -311,7 +311,7 @@ test "the conversation with the blocked user is not marked as unread on a reply"
|
||||||
"visibility" => "direct"
|
"visibility" => "direct"
|
||||||
})
|
})
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(blocker, blocked)
|
{:ok, _user_relationship} = User.block(blocker, blocked)
|
||||||
assert [%{read: true}] = Participation.for_user(blocker)
|
assert [%{read: true}] = Participation.for_user(blocker)
|
||||||
assert User.get_cached_by_id(blocker.id).unread_conversation_count == 0
|
assert User.get_cached_by_id(blocker.id).unread_conversation_count == 0
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ test "it creates a notification for user if the user blocks the activity author"
|
||||||
activity = insert(:note_activity)
|
activity = insert(:note_activity)
|
||||||
author = User.get_cached_by_ap_id(activity.data["actor"])
|
author = User.get_cached_by_ap_id(activity.data["actor"])
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
{:ok, _user_block} = User.block(user, author)
|
{:ok, _user_relationship} = User.block(user, author)
|
||||||
|
|
||||||
assert Notification.create_notification(activity, user)
|
assert Notification.create_notification(activity, user)
|
||||||
end
|
end
|
||||||
|
@ -112,7 +112,7 @@ test "notification created if user is muted without notifications" do
|
||||||
muter = insert(:user)
|
muter = insert(:user)
|
||||||
muted = insert(:user)
|
muted = insert(:user)
|
||||||
|
|
||||||
{:ok, _user_mute} = User.mute(muter, muted, false)
|
{:ok, _user_relationships} = User.mute(muter, muted, false)
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
|
{:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
|
||||||
|
|
||||||
|
@ -636,7 +636,7 @@ test "notifications are deleted if a remote user is deleted" do
|
||||||
test "it returns notifications for muted user without notifications" do
|
test "it returns notifications for muted user without notifications" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
muted = insert(:user)
|
muted = insert(:user)
|
||||||
{:ok, _user_mute} = User.mute(user, muted, false)
|
{:ok, _user_relationships} = User.mute(user, muted, false)
|
||||||
|
|
||||||
{:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
|
{:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
|
||||||
|
|
||||||
|
@ -646,10 +646,7 @@ test "it returns notifications for muted user without notifications" do
|
||||||
test "it doesn't return notifications for muted user with notifications" do
|
test "it doesn't return notifications for muted user with notifications" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
muted = insert(:user)
|
muted = insert(:user)
|
||||||
{:ok, _user_mute} = User.mute(user, muted)
|
{:ok, _user_relationships} = User.mute(user, muted)
|
||||||
|
|
||||||
# Refreshing to reflect embedded ap id relation fields (remove once removed)
|
|
||||||
user = refresh_record(user)
|
|
||||||
|
|
||||||
{:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
|
{:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
|
||||||
|
|
||||||
|
@ -659,7 +656,7 @@ test "it doesn't return notifications for muted user with notifications" do
|
||||||
test "it doesn't return notifications for blocked user" do
|
test "it doesn't return notifications for blocked user" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
blocked = insert(:user)
|
blocked = insert(:user)
|
||||||
{:ok, _user_block} = User.block(user, blocked)
|
{:ok, _user_relationship} = User.block(user, blocked)
|
||||||
|
|
||||||
{:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
|
{:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
|
||||||
|
|
||||||
|
@ -689,7 +686,7 @@ test "it doesn't return notifications for muted thread" do
|
||||||
test "it returns notifications from a muted user when with_muted is set" do
|
test "it returns notifications from a muted user when with_muted is set" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
muted = insert(:user)
|
muted = insert(:user)
|
||||||
{:ok, _user_mute} = User.mute(user, muted)
|
{:ok, _user_relationships} = User.mute(user, muted)
|
||||||
|
|
||||||
{:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
|
{:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
|
||||||
|
|
||||||
|
@ -699,7 +696,7 @@ test "it returns notifications from a muted user when with_muted is set" do
|
||||||
test "it doesn't return notifications from a blocked user when with_muted is set" do
|
test "it doesn't return notifications from a blocked user when with_muted is set" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
blocked = insert(:user)
|
blocked = insert(:user)
|
||||||
{:ok, _user_block} = User.block(user, blocked)
|
{:ok, _user_relationship} = User.block(user, blocked)
|
||||||
|
|
||||||
{:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
|
{:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,7 @@ test "clears follow requests when requester is blocked" do
|
||||||
CommonAPI.follow(follower, followed)
|
CommonAPI.follow(follower, followed)
|
||||||
assert [_activity] = User.get_follow_requests(followed)
|
assert [_activity] = User.get_follow_requests(followed)
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(followed, follower)
|
{:ok, _user_relationship} = User.block(followed, follower)
|
||||||
assert [] = User.get_follow_requests(followed)
|
assert [] = User.get_follow_requests(followed)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -113,8 +113,8 @@ test "follow_all follows mutliple users" do
|
||||||
not_followed = insert(:user)
|
not_followed = insert(:user)
|
||||||
reverse_blocked = insert(:user)
|
reverse_blocked = insert(:user)
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(user, blocked)
|
{:ok, _user_relationship} = User.block(user, blocked)
|
||||||
{:ok, _user_block} = User.block(reverse_blocked, user)
|
{:ok, _user_relationship} = User.block(reverse_blocked, user)
|
||||||
|
|
||||||
{:ok, user} = User.follow(user, followed_zero)
|
{:ok, user} = User.follow(user, followed_zero)
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ test "can't follow a user who blocked us" do
|
||||||
blocker = insert(:user)
|
blocker = insert(:user)
|
||||||
blockee = insert(:user)
|
blockee = insert(:user)
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(blocker, blockee)
|
{:ok, _user_relationship} = User.block(blocker, blockee)
|
||||||
|
|
||||||
{:error, _} = User.follow(blockee, blocker)
|
{:error, _} = User.follow(blockee, blocker)
|
||||||
end
|
end
|
||||||
|
@ -175,7 +175,7 @@ test "can't subscribe to a user who blocked us" do
|
||||||
blocker = insert(:user)
|
blocker = insert(:user)
|
||||||
blocked = insert(:user)
|
blocked = insert(:user)
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(blocker, blocked)
|
{:ok, _user_relationship} = User.block(blocker, blocked)
|
||||||
|
|
||||||
{:error, _} = User.subscribe(blocked, blocker)
|
{:error, _} = User.subscribe(blocked, blocker)
|
||||||
end
|
end
|
||||||
|
@ -673,10 +673,7 @@ test "it mutes people" do
|
||||||
refute User.mutes?(user, muted_user)
|
refute User.mutes?(user, muted_user)
|
||||||
refute User.muted_notifications?(user, muted_user)
|
refute User.muted_notifications?(user, muted_user)
|
||||||
|
|
||||||
{:ok, _user_mute} = User.mute(user, muted_user)
|
{:ok, _user_relationships} = User.mute(user, muted_user)
|
||||||
|
|
||||||
# Refreshing to reflect embedded ap id relation fields (remove once removed)
|
|
||||||
user = refresh_record(user)
|
|
||||||
|
|
||||||
assert User.mutes?(user, muted_user)
|
assert User.mutes?(user, muted_user)
|
||||||
assert User.muted_notifications?(user, muted_user)
|
assert User.muted_notifications?(user, muted_user)
|
||||||
|
@ -686,7 +683,7 @@ test "it unmutes users" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
muted_user = insert(:user)
|
muted_user = insert(:user)
|
||||||
|
|
||||||
{:ok, _user_mute} = User.mute(user, muted_user)
|
{:ok, _user_relationships} = User.mute(user, muted_user)
|
||||||
{:ok, _user_mute} = User.unmute(user, muted_user)
|
{:ok, _user_mute} = User.unmute(user, muted_user)
|
||||||
|
|
||||||
refute User.mutes?(user, muted_user)
|
refute User.mutes?(user, muted_user)
|
||||||
|
@ -700,7 +697,7 @@ test "it mutes user without notifications" do
|
||||||
refute User.mutes?(user, muted_user)
|
refute User.mutes?(user, muted_user)
|
||||||
refute User.muted_notifications?(user, muted_user)
|
refute User.muted_notifications?(user, muted_user)
|
||||||
|
|
||||||
{:ok, _user_mute} = User.mute(user, muted_user, false)
|
{:ok, _user_relationships} = User.mute(user, muted_user, false)
|
||||||
|
|
||||||
assert User.mutes?(user, muted_user)
|
assert User.mutes?(user, muted_user)
|
||||||
refute User.muted_notifications?(user, muted_user)
|
refute User.muted_notifications?(user, muted_user)
|
||||||
|
@ -714,7 +711,7 @@ test "it blocks people" do
|
||||||
|
|
||||||
refute User.blocks?(user, blocked_user)
|
refute User.blocks?(user, blocked_user)
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(user, blocked_user)
|
{:ok, _user_relationship} = User.block(user, blocked_user)
|
||||||
|
|
||||||
assert User.blocks?(user, blocked_user)
|
assert User.blocks?(user, blocked_user)
|
||||||
end
|
end
|
||||||
|
@ -723,7 +720,7 @@ test "it unblocks users" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
blocked_user = insert(:user)
|
blocked_user = insert(:user)
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(user, blocked_user)
|
{:ok, _user_relationship} = User.block(user, blocked_user)
|
||||||
{:ok, _user_block} = User.unblock(user, blocked_user)
|
{:ok, _user_block} = User.unblock(user, blocked_user)
|
||||||
|
|
||||||
refute User.blocks?(user, blocked_user)
|
refute User.blocks?(user, blocked_user)
|
||||||
|
@ -739,7 +736,7 @@ test "blocks tear down cyclical follow relationships" do
|
||||||
assert User.following?(blocker, blocked)
|
assert User.following?(blocker, blocked)
|
||||||
assert User.following?(blocked, blocker)
|
assert User.following?(blocked, blocker)
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(blocker, blocked)
|
{:ok, _user_relationship} = User.block(blocker, blocked)
|
||||||
blocked = User.get_cached_by_id(blocked.id)
|
blocked = User.get_cached_by_id(blocked.id)
|
||||||
|
|
||||||
assert User.blocks?(blocker, blocked)
|
assert User.blocks?(blocker, blocked)
|
||||||
|
@ -757,7 +754,7 @@ test "blocks tear down blocker->blocked follow relationships" do
|
||||||
assert User.following?(blocker, blocked)
|
assert User.following?(blocker, blocked)
|
||||||
refute User.following?(blocked, blocker)
|
refute User.following?(blocked, blocker)
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(blocker, blocked)
|
{:ok, _user_relationship} = User.block(blocker, blocked)
|
||||||
blocked = User.get_cached_by_id(blocked.id)
|
blocked = User.get_cached_by_id(blocked.id)
|
||||||
|
|
||||||
assert User.blocks?(blocker, blocked)
|
assert User.blocks?(blocker, blocked)
|
||||||
|
@ -775,7 +772,7 @@ test "blocks tear down blocked->blocker follow relationships" do
|
||||||
refute User.following?(blocker, blocked)
|
refute User.following?(blocker, blocked)
|
||||||
assert User.following?(blocked, blocker)
|
assert User.following?(blocked, blocker)
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(blocker, blocked)
|
{:ok, _user_relationship} = User.block(blocker, blocked)
|
||||||
blocked = User.get_cached_by_id(blocked.id)
|
blocked = User.get_cached_by_id(blocked.id)
|
||||||
|
|
||||||
assert User.blocks?(blocker, blocked)
|
assert User.blocks?(blocker, blocked)
|
||||||
|
@ -793,7 +790,7 @@ test "blocks tear down blocked->blocker subscription relationships" do
|
||||||
assert User.subscribed_to?(blocked, blocker)
|
assert User.subscribed_to?(blocked, blocker)
|
||||||
refute User.subscribed_to?(blocker, blocked)
|
refute User.subscribed_to?(blocker, blocked)
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(blocker, blocked)
|
{:ok, _user_relationship} = User.block(blocker, blocked)
|
||||||
|
|
||||||
assert User.blocks?(blocker, blocked)
|
assert User.blocks?(blocker, blocked)
|
||||||
refute User.subscribed_to?(blocker, blocked)
|
refute User.subscribed_to?(blocker, blocked)
|
||||||
|
@ -1323,7 +1320,7 @@ test "follower count is updated when a follower is blocked" do
|
||||||
{:ok, _follower2} = User.follow(follower2, user)
|
{:ok, _follower2} = User.follow(follower2, user)
|
||||||
{:ok, _follower3} = User.follow(follower3, user)
|
{:ok, _follower3} = User.follow(follower3, user)
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(user, follower)
|
{:ok, _user_relationship} = User.block(user, follower)
|
||||||
user = refresh_record(user)
|
user = refresh_record(user)
|
||||||
|
|
||||||
assert User.user_info(user).follower_count == 2
|
assert User.user_info(user).follower_count == 2
|
||||||
|
|
|
@ -484,7 +484,7 @@ test "retrieves activities that have a given context" do
|
||||||
activity_five = insert(:note_activity)
|
activity_five = insert(:note_activity)
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(user, %{ap_id: activity_five.data["actor"]})
|
{:ok, _user_relationship} = User.block(user, %{ap_id: activity_five.data["actor"]})
|
||||||
|
|
||||||
activities = ActivityPub.fetch_activities_for_context("2hu", %{"blocking_user" => user})
|
activities = ActivityPub.fetch_activities_for_context("2hu", %{"blocking_user" => user})
|
||||||
assert activities == [activity_two, activity]
|
assert activities == [activity_two, activity]
|
||||||
|
@ -497,7 +497,7 @@ test "doesn't return blocked activities" do
|
||||||
activity_three = insert(:note_activity)
|
activity_three = insert(:note_activity)
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
booster = insert(:user)
|
booster = insert(:user)
|
||||||
{:ok, _user_block} = User.block(user, %{ap_id: activity_one.data["actor"]})
|
{:ok, _user_relationship} = User.block(user, %{ap_id: activity_one.data["actor"]})
|
||||||
|
|
||||||
activities =
|
activities =
|
||||||
ActivityPub.fetch_activities([], %{"blocking_user" => user, "skip_preload" => true})
|
ActivityPub.fetch_activities([], %{"blocking_user" => user, "skip_preload" => true})
|
||||||
|
@ -515,7 +515,7 @@ test "doesn't return blocked activities" do
|
||||||
assert Enum.member?(activities, activity_three)
|
assert Enum.member?(activities, activity_three)
|
||||||
assert Enum.member?(activities, activity_one)
|
assert Enum.member?(activities, activity_one)
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(user, %{ap_id: activity_three.data["actor"]})
|
{:ok, _user_relationship} = User.block(user, %{ap_id: activity_three.data["actor"]})
|
||||||
{:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.repeat(activity_three.id, booster)
|
{:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.repeat(activity_three.id, booster)
|
||||||
%Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id)
|
%Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id)
|
||||||
activity_three = Activity.get_by_id(activity_three.id)
|
activity_three = Activity.get_by_id(activity_three.id)
|
||||||
|
@ -542,7 +542,7 @@ test "doesn't return transitive interactions concerning blocked users" do
|
||||||
blockee = insert(:user)
|
blockee = insert(:user)
|
||||||
friend = insert(:user)
|
friend = insert(:user)
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(blocker, blockee)
|
{:ok, _user_relationship} = User.block(blocker, blockee)
|
||||||
|
|
||||||
{:ok, activity_one} = CommonAPI.post(friend, %{"status" => "hey!"})
|
{:ok, activity_one} = CommonAPI.post(friend, %{"status" => "hey!"})
|
||||||
|
|
||||||
|
@ -565,7 +565,7 @@ test "doesn't return announce activities concerning blocked users" do
|
||||||
blockee = insert(:user)
|
blockee = insert(:user)
|
||||||
friend = insert(:user)
|
friend = insert(:user)
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(blocker, blockee)
|
{:ok, _user_relationship} = User.block(blocker, blockee)
|
||||||
|
|
||||||
{:ok, activity_one} = CommonAPI.post(friend, %{"status" => "hey!"})
|
{:ok, activity_one} = CommonAPI.post(friend, %{"status" => "hey!"})
|
||||||
|
|
||||||
|
@ -613,7 +613,7 @@ test "doesn't return muted activities" do
|
||||||
booster = insert(:user)
|
booster = insert(:user)
|
||||||
|
|
||||||
activity_one_actor = User.get_by_ap_id(activity_one.data["actor"])
|
activity_one_actor = User.get_by_ap_id(activity_one.data["actor"])
|
||||||
{:ok, _user_mute} = User.mute(user, activity_one_actor)
|
{:ok, _user_relationships} = User.mute(user, activity_one_actor)
|
||||||
|
|
||||||
activities =
|
activities =
|
||||||
ActivityPub.fetch_activities([], %{"muting_user" => user, "skip_preload" => true})
|
ActivityPub.fetch_activities([], %{"muting_user" => user, "skip_preload" => true})
|
||||||
|
@ -644,7 +644,7 @@ test "doesn't return muted activities" do
|
||||||
assert Enum.member?(activities, activity_one)
|
assert Enum.member?(activities, activity_one)
|
||||||
|
|
||||||
activity_three_actor = User.get_by_ap_id(activity_three.data["actor"])
|
activity_three_actor = User.get_by_ap_id(activity_three.data["actor"])
|
||||||
{:ok, _user_mute} = User.mute(user, activity_three_actor)
|
{:ok, _user_relationships} = User.mute(user, activity_three_actor)
|
||||||
{:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.repeat(activity_three.id, booster)
|
{:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.repeat(activity_three.id, booster)
|
||||||
%Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id)
|
%Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id)
|
||||||
activity_three = Activity.get_by_id(activity_three.id)
|
activity_three = Activity.get_by_id(activity_three.id)
|
||||||
|
@ -791,7 +791,7 @@ test "doesn't return reblogs for users for whom reblogs have been muted" do
|
||||||
activity = insert(:note_activity)
|
activity = insert(:note_activity)
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
booster = insert(:user)
|
booster = insert(:user)
|
||||||
{:ok, user} = CommonAPI.hide_reblogs(user, booster)
|
{:ok, _reblog_mute} = CommonAPI.hide_reblogs(user, booster)
|
||||||
|
|
||||||
{:ok, activity, _} = CommonAPI.repeat(activity.id, booster)
|
{:ok, activity, _} = CommonAPI.repeat(activity.id, booster)
|
||||||
|
|
||||||
|
@ -804,8 +804,8 @@ test "returns reblogs for users for whom reblogs have not been muted" do
|
||||||
activity = insert(:note_activity)
|
activity = insert(:note_activity)
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
booster = insert(:user)
|
booster = insert(:user)
|
||||||
{:ok, user} = CommonAPI.hide_reblogs(user, booster)
|
{:ok, _reblog_mute} = CommonAPI.hide_reblogs(user, booster)
|
||||||
{:ok, user} = CommonAPI.show_reblogs(user, booster)
|
{:ok, _reblog_mute} = CommonAPI.show_reblogs(user, booster)
|
||||||
|
|
||||||
{:ok, activity, _} = CommonAPI.repeat(activity.id, booster)
|
{:ok, activity, _} = CommonAPI.repeat(activity.id, booster)
|
||||||
|
|
||||||
|
|
|
@ -128,7 +128,7 @@ test "it rejects incoming follow requests from blocked users when deny_follow_bl
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
{:ok, target} = User.get_or_fetch("http://mastodon.example.org/users/admin")
|
{:ok, target} = User.get_or_fetch("http://mastodon.example.org/users/admin")
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(user, target)
|
{:ok, _user_relationship} = User.block(user, target)
|
||||||
|
|
||||||
data =
|
data =
|
||||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||||
|
|
|
@ -509,14 +509,14 @@ test "updates state of multiple reports" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "add a reblog mute", %{muter: muter, muted: muted} do
|
test "add a reblog mute", %{muter: muter, muted: muted} do
|
||||||
{:ok, muter} = CommonAPI.hide_reblogs(muter, muted)
|
{:ok, _reblog_mute} = CommonAPI.hide_reblogs(muter, muted)
|
||||||
|
|
||||||
assert User.showing_reblogs?(muter, muted) == false
|
assert User.showing_reblogs?(muter, muted) == false
|
||||||
end
|
end
|
||||||
|
|
||||||
test "remove a reblog mute", %{muter: muter, muted: muted} do
|
test "remove a reblog mute", %{muter: muter, muted: muted} do
|
||||||
{:ok, muter} = CommonAPI.hide_reblogs(muter, muted)
|
{:ok, _reblog_mute} = CommonAPI.hide_reblogs(muter, muted)
|
||||||
{:ok, muter} = CommonAPI.show_reblogs(muter, muted)
|
{:ok, _reblog_mute} = CommonAPI.show_reblogs(muter, muted)
|
||||||
|
|
||||||
assert User.showing_reblogs?(muter, muted) == true
|
assert User.showing_reblogs?(muter, muted) == true
|
||||||
end
|
end
|
||||||
|
|
|
@ -868,7 +868,7 @@ test "getting a list of mutes", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
|
||||||
{:ok, _user_mute} = User.mute(user, other_user)
|
{:ok, _user_relationships} = User.mute(user, other_user)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|
@ -883,7 +883,7 @@ test "getting a list of blocks", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(user, other_user)
|
{:ok, _user_relationship} = User.block(user, other_user)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|
|
|
@ -289,10 +289,7 @@ test "doesn't see notifications after muting user with notifications", %{conn: c
|
||||||
|
|
||||||
assert length(json_response(conn, 200)) == 1
|
assert length(json_response(conn, 200)) == 1
|
||||||
|
|
||||||
{:ok, _user_mute} = User.mute(user, user2)
|
{:ok, _user_relationships} = User.mute(user, user2)
|
||||||
|
|
||||||
# Refreshing to reflect embedded ap id relation fields (remove once removed)
|
|
||||||
user = refresh_record(user)
|
|
||||||
|
|
||||||
conn = assign(build_conn(), :user, user)
|
conn = assign(build_conn(), :user, user)
|
||||||
conn = get(conn, "/api/v1/notifications")
|
conn = get(conn, "/api/v1/notifications")
|
||||||
|
@ -313,7 +310,7 @@ test "see notifications after muting user without notifications", %{conn: conn}
|
||||||
|
|
||||||
assert length(json_response(conn, 200)) == 1
|
assert length(json_response(conn, 200)) == 1
|
||||||
|
|
||||||
{:ok, _user_mute} = User.mute(user, user2, false)
|
{:ok, _user_relationships} = User.mute(user, user2, false)
|
||||||
|
|
||||||
conn = assign(build_conn(), :user, user)
|
conn = assign(build_conn(), :user, user)
|
||||||
conn = get(conn, "/api/v1/notifications")
|
conn = get(conn, "/api/v1/notifications")
|
||||||
|
@ -336,7 +333,7 @@ test "see notifications after muting user with notifications and with_muted para
|
||||||
|
|
||||||
assert length(json_response(conn, 200)) == 1
|
assert length(json_response(conn, 200)) == 1
|
||||||
|
|
||||||
{:ok, _user_mute} = User.mute(user, user2)
|
{:ok, _user_relationships} = User.mute(user, user2)
|
||||||
|
|
||||||
conn = assign(build_conn(), :user, user)
|
conn = assign(build_conn(), :user, user)
|
||||||
conn = get(conn, "/api/v1/notifications", %{"with_muted" => "true"})
|
conn = get(conn, "/api/v1/notifications", %{"with_muted" => "true"})
|
||||||
|
|
|
@ -1108,7 +1108,7 @@ test "does not return users who have favorited the status but are blocked", %{
|
||||||
activity: activity
|
activity: activity
|
||||||
} do
|
} do
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
{:ok, _user_block} = User.block(user, other_user)
|
{:ok, _user_relationship} = User.block(user, other_user)
|
||||||
|
|
||||||
{:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
|
{:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
|
||||||
|
|
||||||
|
@ -1205,7 +1205,7 @@ test "does not return users who have reblogged the status but are blocked", %{
|
||||||
activity: activity
|
activity: activity
|
||||||
} do
|
} do
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
{:ok, _user_block} = User.block(user, other_user)
|
{:ok, _user_relationship} = User.block(user, other_user)
|
||||||
|
|
||||||
{:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
|
{:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
|
||||||
|
|
||||||
|
|
|
@ -194,7 +194,7 @@ test "doesn't include DMs from blocked users", %{conn: conn} do
|
||||||
blocker = insert(:user)
|
blocker = insert(:user)
|
||||||
blocked = insert(:user)
|
blocked = insert(:user)
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
{:ok, _user_block} = User.block(blocker, blocked)
|
{:ok, _user_relationship} = User.block(blocker, blocked)
|
||||||
|
|
||||||
{:ok, _blocked_direct} =
|
{:ok, _blocked_direct} =
|
||||||
CommonAPI.post(blocked, %{
|
CommonAPI.post(blocked, %{
|
||||||
|
|
|
@ -191,11 +191,8 @@ test "represent a relationship for the following and followed user" do
|
||||||
{:ok, user} = User.follow(user, other_user)
|
{:ok, user} = User.follow(user, other_user)
|
||||||
{:ok, other_user} = User.follow(other_user, user)
|
{:ok, other_user} = User.follow(other_user, user)
|
||||||
{:ok, other_user} = User.subscribe(user, other_user)
|
{:ok, other_user} = User.subscribe(user, other_user)
|
||||||
{:ok, _user_mute} = User.mute(user, other_user, true)
|
{:ok, _user_relationships} = User.mute(user, other_user, true)
|
||||||
{:ok, user} = CommonAPI.hide_reblogs(user, other_user)
|
{:ok, _reblog_mute} = CommonAPI.hide_reblogs(user, other_user)
|
||||||
|
|
||||||
# Refreshing to reflect embedded ap id relation fields (remove once removed)
|
|
||||||
user = refresh_record(user)
|
|
||||||
|
|
||||||
expected = %{
|
expected = %{
|
||||||
id: to_string(other_user.id),
|
id: to_string(other_user.id),
|
||||||
|
@ -222,8 +219,8 @@ test "represent a relationship for the blocking and blocked user" do
|
||||||
|
|
||||||
{:ok, user} = User.follow(user, other_user)
|
{:ok, user} = User.follow(user, other_user)
|
||||||
{:ok, other_user} = User.subscribe(user, other_user)
|
{:ok, other_user} = User.subscribe(user, other_user)
|
||||||
{:ok, _user_block} = User.block(user, other_user)
|
{:ok, _user_relationship} = User.block(user, other_user)
|
||||||
{:ok, _user_block} = User.block(other_user, user)
|
{:ok, _user_relationship} = User.block(other_user, user)
|
||||||
|
|
||||||
expected = %{
|
expected = %{
|
||||||
id: to_string(other_user.id),
|
id: to_string(other_user.id),
|
||||||
|
@ -294,7 +291,7 @@ test "represent an embedded relationship" do
|
||||||
|
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
{:ok, other_user} = User.follow(other_user, user)
|
{:ok, other_user} = User.follow(other_user, user)
|
||||||
{:ok, _user_block} = User.block(other_user, user)
|
{:ok, _user_relationship} = User.block(other_user, user)
|
||||||
{:ok, _} = User.follow(insert(:user), user)
|
{:ok, _} = User.follow(insert(:user), user)
|
||||||
|
|
||||||
expected = %{
|
expected = %{
|
||||||
|
|
|
@ -183,7 +183,7 @@ test "tells if the message is muted for some reason" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
|
||||||
{:ok, _user_mute} = User.mute(user, other_user)
|
{:ok, _user_relationships} = User.mute(user, other_user)
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
|
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
|
||||||
status = StatusView.render("show.json", %{activity: activity})
|
status = StatusView.render("show.json", %{activity: activity})
|
||||||
|
@ -199,7 +199,7 @@ test "tells if the message is thread muted" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
|
||||||
{:ok, _user_mute} = User.mute(user, other_user)
|
{:ok, _user_relationships} = User.mute(user, other_user)
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
|
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
|
||||||
status = StatusView.render("show.json", %{activity: activity, for: user})
|
status = StatusView.render("show.json", %{activity: activity, for: user})
|
||||||
|
|
|
@ -59,7 +59,7 @@ test "it doesn't send notify to the 'user:notification' stream when a user is bl
|
||||||
user: user
|
user: user
|
||||||
} do
|
} do
|
||||||
blocked = insert(:user)
|
blocked = insert(:user)
|
||||||
{:ok, _user_block} = User.block(user, blocked)
|
{:ok, _user_relationship} = User.block(user, blocked)
|
||||||
|
|
||||||
task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
|
task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ test "it sends message if recipients invalid and thread containment is enabled b
|
||||||
test "it doesn't send messages involving blocked users" do
|
test "it doesn't send messages involving blocked users" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
blocked_user = insert(:user)
|
blocked_user = insert(:user)
|
||||||
{:ok, _user_block} = User.block(user, blocked_user)
|
{:ok, _user_relationship} = User.block(user, blocked_user)
|
||||||
|
|
||||||
task =
|
task =
|
||||||
Task.async(fn ->
|
Task.async(fn ->
|
||||||
|
@ -301,7 +301,7 @@ test "it doesn't send messages transitively involving blocked users" do
|
||||||
"public" => [fake_socket]
|
"public" => [fake_socket]
|
||||||
}
|
}
|
||||||
|
|
||||||
{:ok, _user_block} = User.block(blocker, blockee)
|
{:ok, _user_relationship} = User.block(blocker, blockee)
|
||||||
|
|
||||||
{:ok, activity_one} = CommonAPI.post(friend, %{"status" => "hey! @#{blockee.nickname}"})
|
{:ok, activity_one} = CommonAPI.post(friend, %{"status" => "hey! @#{blockee.nickname}"})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue