end
defp exclude_blocked(query, user) do
- blocked_ap_ids = User.blocked_ap_ids(user)
+ blocked_ap_ids = User.blocked_users_ap_ids(user)
query
|> where([n, a], a.actor not in ^blocked_ap_ids)
end
defp exclude_muted(query, user, _opts) do
+ notification_muted_ap_ids = User.notification_muted_users_ap_ids(user)
+
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,
on: tm.user_id == ^user.id and tm.context == fragment("?->>'context'", a.data)
)
@strict_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
field(:bio, :string)
field(:email, :string)
field(:tags, {:array, :string}, default: [])
field(:last_refreshed_at, :naive_datetime_usec)
field(:last_digest_emailed_at, :naive_datetime)
-
field(:banner, :map, default: %{})
field(:background, :map, default: %{})
field(:source_data, :map, default: %{})
field(:confirmation_token, :string, default: nil)
field(:default_scope, :string, default: "public")
field(:domain_blocks, {:array, :string}, default: [])
- field(:muted_reblogs, {:array, :string}, default: [])
- field(:muted_notifications, {:array, :string}, default: [])
field(:subscribers, {:array, :string}, default: [])
field(:deactivated, :boolean, default: false)
field(:no_rich_text, :boolean, default: false)
has_many(:outgoing_relationships, UserRelationship, foreign_key: :source_id)
has_many(:incoming_relationships, UserRelationship, foreign_key: :target_id)
- has_many(:blocker_blocks, UserRelationship,
- foreign_key: :source_id,
- where: [relationship_type: :block]
- )
-
- has_many(:blockee_blocks, UserRelationship,
- foreign_key: :target_id,
- where: [relationship_type: :block]
- )
-
- has_many(:blocked_users, through: [:blocker_blocks, :target])
- has_many(:blocker_users, through: [:blockee_blocks, :source])
+ 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,
+ where: [relationship_type: relationship_type]
+ )
- has_many(:muter_mutes, UserRelationship,
- foreign_key: :source_id,
- where: [relationship_type: :mute]
- )
+ # Definitions of `has_many :blockee_blocks`, `has_many :mutee_mutes` etc.
+ has_many(incoming_relation, UserRelationship,
+ foreign_key: :target_id,
+ where: [relationship_type: relationship_type]
+ )
- has_many(:mutee_mutes, UserRelationship,
- foreign_key: :target_id,
- where: [relationship_type: :mute]
- )
+ # Definitions of `has_many :blocked_users`, `has_many :muted_users` etc.
+ has_many(outgoing_relation_target, through: [outgoing_relation, :target])
- has_many(:muted_users, through: [:muter_mutes, :target])
- has_many(:muter_users, through: [:mutee_mutes, :source])
+ # Definitions of `has_many :blocker_users`, `has_many :muter_users` etc.
+ has_many(incoming_relation_source, through: [incoming_relation, :source])
+ end
field(:info, :map, default: %{})
field(:blocks, {:array, :string}, default: [])
# `:mutes` is deprecated (replaced with `muted_users` relation)
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()
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"
def auth_active?(%User{deactivated: true}), do: false
|> Repo.all()
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
add_to_mutes(muter, mutee, notifications?)
end
@spec muted_notifications?(User.t() | nil, User.t() | map()) :: boolean()
def muted_notifications?(nil, _), do: false
- def muted_notifications?(user, %{ap_id: ap_id}),
- do: Enum.member?(user.muted_notifications, ap_id)
+ def muted_notifications?(user, %User{} = target),
+ do: UserRelationship.notification_mute_exists?(user, target)
def blocks?(nil, _), do: false
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 """
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())}
def related_ap_ids(%User{} = user, relationship_types) when is_list(relationship_types) do
- user
- |> assoc(:outgoing_relationships)
- |> join(:inner, [user_rel], u in assoc(user_rel, :target))
- |> where([user_rel, u], user_rel.relationship_type in ^relationship_types)
- |> select([user_rel, u], [user_rel.relationship_type, fragment("array_agg(?)", u.ap_id)])
- |> group_by([user_rel, u], user_rel.relationship_type)
- |> Repo.all()
- |> Enum.into(%{}, fn [k, v] -> {k, v} end)
+ db_result =
+ user
+ |> assoc(:outgoing_relationships)
+ |> join(:inner, [user_rel], u in assoc(user_rel, :target))
+ |> where([user_rel, u], user_rel.relationship_type in ^relationship_types)
+ |> select([user_rel, u], [user_rel.relationship_type, fragment("array_agg(?)", u.ap_id)])
+ |> group_by([user_rel, u], user_rel.relationship_type)
+ |> Repo.all()
+ |> Enum.into(%{}, fn [k, v] -> {k, v} end)
+
+ Enum.into(
+ relationship_types,
+ %{},
+ fn rel_type -> {rel_type, db_result[rel_type] || []} end
+ )
end
@spec subscribers(User.t()) :: [User.t()]
end
def showing_reblogs?(%User{} = user, %User{} = target) do
- target.ap_id not in user.muted_reblogs
+ not UserRelationship.reblog_mute_exists?(user, target)
end
@doc """
UserRelationship.delete_block(user, blocked)
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),
- {:ok, _user} <-
- set_notification_mutes(
- user,
- Enum.uniq([ap_id | user.muted_notifications]),
- notifications?
- ) do
- {:ok, user_mute}
+ {:ok, user_notification_mute} <-
+ (notifications? && UserRelationship.create_notification_mute(user, muted_user)) ||
+ {:ok, nil} do
+ {:ok, Enum.filter([user_mute, user_notification_mute], & &1)}
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),
- {:ok, _user} <-
- set_notification_mutes(
- user,
- List.delete(user.muted_notifications, ap_id),
- true
- ) do
- {:ok, user_mute}
+ {:ok, user_notification_mute} <-
+ UserRelationship.delete_notification_mute(user, muted_user) do
+ {:ok, [user_mute, user_notification_mute]}
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
params = %{invisible: invisible}
timestamps(updated_at: false)
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
user_relationship
|> cast(params, [:relationship_type, :source_id, :target_id])
|> Repo.exists?()
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
%UserRelationship{}
|> changeset(%{
)
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
attrs = %{relationship_type: relationship_type, source_id: source.id, target_id: target.id}
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
changeset
|> validate_change(:target_id, fn _, target_id ->
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
- mutes = opts["muted_ap_ids"] || User.muted_ap_ids(user)
+ mutes = opts["muted_ap_ids"] || User.muted_users_ap_ids(user)
query =
from([activity] in query,
defp restrict_muted(query, _), do: query
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 || []
query =
defp restrict_pinned(query, _), do: query
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(
activity in query,
alias Pleroma.Object
alias Pleroma.ThreadMute
alias Pleroma.User
+ alias Pleroma.UserRelationship
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.ActivityPub.Visibility
defp set_visibility(activity, _), do: {:ok, activity}
- def hide_reblogs(user, %{ap_id: ap_id} = _muted) do
- if ap_id not in user.muted_reblogs do
- User.add_reblog_mute(user, ap_id)
- end
+ def hide_reblogs(%User{} = user, %User{} = target) do
+ UserRelationship.create_reblog_mute(user, target)
end
- def show_reblogs(user, %{ap_id: ap_id} = _muted) do
- if ap_id in user.muted_reblogs do
- User.remove_reblog_mute(user, ap_id)
- end
+ def show_reblogs(%User{} = user, %User{} = target) do
+ UserRelationship.delete_reblog_mute(user, target)
end
end
def mute(%{assigns: %{user: muter, account: muted}} = conn, params) do
notifications? = params |> Map.get("notifications", true) |> truthy_param?()
- with {:ok, _user_mute} <- User.mute(muter, muted, notifications?) do
- # TODO: remove `muter` refresh once `muted_notifications` field is deprecated
- muter = User.get_cached_by_id(muter.id)
+ with {:ok, _user_relationships} <- User.mute(muter, muted, notifications?) do
render(conn, "relationship.json", user: muter, target: muted)
else
{:error, message} -> json_response(conn, :forbidden, %{error: message})
@doc "POST /api/v1/accounts/:id/unmute"
def unmute(%{assigns: %{user: muter, account: muted}} = conn, _params) do
- with {:ok, _user_mute} <- User.unmute(muter, muted) do
- # TODO: remove `muter` refresh once `muted_notifications` field is deprecated
- muter = User.get_cached_by_id(muter.id)
+ with {:ok, _user_relationships} <- User.unmute(muter, muted) do
render(conn, "relationship.json", user: muter, target: muted)
else
{:error, message} -> json_response(conn, :forbidden, %{error: message})
@doc "GET /api/v1/mutes"
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
@doc "GET /api/v1/blocks"
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
@doc "GET /api/v1/endorsements"
with {:ok, follower, _followed, _} <- result do
options = cast_params(params)
-
- case reblogs_visibility(options[:reblogs], result) do
- {:ok, follower} -> {:ok, follower}
- _ -> {:ok, follower}
- end
+ set_reblogs_visibility(options[:reblogs], result)
+ {:ok, follower}
end
end
- defp reblogs_visibility(false, {:ok, follower, followed, _}) do
+ defp set_reblogs_visibility(false, {:ok, follower, followed, _}) do
CommonAPI.hide_reblogs(follower, followed)
end
- defp reblogs_visibility(_, {:ok, follower, followed, _}) do
+ defp set_reblogs_visibility(_, {:ok, follower, followed, _}) do
CommonAPI.show_reblogs(follower, followed)
end
end
defp should_send?(%User{} = user, %Activity{} = item) do
- related_ap_ids = User.related_ap_ids(user, [:block, :mute])
- blocks = related_ap_ids[:block] || []
- mutes = related_ap_ids[:mute] || []
- reblog_mutes = user.muted_reblogs || []
- recipient_blocks = MapSet.new(blocks ++ mutes)
+ %{block: blocked_ap_ids, mute: muted_ap_ids, reblog_mute: reblog_muted_ap_ids} =
+ User.related_ap_ids(user, [:block, :mute, :reblog_mute])
+
+ recipient_blocks = MapSet.new(blocked_ap_ids ++ muted_ap_ids)
recipients = MapSet.new(item.recipients)
domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.domain_blocks)
with parent <- Object.normalize(item) || item,
- true <- Enum.all?([blocks, mutes, reblog_mutes], &(item.actor not in &1)),
- true <- Enum.all?([blocks, mutes], &(parent.data["actor"] not in &1)),
+ true <-
+ 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),
%{host: item_host} <- URI.parse(item.actor),
%{host: parent_host} <- URI.parse(parent.data["actor"]),
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
assert [%{read: true}, %{read: true}, %{read: true}, %{read: false}] =
blocked = 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
{:ok, _direct1} =
"visibility" => "direct"
})
- {:ok, _user_block} = User.block(blocker, blocked)
+ {:ok, _user_relationship} = User.block(blocker, blocked)
assert [%{read: true}] = Participation.for_user(blocker)
assert User.get_cached_by_id(blocker.id).unread_conversation_count == 0
activity = insert(:note_activity)
author = User.get_cached_by_ap_id(activity.data["actor"])
user = insert(:user)
- {:ok, _user_block} = User.block(user, author)
+ {:ok, _user_relationship} = User.block(user, author)
assert Notification.create_notification(activity, user)
end
muter = 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}"})
test "it returns notifications for muted user without notifications" do
user = 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}"})
test "it doesn't return notifications for muted user with notifications" do
user = insert(:user)
muted = insert(:user)
- {:ok, _user_mute} = User.mute(user, muted)
-
- # Refreshing to reflect embedded ap id relation fields (remove once removed)
- user = refresh_record(user)
+ {:ok, _user_relationships} = User.mute(user, muted)
{:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
test "it doesn't return notifications for blocked user" do
user = 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}"})
test "it returns notifications from a muted user when with_muted is set" do
user = 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}"})
test "it doesn't return notifications from a blocked user when with_muted is set" do
user = 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}"})
CommonAPI.follow(follower, 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)
end
not_followed = insert(:user)
reverse_blocked = insert(:user)
- {:ok, _user_block} = User.block(user, blocked)
- {:ok, _user_block} = User.block(reverse_blocked, user)
+ {:ok, _user_relationship} = User.block(user, blocked)
+ {:ok, _user_relationship} = User.block(reverse_blocked, user)
{:ok, user} = User.follow(user, followed_zero)
blocker = insert(:user)
blockee = insert(:user)
- {:ok, _user_block} = User.block(blocker, blockee)
+ {:ok, _user_relationship} = User.block(blocker, blockee)
{:error, _} = User.follow(blockee, blocker)
end
blocker = insert(:user)
blocked = insert(:user)
- {:ok, _user_block} = User.block(blocker, blocked)
+ {:ok, _user_relationship} = User.block(blocker, blocked)
{:error, _} = User.subscribe(blocked, blocker)
end
refute User.mutes?(user, muted_user)
refute User.muted_notifications?(user, muted_user)
- {:ok, _user_mute} = User.mute(user, muted_user)
-
- # Refreshing to reflect embedded ap id relation fields (remove once removed)
- user = refresh_record(user)
+ {:ok, _user_relationships} = User.mute(user, muted_user)
assert User.mutes?(user, muted_user)
assert User.muted_notifications?(user, muted_user)
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)
refute User.mutes?(user, muted_user)
refute User.mutes?(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)
refute User.muted_notifications?(user, muted_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)
end
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)
refute User.blocks?(user, blocked_user)
assert User.following?(blocker, blocked)
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)
assert User.blocks?(blocker, blocked)
assert User.following?(blocker, blocked)
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)
assert User.blocks?(blocker, blocked)
refute User.following?(blocker, blocked)
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)
assert User.blocks?(blocker, blocked)
assert User.subscribed_to?(blocked, blocker)
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)
refute User.subscribed_to?(blocker, blocked)
{:ok, _follower2} = User.follow(follower2, 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)
assert User.user_info(user).follower_count == 2
activity_five = insert(:note_activity)
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})
assert activities == [activity_two, activity]
activity_three = insert(:note_activity)
user = 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 =
ActivityPub.fetch_activities([], %{"blocking_user" => user, "skip_preload" => true})
assert Enum.member?(activities, activity_three)
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)
%Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id)
activity_three = Activity.get_by_id(activity_three.id)
blockee = 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!"})
blockee = 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!"})
booster = insert(:user)
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 =
ActivityPub.fetch_activities([], %{"muting_user" => user, "skip_preload" => true})
assert Enum.member?(activities, activity_one)
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)
%Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id)
activity_three = Activity.get_by_id(activity_three.id)
activity = insert(:note_activity)
user = 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)
activity = insert(:note_activity)
user = insert(:user)
booster = insert(:user)
- {:ok, user} = CommonAPI.hide_reblogs(user, booster)
- {:ok, user} = CommonAPI.show_reblogs(user, booster)
+ {:ok, _reblog_mute} = CommonAPI.hide_reblogs(user, booster)
+ {:ok, _reblog_mute} = CommonAPI.show_reblogs(user, booster)
{:ok, activity, _} = CommonAPI.repeat(activity.id, booster)
user = insert(:user)
{: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 =
File.read!("test/fixtures/mastodon-follow-activity.json")
end
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
end
test "remove a reblog mute", %{muter: muter, muted: muted} do
- {:ok, muter} = CommonAPI.hide_reblogs(muter, muted)
- {:ok, muter} = CommonAPI.show_reblogs(muter, muted)
+ {:ok, _reblog_mute} = CommonAPI.hide_reblogs(muter, muted)
+ {:ok, _reblog_mute} = CommonAPI.show_reblogs(muter, muted)
assert User.showing_reblogs?(muter, muted) == true
end
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
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
assert length(json_response(conn, 200)) == 1
- {:ok, _user_mute} = User.mute(user, user2)
-
- # Refreshing to reflect embedded ap id relation fields (remove once removed)
- user = refresh_record(user)
+ {:ok, _user_relationships} = User.mute(user, user2)
conn = assign(build_conn(), :user, user)
conn = get(conn, "/api/v1/notifications")
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 = get(conn, "/api/v1/notifications")
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 = get(conn, "/api/v1/notifications", %{"with_muted" => "true"})
activity: activity
} do
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)
activity: activity
} do
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)
blocker = insert(:user)
blocked = insert(:user)
user = insert(:user)
- {:ok, _user_block} = User.block(blocker, blocked)
+ {:ok, _user_relationship} = User.block(blocker, blocked)
{:ok, _blocked_direct} =
CommonAPI.post(blocked, %{
{:ok, user} = User.follow(user, other_user)
{:ok, other_user} = User.follow(other_user, user)
{:ok, other_user} = User.subscribe(user, other_user)
- {:ok, _user_mute} = User.mute(user, other_user, true)
- {:ok, user} = CommonAPI.hide_reblogs(user, other_user)
-
- # Refreshing to reflect embedded ap id relation fields (remove once removed)
- user = refresh_record(user)
+ {:ok, _user_relationships} = User.mute(user, other_user, true)
+ {:ok, _reblog_mute} = CommonAPI.hide_reblogs(user, other_user)
expected = %{
id: to_string(other_user.id),
{:ok, user} = User.follow(user, other_user)
{:ok, other_user} = User.subscribe(user, other_user)
- {:ok, _user_block} = User.block(user, other_user)
- {:ok, _user_block} = User.block(other_user, user)
+ {:ok, _user_relationship} = User.block(user, other_user)
+ {:ok, _user_relationship} = User.block(other_user, user)
expected = %{
id: to_string(other_user.id),
other_user = insert(: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)
expected = %{
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"})
status = StatusView.render("show.json", %{activity: activity})
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"})
status = StatusView.render("show.json", %{activity: activity, for: user})
user: user
} do
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)
test "it doesn't send messages involving blocked users" do
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.async(fn ->
"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}"})