Merge branch 'commonapi-cleanup' into 'develop'

CommonAPI Cleanup

See merge request pleroma/pleroma!4189
This commit is contained in:
feld 2024-07-22 23:36:18 +00:00
commit ff663c0aeb
60 changed files with 363 additions and 324 deletions

View file

View file

@ -12,6 +12,8 @@ defmodule Pleroma.Conversation.Participation do
import Ecto.Changeset import Ecto.Changeset
import Ecto.Query import Ecto.Query
@type t :: %__MODULE__{}
schema "conversation_participations" do schema "conversation_participations" do
belongs_to(:user, User, type: FlakeId.Ecto.CompatType) belongs_to(:user, User, type: FlakeId.Ecto.CompatType)
belongs_to(:conversation, Conversation) belongs_to(:conversation, Conversation)

View file

@ -199,8 +199,8 @@ def move_following(origin, target) do
|> preload([:follower]) |> preload([:follower])
|> Repo.all() |> Repo.all()
|> Enum.map(fn following_relationship -> |> Enum.map(fn following_relationship ->
Pleroma.Web.CommonAPI.follow(following_relationship.follower, target) Pleroma.Web.CommonAPI.follow(target, following_relationship.follower)
Pleroma.Web.CommonAPI.unfollow(following_relationship.follower, origin) Pleroma.Web.CommonAPI.unfollow(origin, following_relationship.follower)
end) end)
|> case do |> case do
[] -> [] ->

View file

@ -734,7 +734,7 @@ def skip?(_type, _activity, _user, _opts), do: false
def mark_as_read?(activity, target_user) do def mark_as_read?(activity, target_user) do
user = Activity.user_actor(activity) user = Activity.user_actor(activity)
User.mutes_user?(target_user, user) || CommonAPI.thread_muted?(target_user, activity) User.mutes_user?(target_user, user) || CommonAPI.thread_muted?(activity, target_user)
end end
def for_user_and_activity(user, activity) do def for_user_and_activity(user, activity) do

View file

@ -31,7 +31,7 @@ def perform(:blocks_import, %User{} = blocker, [_ | _] = identifiers) do
identifiers, identifiers,
fn identifier -> fn identifier ->
with {:ok, %User{} = blocked} <- User.get_or_fetch(identifier), with {:ok, %User{} = blocked} <- User.get_or_fetch(identifier),
{:ok, _block} <- CommonAPI.block(blocker, blocked) do {:ok, _block} <- CommonAPI.block(blocked, blocker) do
blocked blocked
else else
error -> handle_error(:blocks_import, identifier, error) error -> handle_error(:blocks_import, identifier, error)
@ -46,7 +46,7 @@ def perform(:follow_import, %User{} = follower, [_ | _] = identifiers) do
fn identifier -> fn identifier ->
with {:ok, %User{} = followed} <- User.get_or_fetch(identifier), with {:ok, %User{} = followed} <- User.get_or_fetch(identifier),
{:ok, follower, followed} <- User.maybe_direct_follow(follower, followed), {:ok, follower, followed} <- User.maybe_direct_follow(follower, followed),
{:ok, _, _, _} <- CommonAPI.follow(follower, followed) do {:ok, _, _, _} <- CommonAPI.follow(followed, follower) do
followed followed
else else
error -> handle_error(:follow_import, identifier, error) error -> handle_error(:follow_import, identifier, error)

View file

@ -49,7 +49,7 @@ defp try_follow(follower, message) do
"#{__MODULE__}: Follow request from #{follower.nickname} to #{user.nickname}" "#{__MODULE__}: Follow request from #{follower.nickname} to #{user.nickname}"
) )
CommonAPI.follow(follower, user) CommonAPI.follow(user, follower)
end end
end) end)

View file

@ -22,7 +22,7 @@ def get_actor, do: User.get_or_create_service_actor_by_ap_id(ap_id(), @nickname)
def follow(target_instance) do def follow(target_instance) do
with %User{} = local_user <- get_actor(), with %User{} = local_user <- get_actor(),
{:ok, %User{} = target_user} <- User.get_or_fetch_by_ap_id(target_instance), {:ok, %User{} = target_user} <- User.get_or_fetch_by_ap_id(target_instance),
{:ok, _, _, activity} <- CommonAPI.follow(local_user, target_user) do {:ok, _, _, activity} <- CommonAPI.follow(target_user, local_user) do
Logger.info("relay: followed instance: #{target_instance}; id=#{activity.data["id"]}") Logger.info("relay: followed instance: #{target_instance}; id=#{activity.data["id"]}")
{:ok, activity} {:ok, activity}
else else

View file

@ -26,13 +26,16 @@ defmodule Pleroma.Web.CommonAPI do
require Pleroma.Constants require Pleroma.Constants
require Logger require Logger
def block(blocker, blocked) do @spec block(User.t(), User.t()) :: {:ok, Activity.t()} | {:error, any()}
def block(blocked, blocker) do
with {:ok, block_data, _} <- Builder.block(blocker, blocked), with {:ok, block_data, _} <- Builder.block(blocker, blocked),
{:ok, block, _} <- Pipeline.common_pipeline(block_data, local: true) do {:ok, block, _} <- Pipeline.common_pipeline(block_data, local: true) do
{:ok, block} {:ok, block}
end end
end end
@spec post_chat_message(User.t(), User.t(), String.t(), list()) ::
{:ok, Activity.t()} | {:error, any()}
def post_chat_message(%User{} = user, %User{} = recipient, content, opts \\ []) do def post_chat_message(%User{} = user, %User{} = recipient, content, opts \\ []) do
with maybe_attachment <- opts[:media_id] && Object.get_by_id(opts[:media_id]), with maybe_attachment <- opts[:media_id] && Object.get_by_id(opts[:media_id]),
:ok <- validate_chat_attachment_attribution(maybe_attachment, user), :ok <- validate_chat_attachment_attribution(maybe_attachment, user),
@ -96,7 +99,8 @@ defp validate_chat_content_length(content, _) do
end end
end end
def unblock(blocker, blocked) do @spec unblock(User.t(), User.t()) :: {:ok, Activity.t()} | {:error, any()}
def unblock(blocked, blocker) do
with {_, %Activity{} = block} <- {:fetch_block, Utils.fetch_latest_block(blocker, blocked)}, with {_, %Activity{} = block} <- {:fetch_block, Utils.fetch_latest_block(blocker, blocked)},
{:ok, unblock_data, _} <- Builder.undo(blocker, block), {:ok, unblock_data, _} <- Builder.undo(blocker, block),
{:ok, unblock, _} <- Pipeline.common_pipeline(unblock_data, local: true) do {:ok, unblock, _} <- Pipeline.common_pipeline(unblock_data, local: true) do
@ -115,7 +119,9 @@ def unblock(blocker, blocked) do
end end
end end
def follow(follower, followed) do @spec follow(User.t(), User.t()) ::
{:ok, User.t(), User.t(), Activity.t() | Object.t()} | {:error, :rejected}
def follow(followed, follower) do
timeout = Pleroma.Config.get([:activitypub, :follow_handshake_timeout]) timeout = Pleroma.Config.get([:activitypub, :follow_handshake_timeout])
with {:ok, follow_data, _} <- Builder.follow(follower, followed), with {:ok, follow_data, _} <- Builder.follow(follower, followed),
@ -129,7 +135,8 @@ def follow(follower, followed) do
end end
end end
def unfollow(follower, unfollowed) do @spec unfollow(User.t(), User.t()) :: {:ok, User.t()} | {:error, any()}
def unfollow(unfollowed, follower) do
with {:ok, follower, _follow_activity} <- User.unfollow(follower, unfollowed), with {:ok, follower, _follow_activity} <- User.unfollow(follower, unfollowed),
{:ok, _activity} <- ActivityPub.unfollow(follower, unfollowed), {:ok, _activity} <- ActivityPub.unfollow(follower, unfollowed),
{:ok, _subscription} <- User.unsubscribe(follower, unfollowed), {:ok, _subscription} <- User.unsubscribe(follower, unfollowed),
@ -138,6 +145,7 @@ def unfollow(follower, unfollowed) do
end end
end end
@spec accept_follow_request(User.t(), User.t()) :: {:ok, User.t()} | {:error, any()}
def accept_follow_request(follower, followed) do def accept_follow_request(follower, followed) do
with %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed), with %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
{:ok, accept_data, _} <- Builder.accept(followed, follow_activity), {:ok, accept_data, _} <- Builder.accept(followed, follow_activity),
@ -146,6 +154,7 @@ def accept_follow_request(follower, followed) do
end end
end end
@spec reject_follow_request(User.t(), User.t()) :: {:ok, User.t()} | {:error, any()} | nil
def reject_follow_request(follower, followed) do def reject_follow_request(follower, followed) do
with %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed), with %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
{:ok, reject_data, _} <- Builder.reject(followed, follow_activity), {:ok, reject_data, _} <- Builder.reject(followed, follow_activity),
@ -154,6 +163,7 @@ def reject_follow_request(follower, followed) do
end end
end end
@spec delete(String.t(), User.t()) :: {:ok, Activity.t()} | {:error, any()}
def delete(activity_id, user) do def delete(activity_id, user) do
with {_, %Activity{data: %{"object" => _, "type" => "Create"}} = activity} <- with {_, %Activity{data: %{"object" => _, "type" => "Create"}} = activity} <-
{:find_activity, Activity.get_by_id(activity_id, filter: [])}, {:find_activity, Activity.get_by_id(activity_id, filter: [])},
@ -203,6 +213,7 @@ def delete(activity_id, user) do
end end
end end
@spec repeat(String.t(), User.t(), map()) :: {:ok, Activity.t()} | {:error, any()}
def repeat(id, user, params \\ %{}) do def repeat(id, user, params \\ %{}) do
with %Activity{data: %{"type" => "Create"}} = activity <- Activity.get_by_id(id), with %Activity{data: %{"type" => "Create"}} = activity <- Activity.get_by_id(id),
object = %Object{} <- Object.normalize(activity, fetch: false), object = %Object{} <- Object.normalize(activity, fetch: false),
@ -220,6 +231,7 @@ def repeat(id, user, params \\ %{}) do
end end
end end
@spec unrepeat(String.t(), User.t()) :: {:ok, Activity.t()} | {:error, any()}
def unrepeat(id, user) do def unrepeat(id, user) do
with {_, %Activity{data: %{"type" => "Create"}} = activity} <- with {_, %Activity{data: %{"type" => "Create"}} = activity} <-
{:find_activity, Activity.get_by_id(id)}, {:find_activity, Activity.get_by_id(id)},
@ -235,8 +247,8 @@ def unrepeat(id, user) do
end end
end end
@spec favorite(User.t(), binary()) :: {:ok, Activity.t() | :already_liked} | {:error, any()} @spec favorite(String.t(), User.t()) :: {:ok, Activity.t()} | {:error, any()}
def favorite(%User{} = user, id) do def favorite(id, %User{} = user) do
case favorite_helper(user, id) do case favorite_helper(user, id) do
{:ok, _} = res -> {:ok, _} = res ->
res res
@ -250,7 +262,7 @@ def favorite(%User{} = user, id) do
end end
end end
def favorite_helper(user, id) do defp favorite_helper(user, id) do
with {_, %Activity{object: object}} <- {:find_object, Activity.get_by_id_with_object(id)}, with {_, %Activity{object: object}} <- {:find_object, Activity.get_by_id_with_object(id)},
{_, {:ok, like_object, meta}} <- {:build_object, Builder.like(user, object)}, {_, {:ok, like_object, meta}} <- {:build_object, Builder.like(user, object)},
{_, {:ok, %Activity{} = activity, _meta}} <- {_, {:ok, %Activity{} = activity, _meta}} <-
@ -273,6 +285,7 @@ def favorite_helper(user, id) do
end end
end end
@spec unfavorite(String.t(), User.t()) :: {:ok, Activity.t()} | {:error, any()}
def unfavorite(id, user) do def unfavorite(id, user) do
with {_, %Activity{data: %{"type" => "Create"}} = activity} <- with {_, %Activity{data: %{"type" => "Create"}} = activity} <-
{:find_activity, Activity.get_by_id(id)}, {:find_activity, Activity.get_by_id(id)},
@ -288,6 +301,8 @@ def unfavorite(id, user) do
end end
end end
@spec react_with_emoji(String.t(), User.t(), String.t()) ::
{:ok, Activity.t()} | {:error, any()}
def react_with_emoji(id, user, emoji) do def react_with_emoji(id, user, emoji) do
with %Activity{} = activity <- Activity.get_by_id(id), with %Activity{} = activity <- Activity.get_by_id(id),
object <- Object.normalize(activity, fetch: false), object <- Object.normalize(activity, fetch: false),
@ -300,6 +315,8 @@ def react_with_emoji(id, user, emoji) do
end end
end end
@spec unreact_with_emoji(String.t(), User.t(), String.t()) ::
{:ok, Activity.t()} | {:error, any()}
def unreact_with_emoji(id, user, emoji) do def unreact_with_emoji(id, user, emoji) do
with %Activity{} = reaction_activity <- Utils.get_latest_reaction(id, user, emoji), with %Activity{} = reaction_activity <- Utils.get_latest_reaction(id, user, emoji),
{_, {:ok, _}} <- {:cancel_jobs, maybe_cancel_jobs(reaction_activity)}, {_, {:ok, _}} <- {:cancel_jobs, maybe_cancel_jobs(reaction_activity)},
@ -312,7 +329,8 @@ def unreact_with_emoji(id, user, emoji) do
end end
end end
def vote(user, %{data: %{"type" => "Question"}} = object, choices) do @spec vote(Object.t(), User.t(), list()) :: {:ok, list(), Object.t()} | {:error, any()}
def vote(%Object{data: %{"type" => "Question"}} = object, %User{} = user, choices) do
with :ok <- validate_not_author(object, user), with :ok <- validate_not_author(object, user),
:ok <- validate_existing_votes(user, object), :ok <- validate_existing_votes(user, object),
{:ok, options, choices} <- normalize_and_validate_choices(choices, object) do {:ok, options, choices} <- normalize_and_validate_choices(choices, object) do
@ -373,14 +391,16 @@ defp normalize_and_validate_choices(choices, object) do
end end
end end
def public_announce?(_, %{visibility: visibility}) defp public_announce?(_, %{visibility: visibility})
when visibility in ~w{public unlisted private direct}, when visibility in ~w{public unlisted private direct},
do: visibility in ~w(public unlisted) do: visibility in ~w(public unlisted)
def public_announce?(object, _) do defp public_announce?(object, _) do
Visibility.public?(object) Visibility.public?(object)
end end
@spec get_visibility(map(), map() | nil, Participation.t() | nil) ::
{String.t() | nil, String.t() | nil}
def get_visibility(_, _, %Participation{}), do: {"direct", "direct"} def get_visibility(_, _, %Participation{}), do: {"direct", "direct"}
def get_visibility(%{visibility: visibility}, in_reply_to, _) def get_visibility(%{visibility: visibility}, in_reply_to, _)
@ -399,6 +419,7 @@ def get_visibility(_, in_reply_to, _) when not is_nil(in_reply_to) do
def get_visibility(_, in_reply_to, _), do: {"public", get_replied_to_visibility(in_reply_to)} def get_visibility(_, in_reply_to, _), do: {"public", get_replied_to_visibility(in_reply_to)}
@spec get_replied_to_visibility(Activity.t() | nil) :: String.t() | nil
def get_replied_to_visibility(nil), do: nil def get_replied_to_visibility(nil), do: nil
def get_replied_to_visibility(activity) do def get_replied_to_visibility(activity) do
@ -407,6 +428,8 @@ def get_replied_to_visibility(activity) do
end end
end end
@spec check_expiry_date({:ok, nil | integer()} | String.t()) ::
{:ok, boolean() | nil} | {:error, String.t()}
def check_expiry_date({:ok, nil} = res), do: res def check_expiry_date({:ok, nil} = res), do: res
def check_expiry_date({:ok, in_seconds}) do def check_expiry_date({:ok, in_seconds}) do
@ -424,19 +447,22 @@ def check_expiry_date(expiry_str) do
|> check_expiry_date() |> check_expiry_date()
end end
@spec listen(User.t(), map()) :: {:ok, Activity.t()} | {:error, any()}
def listen(user, data) do def listen(user, data) do
with {:ok, draft} <- ActivityDraft.listen(user, data) do with {:ok, draft} <- ActivityDraft.listen(user, data) do
ActivityPub.listen(draft.changes) ActivityPub.listen(draft.changes)
end end
end end
@spec post(User.t(), map()) :: {:ok, Activity.t()} | {:error, any()}
def post(user, %{status: _} = data) do def post(user, %{status: _} = data) do
with {:ok, draft} <- ActivityDraft.create(user, data) do with {:ok, draft} <- ActivityDraft.create(user, data) do
ActivityPub.create(draft.changes, draft.preview?) ActivityPub.create(draft.changes, draft.preview?)
end end
end end
def update(user, orig_activity, changes) do @spec update(Activity.t(), User.t(), map()) :: {:ok, Activity.t()} | {:error, any()}
def update(orig_activity, %User{} = user, changes) do
with orig_object <- Object.normalize(orig_activity), with orig_object <- Object.normalize(orig_activity),
{:ok, new_object} <- make_update_data(user, orig_object, changes), {:ok, new_object} <- make_update_data(user, orig_object, changes),
{:ok, update_data, _} <- Builder.update(user, new_object), {:ok, update_data, _} <- Builder.update(user, new_object),
@ -526,7 +552,8 @@ def unpin(id, user) do
end end
end end
def add_mute(user, activity, params \\ %{}) do @spec add_mute(Activity.t(), User.t(), map()) :: {:ok, Activity.t()} | {:error, any()}
def add_mute(activity, user, params \\ %{}) do
expires_in = Map.get(params, :expires_in, 0) expires_in = Map.get(params, :expires_in, 0)
with {:ok, _} <- ThreadMute.add_mute(user.id, activity.data["context"]), with {:ok, _} <- ThreadMute.add_mute(user.id, activity.data["context"]),
@ -545,15 +572,17 @@ def add_mute(user, activity, params \\ %{}) do
end end
end end
def remove_mute(%User{} = user, %Activity{} = activity) do @spec remove_mute(Activity.t(), User.t()) :: {:ok, Activity.t()} | {:error, any()}
def remove_mute(%Activity{} = activity, %User{} = user) do
ThreadMute.remove_mute(user.id, activity.data["context"]) ThreadMute.remove_mute(user.id, activity.data["context"])
{:ok, activity} {:ok, activity}
end end
def remove_mute(user_id, activity_id) do @spec remove_mute(String.t(), String.t()) :: {:ok, Activity.t()} | {:error, any()}
def remove_mute(activity_id, user_id) do
with {:user, %User{} = user} <- {:user, User.get_by_id(user_id)}, with {:user, %User{} = user} <- {:user, User.get_by_id(user_id)},
{:activity, %Activity{} = activity} <- {:activity, Activity.get_by_id(activity_id)} do {:activity, %Activity{} = activity} <- {:activity, Activity.get_by_id(activity_id)} do
remove_mute(user, activity) remove_mute(activity, user)
else else
{what, result} = error -> {what, result} = error ->
Logger.warning( Logger.warning(
@ -564,13 +593,15 @@ def remove_mute(user_id, activity_id) do
end end
end end
def thread_muted?(%User{id: user_id}, %{data: %{"context" => context}}) @spec thread_muted?(Activity.t(), User.t()) :: boolean()
def thread_muted?(%{data: %{"context" => context}}, %User{id: user_id})
when is_binary(context) do when is_binary(context) do
ThreadMute.exists?(user_id, context) ThreadMute.exists?(user_id, context)
end end
def thread_muted?(_, _), do: false def thread_muted?(_, _), do: false
@spec report(User.t(), map()) :: {:ok, Activity.t()} | {:error, any()}
def report(user, data) do def report(user, data) do
with {:ok, account} <- get_reported_account(data.account_id), with {:ok, account} <- get_reported_account(data.account_id),
{:ok, {content_html, _, _}} <- make_report_content_html(data[:comment]), {:ok, {content_html, _, _}} <- make_report_content_html(data[:comment]),
@ -604,6 +635,8 @@ defp get_report_rules(rule_ids) do
|> Enum.filter(&Rule.exists?/1) |> Enum.filter(&Rule.exists?/1)
end end
@spec update_report_state(String.t() | [String.t()], String.t()) ::
{:ok, any()} | {:error, any()}
def update_report_state(activity_ids, state) when is_list(activity_ids) do def update_report_state(activity_ids, state) when is_list(activity_ids) do
case Utils.update_report_state(activity_ids, state) do case Utils.update_report_state(activity_ids, state) do
:ok -> {:ok, activity_ids} :ok -> {:ok, activity_ids}
@ -619,6 +652,7 @@ def update_report_state(activity_id, state) do
end end
end end
@spec update_activity_scope(String.t(), map()) :: {:ok, any()} | {:error, any()}
def update_activity_scope(activity_id, opts \\ %{}) do def update_activity_scope(activity_id, opts \\ %{}) do
with %Activity{} = activity <- Activity.get_by_id_with_object(activity_id), with %Activity{} = activity <- Activity.get_by_id_with_object(activity_id),
{:ok, activity} <- toggle_sensitive(activity, opts) do {:ok, activity} <- toggle_sensitive(activity, opts) do
@ -652,14 +686,17 @@ 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{} = user, %User{} = target) do @spec hide_reblogs(User.t(), User.t()) :: {:ok, any()} | {:error, any()}
def hide_reblogs(%User{} = target, %User{} = user) do
UserRelationship.create_reblog_mute(user, target) UserRelationship.create_reblog_mute(user, target)
end end
def show_reblogs(%User{} = user, %User{} = target) do @spec show_reblogs(User.t(), User.t()) :: {:ok, any()} | {:error, any()}
def show_reblogs(%User{} = target, %User{} = user) do
UserRelationship.delete_reblog_mute(user, target) UserRelationship.delete_reblog_mute(user, target)
end end
@spec get_user(String.t(), boolean()) :: User.t() | nil
def get_user(ap_id, fake_record_fallback \\ true) do def get_user(ap_id, fake_record_fallback \\ true) do
cond do cond do
user = User.get_cached_by_ap_id(ap_id) -> user = User.get_cached_by_ap_id(ap_id) ->

View file

@ -460,7 +460,7 @@ def unfollow(%{assigns: %{user: %{id: id}, account: %{id: id}}}, _params) do
end end
def unfollow(%{assigns: %{user: follower, account: followed}} = conn, _params) do def unfollow(%{assigns: %{user: follower, account: followed}} = conn, _params) do
with {:ok, follower} <- CommonAPI.unfollow(follower, followed) do with {:ok, follower} <- CommonAPI.unfollow(followed, follower) do
render(conn, "relationship.json", user: follower, target: followed) render(conn, "relationship.json", user: follower, target: followed)
end end
end end
@ -495,7 +495,7 @@ def unmute(%{assigns: %{user: muter, account: muted}} = conn, _params) do
@doc "POST /api/v1/accounts/:id/block" @doc "POST /api/v1/accounts/:id/block"
def block(%{assigns: %{user: blocker, account: blocked}} = conn, _params) do def block(%{assigns: %{user: blocker, account: blocked}} = conn, _params) do
with {:ok, _activity} <- CommonAPI.block(blocker, blocked) do with {:ok, _activity} <- CommonAPI.block(blocked, blocker) do
render(conn, "relationship.json", user: blocker, target: blocked) render(conn, "relationship.json", user: blocker, target: blocked)
else else
{:error, message} -> json_response(conn, :forbidden, %{error: message}) {:error, message} -> json_response(conn, :forbidden, %{error: message})
@ -504,7 +504,7 @@ def block(%{assigns: %{user: blocker, account: blocked}} = conn, _params) do
@doc "POST /api/v1/accounts/:id/unblock" @doc "POST /api/v1/accounts/:id/unblock"
def unblock(%{assigns: %{user: blocker, account: blocked}} = conn, _params) do def unblock(%{assigns: %{user: blocker, account: blocked}} = conn, _params) do
with {:ok, _activity} <- CommonAPI.unblock(blocker, blocked) do with {:ok, _activity} <- CommonAPI.unblock(blocked, blocker) do
render(conn, "relationship.json", user: blocker, target: blocked) render(conn, "relationship.json", user: blocker, target: blocked)
else else
{:error, message} -> json_response(conn, :forbidden, %{error: message}) {:error, message} -> json_response(conn, :forbidden, %{error: message})

View file

@ -51,7 +51,7 @@ def vote(
with %Object{data: %{"type" => "Question"}} = object <- Object.get_by_id(id), with %Object{data: %{"type" => "Question"}} = object <- Object.get_by_id(id),
%Activity{} = activity <- Activity.get_create_by_object_ap_id(object.data["id"]), %Activity{} = activity <- Activity.get_create_by_object_ap_id(object.data["id"]),
true <- Visibility.visible_for_user?(activity, user), true <- Visibility.visible_for_user?(activity, user),
{:ok, _activities, object} <- get_cached_vote_or_vote(user, object, choices) do {:ok, _activities, object} <- get_cached_vote_or_vote(object, user, choices) do
try_render(conn, "show.json", %{object: object, for: user}) try_render(conn, "show.json", %{object: object, for: user})
else else
nil -> render_error(conn, :not_found, "Record not found") nil -> render_error(conn, :not_found, "Record not found")
@ -60,11 +60,11 @@ def vote(
end end
end end
defp get_cached_vote_or_vote(user, object, choices) do defp get_cached_vote_or_vote(object, user, choices) do
idempotency_key = "polls:#{user.id}:#{object.data["id"]}" idempotency_key = "polls:#{user.id}:#{object.data["id"]}"
@cachex.fetch!(:idempotency_cache, idempotency_key, fn _ -> @cachex.fetch!(:idempotency_cache, idempotency_key, fn _ ->
case CommonAPI.vote(user, object, choices) do case CommonAPI.vote(object, user, choices) do
{:error, _message} = res -> {:ignore, res} {:error, _message} = res -> {:ignore, res}
res -> {:commit, res} res -> {:commit, res}
end end

View file

@ -276,7 +276,7 @@ def update(
actor <- Activity.user_actor(activity), actor <- Activity.user_actor(activity),
{_, true} <- {:own_status, actor.id == user.id}, {_, true} <- {:own_status, actor.id == user.id},
changes <- body_params |> put_application(conn), changes <- body_params |> put_application(conn),
{_, {:ok, _update_activity}} <- {:pipeline, CommonAPI.update(user, activity, changes)}, {_, {:ok, _update_activity}} <- {:pipeline, CommonAPI.update(activity, user, changes)},
{_, %Activity{}} = {_, activity} <- {:refetched, Activity.get_by_id_with_object(id)} do {_, %Activity{}} = {_, activity} <- {:refetched, Activity.get_by_id_with_object(id)} do
try_render(conn, "show.json", try_render(conn, "show.json",
activity: activity, activity: activity,
@ -357,7 +357,7 @@ def favourite(
conn, conn,
_ _
) do ) do
with {:ok, _fav} <- CommonAPI.favorite(user, activity_id), with {:ok, _fav} <- CommonAPI.favorite(activity_id, user),
%Activity{} = activity <- Activity.get_by_id(activity_id) do %Activity{} = activity <- Activity.get_by_id(activity_id) do
try_render(conn, "show.json", activity: activity, for: user, as: :activity) try_render(conn, "show.json", activity: activity, for: user, as: :activity)
end end
@ -453,7 +453,7 @@ def mute_conversation(
_ _
) do ) do
with %Activity{} = activity <- Activity.get_by_id(id), with %Activity{} = activity <- Activity.get_by_id(id),
{:ok, activity} <- CommonAPI.add_mute(user, activity, params) do {:ok, activity} <- CommonAPI.add_mute(activity, user, params) do
try_render(conn, "show.json", activity: activity, for: user, as: :activity) try_render(conn, "show.json", activity: activity, for: user, as: :activity)
end end
end end
@ -467,7 +467,7 @@ def unmute_conversation(
_ _
) do ) do
with %Activity{} = activity <- Activity.get_by_id(id), with %Activity{} = activity <- Activity.get_by_id(id),
{:ok, activity} <- CommonAPI.remove_mute(user, activity) do {:ok, activity} <- CommonAPI.remove_mute(activity, user) do
try_render(conn, "show.json", activity: activity, for: user, as: :activity) try_render(conn, "show.json", activity: activity, for: user, as: :activity)
end end
end end

View file

@ -16,7 +16,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
def follow(follower, followed, params \\ %{}) do def follow(follower, followed, params \\ %{}) do
result = result =
if not User.following?(follower, followed) do if not User.following?(follower, followed) do
CommonAPI.follow(follower, followed) CommonAPI.follow(followed, follower)
else else
{:ok, follower, followed, nil} {:ok, follower, followed, nil}
end end
@ -30,11 +30,11 @@ def follow(follower, followed, params \\ %{}) do
end end
defp set_reblogs_visibility(false, {:ok, follower, followed, _}) do defp set_reblogs_visibility(false, {:ok, follower, followed, _}) do
CommonAPI.hide_reblogs(follower, followed) CommonAPI.hide_reblogs(followed, follower)
end end
defp set_reblogs_visibility(_, {:ok, follower, followed, _}) do defp set_reblogs_visibility(_, {:ok, follower, followed, _}) do
CommonAPI.show_reblogs(follower, followed) CommonAPI.show_reblogs(followed, follower)
end end
defp set_subscription(true, {:ok, follower, followed, _}) do defp set_subscription(true, {:ok, follower, followed, _}) do

View file

@ -293,7 +293,7 @@ def render("show.json", %{activity: %{data: %{"object" => _object}} = activity}
cond do cond do
is_nil(opts[:for]) -> false is_nil(opts[:for]) -> false
is_boolean(activity.thread_muted?) -> activity.thread_muted? is_boolean(activity.thread_muted?) -> activity.thread_muted?
true -> CommonAPI.thread_muted?(opts[:for], activity) true -> CommonAPI.thread_muted?(activity, opts[:for])
end end
attachment_data = object.data["attachment"] || [] attachment_data = object.data["attachment"] || []

View file

@ -206,7 +206,7 @@ def filtered_by_user?(%User{} = user, %Activity{} = item, streamed_type) do
false <- Pleroma.Web.ActivityPub.MRF.subdomain_match?(domain_blocks, item_host), false <- Pleroma.Web.ActivityPub.MRF.subdomain_match?(domain_blocks, item_host),
false <- Pleroma.Web.ActivityPub.MRF.subdomain_match?(domain_blocks, parent_host), false <- Pleroma.Web.ActivityPub.MRF.subdomain_match?(domain_blocks, parent_host),
true <- thread_containment(item, user), true <- thread_containment(item, user),
false <- CommonAPI.thread_muted?(user, parent) do false <- CommonAPI.thread_muted?(parent, user) do
false false
else else
_ -> true _ -> true

View file

@ -73,7 +73,7 @@ defp status?(acct) do
# #
def do_follow(%{assigns: %{user: %User{} = user}} = conn, %{"user" => %{"id" => id}}) do def do_follow(%{assigns: %{user: %User{} = user}} = conn, %{"user" => %{"id" => id}}) do
with {:fetch_user, %User{} = followee} <- {:fetch_user, User.get_cached_by_id(id)}, with {:fetch_user, %User{} = followee} <- {:fetch_user, User.get_cached_by_id(id)},
{:ok, _, _, _} <- CommonAPI.follow(user, followee) do {:ok, _, _, _} <- CommonAPI.follow(followee, user) do
redirect(conn, to: "/users/#{followee.id}") redirect(conn, to: "/users/#{followee.id}")
else else
error -> error ->
@ -90,7 +90,7 @@ def do_follow(conn, %{"authorization" => %{"name" => _, "password" => _, "id" =>
with {_, %User{} = followee} <- {:fetch_user, User.get_cached_by_id(id)}, with {_, %User{} = followee} <- {:fetch_user, User.get_cached_by_id(id)},
{_, {:ok, user}, _} <- {:auth, WrapperAuthenticator.get_user(conn), followee}, {_, {:ok, user}, _} <- {:auth, WrapperAuthenticator.get_user(conn), followee},
{_, _, _, false} <- {:mfa_required, followee, user, MFA.require?(user)}, {_, _, _, false} <- {:mfa_required, followee, user, MFA.require?(user)},
{:ok, _, _, _} <- CommonAPI.follow(user, followee) do {:ok, _, _, _} <- CommonAPI.follow(followee, user) do
redirect(conn, to: "/users/#{followee.id}") redirect(conn, to: "/users/#{followee.id}")
else else
error -> error ->
@ -108,7 +108,7 @@ def do_follow(conn, %{"mfa" => %{"code" => code, "token" => token, "id" => id}})
{_, _, {:ok, %{user: user}}} <- {:mfa_token, followee, MFA.Token.validate(token)}, {_, _, {:ok, %{user: user}}} <- {:mfa_token, followee, MFA.Token.validate(token)},
{_, _, _, {:ok, _}} <- {_, _, _, {:ok, _}} <-
{:verify_mfa_code, followee, token, TOTPAuthenticator.verify(code, user)}, {:verify_mfa_code, followee, token, TOTPAuthenticator.verify(code, user)},
{:ok, _, _, _} <- CommonAPI.follow(user, followee) do {:ok, _, _, _} <- CommonAPI.follow(followee, user) do
redirect(conn, to: "/users/#{followee.id}") redirect(conn, to: "/users/#{followee.id}")
else else
error -> error ->

View file

@ -14,7 +14,7 @@ def perform(%Job{args: %{"op" => "unmute_user", "muter_id" => muter_id, "mutee_i
def perform(%Job{ def perform(%Job{
args: %{"op" => "unmute_conversation", "user_id" => user_id, "activity_id" => activity_id} args: %{"op" => "unmute_conversation", "user_id" => user_id, "activity_id" => activity_id}
}) do }) do
Pleroma.Web.CommonAPI.remove_mute(user_id, activity_id) Pleroma.Web.CommonAPI.remove_mute(activity_id, user_id)
:ok :ok
end end

View file

@ -251,7 +251,7 @@ test "with the --keep-threads option it deletes old threads with no local intera
|> Repo.update!() |> Repo.update!()
{:ok, old_favourite_activity} = {:ok, old_favourite_activity} =
CommonAPI.favorite(remote_user2, old_remote_post_activity.id) CommonAPI.favorite(old_remote_post_activity.id, remote_user2)
old_favourite_activity old_favourite_activity
|> Ecto.Changeset.change(%{local: false, updated_at: old_insert_date}) |> Ecto.Changeset.change(%{local: false, updated_at: old_insert_date})
@ -302,7 +302,7 @@ test "with the --keep-threads option it keeps old threads with local interaction
|> Ecto.Changeset.change(%{local: false, updated_at: old_insert_date}) |> Ecto.Changeset.change(%{local: false, updated_at: old_insert_date})
|> Repo.update!() |> Repo.update!()
{:ok, old_favourite_activity} = CommonAPI.favorite(local_user, old_remote_post3_activity.id) {:ok, old_favourite_activity} = CommonAPI.favorite(old_remote_post3_activity.id, local_user)
old_favourite_activity old_favourite_activity
|> Ecto.Changeset.change(%{local: true, updated_at: old_insert_date}) |> Ecto.Changeset.change(%{local: true, updated_at: old_insert_date})
@ -586,7 +586,7 @@ test "it turns OrderedCollection likes into empty arrays" do
{:ok, %{id: id, object: object}} = CommonAPI.post(user, %{status: "test"}) {:ok, %{id: id, object: object}} = CommonAPI.post(user, %{status: "test"})
{:ok, %{object: object2}} = CommonAPI.post(user, %{status: "test test"}) {:ok, %{object: object2}} = CommonAPI.post(user, %{status: "test test"})
CommonAPI.favorite(user2, id) CommonAPI.favorite(id, user2)
likes = %{ likes = %{
"first" => "first" =>

View file

@ -249,7 +249,7 @@ test "get_by_object_ap_id_with_object/1" do
{:ok, %{id: id, object: %{data: %{"id" => obj_id}}}} = {:ok, %{id: id, object: %{data: %{"id" => obj_id}}}} =
Pleroma.Web.CommonAPI.post(user, %{status: "cofe"}) Pleroma.Web.CommonAPI.post(user, %{status: "cofe"})
Pleroma.Web.CommonAPI.favorite(another, id) Pleroma.Web.CommonAPI.favorite(id, another)
assert obj_id assert obj_id
|> Pleroma.Activity.Queries.by_object_id() |> Pleroma.Activity.Queries.by_object_id()

View file

@ -404,7 +404,7 @@ test "disconnect when token is revoked", %{app: app, user: user, token: token} d
test "receives private statuses", %{user: reading_user, token: token} do test "receives private statuses", %{user: reading_user, token: token} do
user = insert(:user) user = insert(:user)
CommonAPI.follow(reading_user, user) CommonAPI.follow(user, reading_user)
{:ok, _} = start_socket("?stream=user&access_token=#{token.token}") {:ok, _} = start_socket("?stream=user&access_token=#{token.token}")
@ -431,7 +431,7 @@ test "receives private statuses", %{user: reading_user, token: token} do
test "receives edits", %{user: reading_user, token: token} do test "receives edits", %{user: reading_user, token: token} do
user = insert(:user) user = insert(:user)
CommonAPI.follow(reading_user, user) CommonAPI.follow(user, reading_user)
{:ok, _} = start_socket("?stream=user&access_token=#{token.token}") {:ok, _} = start_socket("?stream=user&access_token=#{token.token}")
@ -440,7 +440,7 @@ test "receives edits", %{user: reading_user, token: token} do
assert_receive {:text, _raw_json}, 1_000 assert_receive {:text, _raw_json}, 1_000
{:ok, _} = CommonAPI.update(user, activity, %{status: "mew mew", visibility: "private"}) {:ok, _} = CommonAPI.update(activity, user, %{status: "mew mew", visibility: "private"})
assert_receive {:text, raw_json}, 1_000 assert_receive {:text, raw_json}, 1_000
@ -459,7 +459,7 @@ test "receives edits", %{user: reading_user, token: token} do
test "receives notifications", %{user: reading_user, token: token} do test "receives notifications", %{user: reading_user, token: token} do
user = insert(:user) user = insert(:user)
CommonAPI.follow(reading_user, user) CommonAPI.follow(user, reading_user)
{:ok, _} = start_socket("?stream=user:notification&access_token=#{token.token}") {:ok, _} = start_socket("?stream=user:notification&access_token=#{token.token}")

View file

@ -21,7 +21,7 @@ test "it fills in missing notification types" do
{:ok, post} = CommonAPI.post(user, %{status: "yeah, @#{other_user.nickname}"}) {:ok, post} = CommonAPI.post(user, %{status: "yeah, @#{other_user.nickname}"})
{:ok, chat} = CommonAPI.post_chat_message(user, other_user, "yo") {:ok, chat} = CommonAPI.post_chat_message(user, other_user, "yo")
{:ok, react} = CommonAPI.react_with_emoji(post.id, other_user, "") {:ok, react} = CommonAPI.react_with_emoji(post.id, other_user, "")
{:ok, like} = CommonAPI.favorite(other_user, post.id) {:ok, like} = CommonAPI.favorite(post.id, other_user)
{:ok, react_2} = CommonAPI.react_with_emoji(post.id, other_user, "") {:ok, react_2} = CommonAPI.react_with_emoji(post.id, other_user, "")
data = data =

View file

@ -165,7 +165,7 @@ test "it sends edited notifications to those who repeated a status" do
{:ok, _activity_two} = CommonAPI.repeat(activity_one.id, repeated_user) {:ok, _activity_two} = CommonAPI.repeat(activity_one.id, repeated_user)
{:ok, _edit_activity} = {:ok, _edit_activity} =
CommonAPI.update(user, activity_one, %{ CommonAPI.update(activity_one, user, %{
status: "hey @#{other_user.nickname}! mew mew" status: "hey @#{other_user.nickname}! mew mew"
}) })
@ -180,8 +180,8 @@ test "create_poll_notifications/1" do
question = insert(:question, user: user1) question = insert(:question, user: user1)
activity = insert(:question_activity, question: question) activity = insert(:question_activity, question: question)
{:ok, _, _} = CommonAPI.vote(user2, question, [0]) {:ok, _, _} = CommonAPI.vote(question, user2, [0])
{:ok, _, _} = CommonAPI.vote(user3, question, [1]) {:ok, _, _} = CommonAPI.vote(question, user3, [1])
{:ok, notifications} = Notification.create_poll_notifications(activity) {:ok, notifications} = Notification.create_poll_notifications(activity)
@ -209,7 +209,7 @@ test "it disables notifications from non-followees" do
notification_settings: %Pleroma.User.NotificationSetting{block_from_strangers: true} notification_settings: %Pleroma.User.NotificationSetting{block_from_strangers: true}
) )
CommonAPI.follow(follower, followed) CommonAPI.follow(followed, follower)
{:ok, activity} = CommonAPI.post(follower, %{status: "hey @#{followed.nickname}"}) {:ok, activity} = CommonAPI.post(follower, %{status: "hey @#{followed.nickname}"})
refute Notification.create_notification(activity, followed) refute Notification.create_notification(activity, followed)
end end
@ -222,7 +222,7 @@ test "it allows notifications from followees" do
notification_settings: %Pleroma.User.NotificationSetting{block_from_strangers: true} notification_settings: %Pleroma.User.NotificationSetting{block_from_strangers: true}
) )
CommonAPI.follow(receiver, poster) CommonAPI.follow(poster, receiver)
{:ok, activity} = CommonAPI.post(poster, %{status: "hey @#{receiver.nickname}"}) {:ok, activity} = CommonAPI.post(poster, %{status: "hey @#{receiver.nickname}"})
assert Notification.create_notification(activity, receiver) assert Notification.create_notification(activity, receiver)
end end
@ -238,7 +238,7 @@ test "it doesn't create duplicate notifications for follow+subscribed users" do
user = insert(:user) user = insert(:user)
subscriber = insert(:user) subscriber = insert(:user)
{:ok, _, _, _} = CommonAPI.follow(subscriber, user) {:ok, _, _, _} = CommonAPI.follow(user, subscriber)
User.subscribe(subscriber, user) User.subscribe(subscriber, user)
{:ok, status} = CommonAPI.post(user, %{status: "Akariiiin"}) {:ok, status} = CommonAPI.post(user, %{status: "Akariiiin"})
{:ok, [_notif]} = Notification.create_notifications(status) {:ok, [_notif]} = Notification.create_notifications(status)
@ -295,7 +295,7 @@ test "it creates notifications when someone likes user's status with a filtered
insert(:filter, user: user, phrase: "tesla", hide: true) insert(:filter, user: user, phrase: "tesla", hide: true)
{:ok, activity_one} = CommonAPI.post(user, %{status: "wow tesla"}) {:ok, activity_one} = CommonAPI.post(user, %{status: "wow tesla"})
{:ok, activity_two} = CommonAPI.favorite(other_user, activity_one.id) {:ok, activity_two} = CommonAPI.favorite(activity_one.id, other_user)
{:ok, [notification]} = Notification.create_notifications(activity_two) {:ok, [notification]} = Notification.create_notifications(activity_two)
@ -309,7 +309,7 @@ test "it creates `follow` notification for approved Follow activity" do
user = insert(:user) user = insert(:user)
followed_user = insert(:user, is_locked: false) followed_user = insert(:user, is_locked: false)
{:ok, _, _, _activity} = CommonAPI.follow(user, followed_user) {:ok, _, _, _activity} = CommonAPI.follow(followed_user, user)
assert FollowingRelationship.following?(user, followed_user) assert FollowingRelationship.following?(user, followed_user)
assert [notification] = Notification.for_user(followed_user) assert [notification] = Notification.for_user(followed_user)
@ -324,7 +324,7 @@ test "it creates `follow_request` notification for pending Follow activity" do
user = insert(:user) user = insert(:user)
followed_user = insert(:user, is_locked: true) followed_user = insert(:user, is_locked: true)
{:ok, _, _, _activity} = CommonAPI.follow(user, followed_user) {:ok, _, _, _activity} = CommonAPI.follow(followed_user, user)
refute FollowingRelationship.following?(user, followed_user) refute FollowingRelationship.following?(user, followed_user)
assert [notification] = Notification.for_user(followed_user) assert [notification] = Notification.for_user(followed_user)
@ -349,12 +349,12 @@ test "it doesn't create a notification for follow-unfollow-follow chains" do
user = insert(:user) user = insert(:user)
followed_user = insert(:user, is_locked: false) followed_user = insert(:user, is_locked: false)
{:ok, _, _, _activity} = CommonAPI.follow(user, followed_user) {:ok, _, _, _activity} = CommonAPI.follow(followed_user, user)
assert FollowingRelationship.following?(user, followed_user) assert FollowingRelationship.following?(user, followed_user)
assert [notification] = Notification.for_user(followed_user) assert [notification] = Notification.for_user(followed_user)
CommonAPI.unfollow(user, followed_user) CommonAPI.unfollow(followed_user, user)
{:ok, _, _, _activity_dupe} = CommonAPI.follow(user, followed_user) {:ok, _, _, _activity_dupe} = CommonAPI.follow(followed_user, user)
notification_id = notification.id notification_id = notification.id
assert [%{id: ^notification_id}] = Notification.for_user(followed_user) assert [%{id: ^notification_id}] = Notification.for_user(followed_user)
@ -363,7 +363,7 @@ test "it doesn't create a notification for follow-unfollow-follow chains" do
test "dismisses the notification on follow request rejection" do test "dismisses the notification on follow request rejection" do
user = insert(:user, is_locked: true) user = insert(:user, is_locked: true)
follower = insert(:user) follower = insert(:user)
{:ok, _, _, _follow_activity} = CommonAPI.follow(follower, user) {:ok, _, _, _follow_activity} = CommonAPI.follow(user, follower)
assert [_notification] = Notification.for_user(user) assert [_notification] = Notification.for_user(user)
{:ok, _follower} = CommonAPI.reject_follow_request(follower, user) {:ok, _follower} = CommonAPI.reject_follow_request(follower, user)
assert [] = Notification.for_user(user) assert [] = Notification.for_user(user)
@ -617,7 +617,7 @@ test "it does not send notification to mentioned users in likes" do
status: "hey @#{other_user.nickname}!" status: "hey @#{other_user.nickname}!"
}) })
{:ok, activity_two} = CommonAPI.favorite(third_user, activity_one.id) {:ok, activity_two} = CommonAPI.favorite(activity_one.id, third_user)
enabled_receivers = Notification.get_notified_from_activity(activity_two) enabled_receivers = Notification.get_notified_from_activity(activity_two)
@ -693,7 +693,7 @@ test "it does not return thread-muting recipient in recipients list" do
{:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}!"}) {:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}!"})
{:ok, _} = CommonAPI.add_mute(other_user, activity) {:ok, _} = CommonAPI.add_mute(activity, other_user)
{:ok, same_context_activity} = {:ok, same_context_activity} =
CommonAPI.post(user, %{ CommonAPI.post(user, %{
@ -748,7 +748,7 @@ test "it sends edited notifications to those who repeated a status" do
{:ok, _activity_two} = CommonAPI.repeat(activity_one.id, repeated_user) {:ok, _activity_two} = CommonAPI.repeat(activity_one.id, repeated_user)
{:ok, edit_activity} = {:ok, edit_activity} =
CommonAPI.update(user, activity_one, %{ CommonAPI.update(activity_one, user, %{
status: "hey @#{other_user.nickname}! mew mew" status: "hey @#{other_user.nickname}! mew mew"
}) })
@ -768,7 +768,7 @@ test "liking an activity results in 1 notification, then 0 if the activity is de
assert Enum.empty?(Notification.for_user(user)) assert Enum.empty?(Notification.for_user(user))
{:ok, _} = CommonAPI.favorite(other_user, activity.id) {:ok, _} = CommonAPI.favorite(activity.id, other_user)
assert length(Notification.for_user(user)) == 1 assert length(Notification.for_user(user)) == 1
@ -785,7 +785,7 @@ test "liking an activity results in 1 notification, then 0 if the activity is un
assert Enum.empty?(Notification.for_user(user)) assert Enum.empty?(Notification.for_user(user))
{:ok, _} = CommonAPI.favorite(other_user, activity.id) {:ok, _} = CommonAPI.favorite(activity.id, other_user)
assert length(Notification.for_user(user)) == 1 assert length(Notification.for_user(user)) == 1
@ -840,7 +840,7 @@ test "liking an activity which is already deleted does not generate a notificati
assert Enum.empty?(Notification.for_user(user)) assert Enum.empty?(Notification.for_user(user))
{:error, :not_found} = CommonAPI.favorite(other_user, activity.id) {:error, :not_found} = CommonAPI.favorite(activity.id, other_user)
assert Enum.empty?(Notification.for_user(user)) assert Enum.empty?(Notification.for_user(user))
end end
@ -1090,7 +1090,7 @@ test "it returns notifications about favorites with filtered word", %{user: user
another_user = insert(:user) another_user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: "Give me my cofe!"}) {:ok, activity} = CommonAPI.post(user, %{status: "Give me my cofe!"})
{:ok, _} = CommonAPI.favorite(another_user, activity.id) {:ok, _} = CommonAPI.favorite(activity.id, another_user)
assert length(Notification.for_user(user)) == 1 assert length(Notification.for_user(user)) == 1
end end
@ -1101,7 +1101,7 @@ test "it returns notifications when related object is without content and filter
insert(:filter, user: followed_user, phrase: "test", hide: true) insert(:filter, user: followed_user, phrase: "test", hide: true)
{:ok, _, _, _activity} = CommonAPI.follow(user, followed_user) {:ok, _, _, _activity} = CommonAPI.follow(followed_user, user)
refute FollowingRelationship.following?(user, followed_user) refute FollowingRelationship.following?(user, followed_user)
assert [notification] = Notification.for_user(followed_user) assert [notification] = Notification.for_user(followed_user)

View file

@ -403,7 +403,7 @@ test "preserves internal fields on refetch", %{mock_modified: mock_modified} do
user = insert(:user) user = insert(:user)
activity = Activity.get_create_by_object_ap_id(object.data["id"]) activity = Activity.get_create_by_object_ap_id(object.data["id"])
{:ok, activity} = CommonAPI.favorite(user, activity.id) {:ok, activity} = CommonAPI.favorite(activity.id, user)
object = Object.get_by_ap_id(activity.data["object"]) object = Object.get_by_ap_id(activity.data["object"])
assert object.data["like_count"] == 1 assert object.data["like_count"] == 1

View file

@ -18,7 +18,7 @@ defmodule Pleroma.ResilienceTest do
other_user = insert(:user) other_user = insert(:user)
{:ok, post_one} = CommonAPI.post(user, %{status: "Here is a post"}) {:ok, post_one} = CommonAPI.post(user, %{status: "Here is a post"})
{:ok, like} = CommonAPI.favorite(other_user, post_one.id) {:ok, like} = CommonAPI.favorite(post_one.id, other_user)
%{ %{
user: user, user: user,
@ -90,7 +90,7 @@ test "after destruction of like activities, things still work", %{
|> json_response(200) |> json_response(200)
# Favoriting again doesn't hurt # Favoriting again doesn't hurt
{:ok, _like_two} = CommonAPI.favorite(other_user, post.id) {:ok, _like_two} = CommonAPI.favorite(post.id, other_user)
post = Repo.get(Activity, post.id) post = Repo.get(Activity, post.id)

View file

@ -73,8 +73,8 @@ test "doesn't count unrelated activities" do
user = insert(:user) user = insert(:user)
other_user = insert(:user) other_user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{visibility: "public", status: "hey"}) {:ok, activity} = CommonAPI.post(user, %{visibility: "public", status: "hey"})
_ = CommonAPI.follow(user, other_user) _ = CommonAPI.follow(other_user, user)
CommonAPI.favorite(other_user, activity.id) CommonAPI.favorite(activity.id, other_user)
CommonAPI.repeat(activity.id, other_user) CommonAPI.repeat(activity.id, other_user)
assert %{"direct" => 0, "private" => 0, "public" => 1, "unlisted" => 0} = assert %{"direct" => 0, "private" => 0, "public" => 1, "unlisted" => 0} =

View file

@ -177,13 +177,13 @@ test "it creates a zip archive with user data" do
{:ok, %{object: %{data: %{"id" => id3}}} = status3} = {:ok, %{object: %{data: %{"id" => id3}}} = status3} =
CommonAPI.post(user, %{status: "status3"}) CommonAPI.post(user, %{status: "status3"})
CommonAPI.favorite(user, status1.id) CommonAPI.favorite(status1.id, user)
CommonAPI.favorite(user, status2.id) CommonAPI.favorite(status2.id, user)
Bookmark.create(user.id, status2.id) Bookmark.create(user.id, status2.id)
Bookmark.create(user.id, status3.id) Bookmark.create(user.id, status3.id)
CommonAPI.follow(user, other_user) CommonAPI.follow(other_user, user)
assert {:ok, backup} = user |> Backup.new() |> Repo.insert() assert {:ok, backup} = user |> Backup.new() |> Repo.insert()
assert {:ok, path} = Backup.export(backup, self()) assert {:ok, path} = Backup.export(backup, self())
@ -283,7 +283,7 @@ test "it counts the correct number processed" do
Enum.map(1..120, fn i -> Enum.map(1..120, fn i ->
{:ok, status} = CommonAPI.post(user, %{status: "status #{i}"}) {:ok, status} = CommonAPI.post(user, %{status: "status #{i}"})
CommonAPI.favorite(user, status.id) CommonAPI.favorite(status.id, user)
Bookmark.create(user.id, status.id) Bookmark.create(user.id, status.id)
end) end)
@ -337,8 +337,8 @@ test "it handles errors" do
{:ok, status1} = CommonAPI.post(user, %{status: "status1"}) {:ok, status1} = CommonAPI.post(user, %{status: "status1"})
{:ok, status2} = CommonAPI.post(user, %{status: "status2"}) {:ok, status2} = CommonAPI.post(user, %{status: "status2"})
{:ok, status3} = CommonAPI.post(user, %{status: "status3"}) {:ok, status3} = CommonAPI.post(user, %{status: "status3"})
CommonAPI.favorite(user, status1.id) CommonAPI.favorite(status1.id, user)
CommonAPI.favorite(user, status2.id) CommonAPI.favorite(status2.id, user)
Bookmark.create(user.id, status2.id) Bookmark.create(user.id, status2.id)
Bookmark.create(user.id, status3.id) Bookmark.create(user.id, status3.id)

View file

@ -182,8 +182,8 @@ test "returns all pending follow requests" do
locked = insert(:user, is_locked: true) locked = insert(:user, is_locked: true)
follower = insert(:user) follower = insert(:user)
CommonAPI.follow(follower, unlocked) CommonAPI.follow(unlocked, follower)
CommonAPI.follow(follower, locked) CommonAPI.follow(locked, follower)
assert [] = User.get_follow_requests(unlocked) assert [] = User.get_follow_requests(unlocked)
assert [activity] = User.get_follow_requests(locked) assert [activity] = User.get_follow_requests(locked)
@ -196,9 +196,9 @@ test "doesn't return already accepted or duplicate follow requests" do
pending_follower = insert(:user) pending_follower = insert(:user)
accepted_follower = insert(:user) accepted_follower = insert(:user)
CommonAPI.follow(pending_follower, locked) CommonAPI.follow(locked, pending_follower)
CommonAPI.follow(pending_follower, locked) CommonAPI.follow(locked, pending_follower)
CommonAPI.follow(accepted_follower, locked) CommonAPI.follow(locked, accepted_follower)
Pleroma.FollowingRelationship.update(accepted_follower, locked, :follow_accept) Pleroma.FollowingRelationship.update(accepted_follower, locked, :follow_accept)
@ -209,7 +209,7 @@ test "doesn't return follow requests for deactivated accounts" do
locked = insert(:user, is_locked: true) locked = insert(:user, is_locked: true)
pending_follower = insert(:user, %{is_active: false}) pending_follower = insert(:user, %{is_active: false})
CommonAPI.follow(pending_follower, locked) CommonAPI.follow(locked, pending_follower)
refute pending_follower.is_active refute pending_follower.is_active
assert [] = User.get_follow_requests(locked) assert [] = User.get_follow_requests(locked)
@ -219,7 +219,7 @@ test "clears follow requests when requester is blocked" do
followed = insert(:user, is_locked: true) followed = insert(:user, is_locked: true)
follower = insert(:user) follower = insert(:user)
CommonAPI.follow(follower, followed) CommonAPI.follow(followed, follower)
assert [_activity] = User.get_follow_requests(followed) assert [_activity] = User.get_follow_requests(followed)
{:ok, _user_relationship} = User.block(followed, follower) {:ok, _user_relationship} = User.block(followed, follower)
@ -1526,7 +1526,7 @@ test "hide a user's statuses from timelines and notifications" do
assert [activity] == ActivityPub.fetch_public_activities(%{}) |> Repo.preload(:bookmark) assert [activity] == ActivityPub.fetch_public_activities(%{}) |> Repo.preload(:bookmark)
assert [%{activity | thread_muted?: CommonAPI.thread_muted?(user2, activity)}] == assert [%{activity | thread_muted?: CommonAPI.thread_muted?(activity, user2)}] ==
ActivityPub.fetch_activities([user2.ap_id | User.following(user2)], %{ ActivityPub.fetch_activities([user2.ap_id | User.following(user2)], %{
user: user2 user: user2
}) })
@ -1691,8 +1691,8 @@ test "it deactivates a user, all follow relationships and all activities", %{use
object_two = insert(:note, user: follower) object_two = insert(:note, user: follower)
activity_two = insert(:note_activity, user: follower, note: object_two) activity_two = insert(:note_activity, user: follower, note: object_two)
{:ok, like} = CommonAPI.favorite(user, activity_two.id) {:ok, like} = CommonAPI.favorite(activity_two.id, user)
{:ok, like_two} = CommonAPI.favorite(follower, activity.id) {:ok, like_two} = CommonAPI.favorite(activity.id, follower)
{:ok, repeat} = CommonAPI.repeat(activity_two.id, user) {:ok, repeat} = CommonAPI.repeat(activity_two.id, user)
{:ok, job} = User.delete(user) {:ok, job} = User.delete(user)

View file

@ -1224,7 +1224,7 @@ test "forwarded report from mastodon", %{conn: conn} do
note = insert(:note_activity, user: reported_user) note = insert(:note_activity, user: reported_user)
Pleroma.Web.CommonAPI.favorite(another, note.id) Pleroma.Web.CommonAPI.favorite(note.id, another)
mock_json_body = mock_json_body =
"test/fixtures/mastodon/application_actor.json" "test/fixtures/mastodon/application_actor.json"
@ -1402,7 +1402,7 @@ test "It returns poll Answers when authenticated", %{conn: conn} do
assert question = Object.normalize(activity, fetch: false) assert question = Object.normalize(activity, fetch: false)
{:ok, [activity], _object} = CommonAPI.vote(voter, question, [1]) {:ok, [activity], _object} = CommonAPI.vote(question, voter, [1])
assert outbox_get = assert outbox_get =
conn conn
@ -1747,7 +1747,7 @@ test "it renders the page, if the user has 'hide_followers' set and the request
%{conn: conn} do %{conn: conn} do
user = insert(:user, hide_followers: true) user = insert(:user, hide_followers: true)
other_user = insert(:user) other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user)
result = result =
conn conn
@ -1843,7 +1843,7 @@ test "it renders the page, if the user has 'hide_follows' set and the request is
%{conn: conn} do %{conn: conn} do
user = insert(:user, hide_follows: true) user = insert(:user, hide_follows: true)
other_user = insert(:user) other_user = insert(:user)
{:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, _other_user, _activity} = CommonAPI.follow(other_user, user)
result = result =
conn conn

View file

@ -1038,7 +1038,7 @@ test "doesn't return activities from blocked domains" do
refute activity in activities refute activity in activities
followed_user = insert(:user) followed_user = insert(:user)
CommonAPI.follow(user, followed_user) CommonAPI.follow(followed_user, user)
{:ok, repeat_activity} = CommonAPI.repeat(activity.id, followed_user) {:ok, repeat_activity} = CommonAPI.repeat(activity.id, followed_user)
activities = ActivityPub.fetch_activities([], %{blocking_user: user, skip_preload: true}) activities = ActivityPub.fetch_activities([], %{blocking_user: user, skip_preload: true})
@ -1171,7 +1171,7 @@ test "doesn't return thread muted activities" do
note_two = insert(:note, data: %{"context" => "suya.."}) note_two = insert(:note, data: %{"context" => "suya.."})
activity_two = insert(:note_activity, note: note_two) activity_two = insert(:note_activity, note: note_two)
{:ok, _activity_two} = CommonAPI.add_mute(user, activity_two) {:ok, _activity_two} = CommonAPI.add_mute(activity_two, user)
assert [_activity_one] = ActivityPub.fetch_activities([], %{muting_user: user}) assert [_activity_one] = ActivityPub.fetch_activities([], %{muting_user: user})
end end
@ -1182,7 +1182,7 @@ test "returns thread muted activities when with_muted is set" do
note_two = insert(:note, data: %{"context" => "suya.."}) note_two = insert(:note, data: %{"context" => "suya.."})
activity_two = insert(:note_activity, note: note_two) activity_two = insert(:note_activity, note: note_two)
{:ok, _activity_two} = CommonAPI.add_mute(user, activity_two) {:ok, _activity_two} = CommonAPI.add_mute(activity_two, user)
assert [_activity_two, _activity_one] = assert [_activity_two, _activity_one] =
ActivityPub.fetch_activities([], %{muting_user: user, with_muted: true}) ActivityPub.fetch_activities([], %{muting_user: user, with_muted: true})
@ -1358,7 +1358,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, _reblog_mute} = CommonAPI.hide_reblogs(user, booster) {:ok, _reblog_mute} = CommonAPI.hide_reblogs(booster, user)
{:ok, activity} = CommonAPI.repeat(activity.id, booster) {:ok, activity} = CommonAPI.repeat(activity.id, booster)
@ -1371,8 +1371,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, _reblog_mute} = CommonAPI.hide_reblogs(user, booster) {:ok, _reblog_mute} = CommonAPI.hide_reblogs(booster, user)
{:ok, _reblog_mute} = CommonAPI.show_reblogs(user, booster) {:ok, _reblog_mute} = CommonAPI.show_reblogs(booster, user)
{:ok, activity} = CommonAPI.repeat(activity.id, booster) {:ok, activity} = CommonAPI.repeat(activity.id, booster)
@ -1452,7 +1452,7 @@ test "it reverts unfollow activity" do
follower = insert(:user) follower = insert(:user)
followed = insert(:user) followed = insert(:user)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed) {:ok, _, _, follow_activity} = CommonAPI.follow(followed, follower)
with_mock(Utils, [:passthrough], maybe_federate: fn _ -> {:error, :reverted} end) do with_mock(Utils, [:passthrough], maybe_federate: fn _ -> {:error, :reverted} end) do
assert {:error, :reverted} = ActivityPub.unfollow(follower, followed) assert {:error, :reverted} = ActivityPub.unfollow(follower, followed)
@ -1469,7 +1469,7 @@ test "creates an undo activity for the last follow" do
follower = insert(:user) follower = insert(:user)
followed = insert(:user) followed = insert(:user)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed) {:ok, _, _, follow_activity} = CommonAPI.follow(followed, follower)
{:ok, activity} = ActivityPub.unfollow(follower, followed) {:ok, activity} = ActivityPub.unfollow(follower, followed)
assert activity.data["type"] == "Undo" assert activity.data["type"] == "Undo"
@ -1486,7 +1486,7 @@ test "creates an undo activity for a pending follow request" do
follower = insert(:user) follower = insert(:user)
followed = insert(:user, %{is_locked: true}) followed = insert(:user, %{is_locked: true})
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed) {:ok, _, _, follow_activity} = CommonAPI.follow(followed, follower)
{:ok, activity} = ActivityPub.unfollow(follower, followed) {:ok, activity} = ActivityPub.unfollow(follower, followed)
assert activity.data["type"] == "Undo" assert activity.data["type"] == "Undo"
@ -1854,14 +1854,14 @@ test "returns a favourite activities sorted by adds to favorite" do
{:ok, a4} = CommonAPI.post(user2, %{status: "Agent Smith "}) {:ok, a4} = CommonAPI.post(user2, %{status: "Agent Smith "})
{:ok, a5} = CommonAPI.post(user1, %{status: "Red or Blue "}) {:ok, a5} = CommonAPI.post(user1, %{status: "Red or Blue "})
{:ok, _} = CommonAPI.favorite(user, a4.id) {:ok, _} = CommonAPI.favorite(a4.id, user)
{:ok, _} = CommonAPI.favorite(other_user, a3.id) {:ok, _} = CommonAPI.favorite(a3.id, other_user)
{:ok, _} = CommonAPI.favorite(user, a3.id) {:ok, _} = CommonAPI.favorite(a3.id, user)
{:ok, _} = CommonAPI.favorite(other_user, a5.id) {:ok, _} = CommonAPI.favorite(a5.id, other_user)
{:ok, _} = CommonAPI.favorite(user, a5.id) {:ok, _} = CommonAPI.favorite(a5.id, user)
{:ok, _} = CommonAPI.favorite(other_user, a4.id) {:ok, _} = CommonAPI.favorite(a4.id, other_user)
{:ok, _} = CommonAPI.favorite(user, a1.id) {:ok, _} = CommonAPI.favorite(a1.id, user)
{:ok, _} = CommonAPI.favorite(other_user, a1.id) {:ok, _} = CommonAPI.favorite(a1.id, other_user)
result = ActivityPub.fetch_favourites(user) result = ActivityPub.fetch_favourites(user)
assert Enum.map(result, & &1.id) == [a1.id, a5.id, a3.id, a4.id] assert Enum.map(result, & &1.id) == [a1.id, a5.id, a3.id, a4.id]

View file

@ -318,7 +318,7 @@ test "has a matching host" do
following_user = insert(:user) following_user = insert(:user)
non_following_user = insert(:user) non_following_user = insert(:user)
{:ok, _, _, _} = CommonAPI.follow(following_user, actor) {:ok, _, _, _} = CommonAPI.follow(actor, following_user)
activity = %{ activity = %{
"actor" => actor.ap_id, "actor" => actor.ap_id,

View file

@ -43,7 +43,7 @@ test "a note from factory validates" do
setup do setup do
user = insert(:user) user = insert(:user)
{:ok, activity} = Pleroma.Web.CommonAPI.post(user, %{status: "mew mew :dinosaur:"}) {:ok, activity} = Pleroma.Web.CommonAPI.post(user, %{status: "mew mew :dinosaur:"})
{:ok, edit} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "edited :blank:"}) {:ok, edit} = Pleroma.Web.CommonAPI.update(activity, user, %{status: "edited :blank:"})
{:ok, %{"object" => external_rep}} = {:ok, %{"object" => external_rep}} =
Pleroma.Web.ActivityPub.Transmogrifier.prepare_outgoing(edit.data) Pleroma.Web.ActivityPub.Transmogrifier.prepare_outgoing(edit.data)

View file

@ -94,7 +94,7 @@ test "it errors when the actor has already like the object", %{
user: user, user: user,
post_activity: post_activity post_activity: post_activity
} do } do
_like = CommonAPI.favorite(user, post_activity.id) _like = CommonAPI.favorite(post_activity.id, user)
refute LikeValidator.cast_and_validate(valid_like).valid? refute LikeValidator.cast_and_validate(valid_like).valid?
end end

View file

@ -15,7 +15,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.UndoHandlingTest do
setup do setup do
user = insert(:user) user = insert(:user)
{:ok, post_activity} = CommonAPI.post(user, %{status: "uguu"}) {:ok, post_activity} = CommonAPI.post(user, %{status: "uguu"})
{:ok, like} = CommonAPI.favorite(user, post_activity.id) {:ok, like} = CommonAPI.favorite(post_activity.id, user)
{:ok, valid_like_undo, []} = Builder.undo(user, like) {:ok, valid_like_undo, []} = Builder.undo(user, like)
%{user: user, like: like, valid_like_undo: valid_like_undo} %{user: user, like: like, valid_like_undo: valid_like_undo}

View file

@ -132,7 +132,7 @@ test "returns object_data in meta for a remote Update" do
setup do setup do
user = insert(:user) user = insert(:user)
{:ok, activity} = Pleroma.Web.CommonAPI.post(user, %{status: "mew mew :dinosaur:"}) {:ok, activity} = Pleroma.Web.CommonAPI.post(user, %{status: "mew mew :dinosaur:"})
{:ok, edit} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "edited :blank:"}) {:ok, edit} = Pleroma.Web.CommonAPI.update(activity, user, %{status: "edited :blank:"})
{:ok, external_rep} = Pleroma.Web.ActivityPub.Transmogrifier.prepare_outgoing(edit.data) {:ok, external_rep} = Pleroma.Web.ActivityPub.Transmogrifier.prepare_outgoing(edit.data)
%{external_rep: external_rep} %{external_rep: external_rep}
end end

View file

@ -53,7 +53,7 @@ test "returns errors when user not found" do
test "returns activity" do test "returns activity" do
user = insert(:user) user = insert(:user)
service_actor = Relay.get_actor() service_actor = Relay.get_actor()
CommonAPI.follow(service_actor, user) CommonAPI.follow(user, service_actor)
assert "#{user.ap_id}/followers" in User.following(service_actor) assert "#{user.ap_id}/followers" in User.following(service_actor)
assert {:ok, %Activity{} = activity} = Relay.unfollow(user.ap_id) assert {:ok, %Activity{} = activity} = Relay.unfollow(user.ap_id)
assert activity.actor == "#{Pleroma.Web.Endpoint.url()}/relay" assert activity.actor == "#{Pleroma.Web.Endpoint.url()}/relay"
@ -74,7 +74,7 @@ test "force unfollow when target service is dead" do
end) end)
service_actor = Relay.get_actor() service_actor = Relay.get_actor()
CommonAPI.follow(service_actor, user) CommonAPI.follow(user, service_actor)
assert "#{user.ap_id}/followers" in User.following(service_actor) assert "#{user.ap_id}/followers" in User.following(service_actor)
assert Pleroma.Repo.get_by( assert Pleroma.Repo.get_by(

View file

@ -50,7 +50,7 @@ test "it handles user deletions", %{delete_user: delete, user: user} do
{:ok, op} = CommonAPI.post(other_user, %{status: "big oof"}) {:ok, op} = CommonAPI.post(other_user, %{status: "big oof"})
{:ok, post} = CommonAPI.post(user, %{status: "hey", in_reply_to_id: op}) {:ok, post} = CommonAPI.post(user, %{status: "hey", in_reply_to_id: op})
{:ok, favorite} = CommonAPI.favorite(user, post.id) {:ok, favorite} = CommonAPI.favorite(post.id, user)
object = Object.normalize(post, fetch: false) object = Object.normalize(post, fetch: false)
{:ok, delete_data, _meta} = Builder.delete(user, object.data["id"]) {:ok, delete_data, _meta} = Builder.delete(user, object.data["id"])
{:ok, delete, _meta} = ActivityPub.persist(delete_data, local: true) {:ok, delete, _meta} = ActivityPub.persist(delete_data, local: true)

View file

@ -516,10 +516,10 @@ test "when activation is required", %{delete: delete, user: user} do
poster = insert(:user) poster = insert(:user)
user = insert(:user) user = insert(:user)
{:ok, post} = CommonAPI.post(poster, %{status: "hey"}) {:ok, post} = CommonAPI.post(poster, %{status: "hey"})
{:ok, like} = CommonAPI.favorite(user, post.id) {:ok, like} = CommonAPI.favorite(post.id, user)
{:ok, reaction} = CommonAPI.react_with_emoji(post.id, user, "👍") {:ok, reaction} = CommonAPI.react_with_emoji(post.id, user, "👍")
{:ok, announce} = CommonAPI.repeat(post.id, user) {:ok, announce} = CommonAPI.repeat(post.id, user)
{:ok, block} = CommonAPI.block(user, poster) {:ok, block} = CommonAPI.block(poster, user)
{:ok, undo_data, _meta} = Builder.undo(user, like) {:ok, undo_data, _meta} = Builder.undo(user, like)
{:ok, like_undo, _meta} = ActivityPub.persist(undo_data, local: true) {:ok, like_undo, _meta} = ActivityPub.persist(undo_data, local: true)
@ -834,7 +834,7 @@ test "creates a notification", %{announce: announce, poster: poster} do
user = insert(:user) user = insert(:user)
followed = insert(:user) followed = insert(:user)
{:ok, _, _, follow_activity} = CommonAPI.follow(user, followed) {:ok, _, _, follow_activity} = CommonAPI.follow(followed, user)
{:ok, reject_data, []} = Builder.reject(followed, follow_activity) {:ok, reject_data, []} = Builder.reject(followed, follow_activity)
{:ok, reject, _meta} = ActivityPub.persist(reject_data, local: true) {:ok, reject, _meta} = ActivityPub.persist(reject_data, local: true)
@ -965,7 +965,7 @@ test "group should not boost it if group is blocking poster", %{
group: group, group: group,
poster: poster poster: poster
} do } do
{:ok, _} = CommonAPI.block(group, poster) {:ok, _} = CommonAPI.block(poster, group)
create_activity_data = make_create.([group]) create_activity_data = make_create.([group])
{:ok, create_activity, _meta} = ActivityPub.persist(create_activity_data, local: false) {:ok, create_activity, _meta} = ActivityPub.persist(create_activity_data, local: false)

View file

@ -18,7 +18,7 @@ test "it works for incoming accepts which were pre-accepted" do
{:ok, follower, followed} = User.follow(follower, followed) {:ok, follower, followed} = User.follow(follower, followed)
assert User.following?(follower, followed) == true assert User.following?(follower, followed) == true
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed) {:ok, _, _, follow_activity} = CommonAPI.follow(followed, follower)
accept_data = accept_data =
File.read!("test/fixtures/mastodon-accept-activity.json") File.read!("test/fixtures/mastodon-accept-activity.json")
@ -48,7 +48,7 @@ test "it works for incoming accepts which are referenced by IRI only" do
follower = insert(:user) follower = insert(:user)
followed = insert(:user, is_locked: true) followed = insert(:user, is_locked: true)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed) {:ok, _, _, follow_activity} = CommonAPI.follow(followed, follower)
accept_data = accept_data =
File.read!("test/fixtures/mastodon-accept-activity.json") File.read!("test/fixtures/mastodon-accept-activity.json")

View file

@ -36,7 +36,7 @@ test "it works for incoming rejects which are referenced by IRI only" do
followed = insert(:user, is_locked: true) followed = insert(:user, is_locked: true)
{:ok, follower, followed} = User.follow(follower, followed) {:ok, follower, followed} = User.follow(follower, followed)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed) {:ok, _, _, follow_activity} = CommonAPI.follow(followed, follower)
assert User.following?(follower, followed) == true assert User.following?(follower, followed) == true

View file

@ -353,7 +353,7 @@ test "Updates of Notes are handled" do
user = insert(:user) user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: "everybody do the dinosaur :dinosaur:"}) {:ok, activity} = CommonAPI.post(user, %{status: "everybody do the dinosaur :dinosaur:"})
{:ok, update} = CommonAPI.update(user, activity, %{status: "mew mew :blank:"}) {:ok, update} = CommonAPI.update(activity, user, %{status: "mew mew :blank:"})
{:ok, prepared} = Transmogrifier.prepare_outgoing(update.data) {:ok, prepared} = Transmogrifier.prepare_outgoing(update.data)

View file

@ -201,7 +201,7 @@ test "fetches existing votes" do
}) })
object = Object.normalize(activity, fetch: false) object = Object.normalize(activity, fetch: false)
{:ok, votes, object} = CommonAPI.vote(other_user, object, [0, 1]) {:ok, votes, object} = CommonAPI.vote(object, other_user, [0, 1])
assert Enum.sort(Utils.get_existing_votes(other_user.ap_id, object)) == Enum.sort(votes) assert Enum.sort(Utils.get_existing_votes(other_user.ap_id, object)) == Enum.sort(votes)
end end
@ -219,8 +219,8 @@ test "fetches only Create activities" do
}) })
object = Object.normalize(activity, fetch: false) object = Object.normalize(activity, fetch: false)
{:ok, [vote], object} = CommonAPI.vote(other_user, object, [0]) {:ok, [vote], object} = CommonAPI.vote(object, other_user, [0])
{:ok, _activity} = CommonAPI.favorite(user, activity.id) {:ok, _activity} = CommonAPI.favorite(activity.id, user)
[fetched_vote] = Utils.get_existing_votes(other_user.ap_id, object) [fetched_vote] = Utils.get_existing_votes(other_user.ap_id, object)
assert fetched_vote.id == vote.id assert fetched_vote.id == vote.id
end end
@ -231,8 +231,8 @@ test "updates the state of all Follow activities with the same actor and object"
user = insert(:user, is_locked: true) user = insert(:user, is_locked: true)
follower = insert(:user) follower = insert(:user)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, user) {:ok, _, _, follow_activity} = CommonAPI.follow(user, follower)
{:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user) {:ok, _, _, follow_activity_two} = CommonAPI.follow(user, follower)
data = data =
follow_activity_two.data follow_activity_two.data
@ -253,8 +253,8 @@ test "also updates the state of accepted follows" do
user = insert(:user) user = insert(:user)
follower = insert(:user) follower = insert(:user)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, user) {:ok, _, _, follow_activity} = CommonAPI.follow(user, follower)
{:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user) {:ok, _, _, follow_activity_two} = CommonAPI.follow(user, follower)
{:ok, follow_activity_two} = {:ok, follow_activity_two} =
Utils.update_follow_state_for_all(follow_activity_two, "reject") Utils.update_follow_state_for_all(follow_activity_two, "reject")
@ -269,8 +269,8 @@ test "updates the state of the given follow activity" do
user = insert(:user, is_locked: true) user = insert(:user, is_locked: true)
follower = insert(:user) follower = insert(:user)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, user) {:ok, _, _, follow_activity} = CommonAPI.follow(user, follower)
{:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user) {:ok, _, _, follow_activity_two} = CommonAPI.follow(user, follower)
data = data =
follow_activity_two.data follow_activity_two.data
@ -355,7 +355,7 @@ test "fetches existing like" do
user = insert(:user) user = insert(:user)
refute Utils.get_existing_like(user.ap_id, object) refute Utils.get_existing_like(user.ap_id, object)
{:ok, like_activity} = CommonAPI.favorite(user, note_activity.id) {:ok, like_activity} = CommonAPI.favorite(note_activity.id, user)
assert ^like_activity = Utils.get_existing_like(user.ap_id, object) assert ^like_activity = Utils.get_existing_like(user.ap_id, object)
end end
@ -382,9 +382,9 @@ test "fetches last block activities" do
user1 = insert(:user) user1 = insert(:user)
user2 = insert(:user) user2 = insert(:user)
assert {:ok, %Activity{} = _} = CommonAPI.block(user1, user2) assert {:ok, %Activity{} = _} = CommonAPI.block(user2, user1)
assert {:ok, %Activity{} = _} = CommonAPI.block(user1, user2) assert {:ok, %Activity{} = _} = CommonAPI.block(user2, user1)
assert {:ok, %Activity{} = activity} = CommonAPI.block(user1, user2) assert {:ok, %Activity{} = activity} = CommonAPI.block(user2, user1)
assert Utils.fetch_latest_block(user1, user2) == activity assert Utils.fetch_latest_block(user1, user2) == activity
end end
@ -546,7 +546,7 @@ test "returns map with Flag object with a non-Create Activity" do
target_account = insert(:user) target_account = insert(:user)
{:ok, activity} = CommonAPI.post(posting_account, %{status: "foobar"}) {:ok, activity} = CommonAPI.post(posting_account, %{status: "foobar"})
{:ok, like} = CommonAPI.favorite(target_account, activity.id) {:ok, like} = CommonAPI.favorite(activity.id, target_account)
context = Utils.generate_context_id() context = Utils.generate_context_id()
content = "foobar" content = "foobar"

View file

@ -59,7 +59,7 @@ test "renders a like activity" do
object = Object.normalize(note, fetch: false) object = Object.normalize(note, fetch: false)
user = insert(:user) user = insert(:user)
{:ok, like_activity} = CommonAPI.favorite(user, note.id) {:ok, like_activity} = CommonAPI.favorite(note.id, user)
result = ObjectView.render("object.json", %{object: like_activity}) result = ObjectView.render("object.json", %{object: like_activity})

View file

@ -138,7 +138,7 @@ test "instance users do not expose oAuth endpoints" do
test "sets totalItems to zero when followers are hidden" do test "sets totalItems to zero when followers are hidden" do
user = insert(:user) user = insert(:user)
other_user = insert(:user) other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user)
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user}) assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
user = Map.merge(user, %{hide_followers_count: true, hide_followers: true}) user = Map.merge(user, %{hide_followers_count: true, hide_followers: true})
refute UserView.render("followers.json", %{user: user}) |> Map.has_key?("totalItems") refute UserView.render("followers.json", %{user: user}) |> Map.has_key?("totalItems")
@ -147,7 +147,7 @@ test "sets totalItems to zero when followers are hidden" do
test "sets correct totalItems when followers are hidden but the follower counter is not" do test "sets correct totalItems when followers are hidden but the follower counter is not" do
user = insert(:user) user = insert(:user)
other_user = insert(:user) other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user)
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user}) assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
user = Map.merge(user, %{hide_followers_count: false, hide_followers: true}) user = Map.merge(user, %{hide_followers_count: false, hide_followers: true})
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user}) assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
@ -158,7 +158,7 @@ test "sets correct totalItems when followers are hidden but the follower counter
test "sets totalItems to zero when follows are hidden" do test "sets totalItems to zero when follows are hidden" do
user = insert(:user) user = insert(:user)
other_user = insert(:user) other_user = insert(:user)
{:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, _other_user, _activity} = CommonAPI.follow(other_user, user)
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user}) assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
user = Map.merge(user, %{hide_follows_count: true, hide_follows: true}) user = Map.merge(user, %{hide_follows_count: true, hide_follows: true})
assert %{"totalItems" => 0} = UserView.render("following.json", %{user: user}) assert %{"totalItems" => 0} = UserView.render("following.json", %{user: user})
@ -167,7 +167,7 @@ test "sets totalItems to zero when follows are hidden" do
test "sets correct totalItems when follows are hidden but the follow counter is not" do test "sets correct totalItems when follows are hidden but the follow counter is not" do
user = insert(:user) user = insert(:user)
other_user = insert(:user) other_user = insert(:user)
{:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, _other_user, _activity} = CommonAPI.follow(other_user, user)
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user}) assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
user = Map.merge(user, %{hide_follows_count: false, hide_follows: true}) user = Map.merge(user, %{hide_follows_count: false, hide_follows: true})
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user}) assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})

View file

@ -69,8 +69,8 @@ test "single user", %{admin: admin, conn: conn} do
# Create some activities to check they got deleted later # Create some activities to check they got deleted later
follower = insert(:user) follower = insert(:user)
{:ok, _} = CommonAPI.post(user, %{status: "test"}) {:ok, _} = CommonAPI.post(user, %{status: "test"})
{:ok, _, _, _} = CommonAPI.follow(user, follower)
{:ok, _, _, _} = CommonAPI.follow(follower, user) {:ok, _, _, _} = CommonAPI.follow(follower, user)
{:ok, _, _, _} = CommonAPI.follow(user, follower)
user = Repo.get(User, user.id) user = Repo.get(User, user.id)
assert user.note_count == 1 assert user.note_count == 1
assert user.follower_count == 1 assert user.follower_count == 1

View file

@ -80,8 +80,8 @@ test "it posts a poll" do
setup do setup do
blocker = insert(:user) blocker = insert(:user)
blocked = insert(:user, local: false) blocked = insert(:user, local: false)
CommonAPI.follow(blocker, blocked)
CommonAPI.follow(blocked, blocker) CommonAPI.follow(blocked, blocker)
CommonAPI.follow(blocker, blocked)
CommonAPI.accept_follow_request(blocker, blocked) CommonAPI.accept_follow_request(blocker, blocked)
CommonAPI.accept_follow_request(blocked, blocked) CommonAPI.accept_follow_request(blocked, blocked)
%{blocker: blocker, blocked: blocked} %{blocker: blocker, blocked: blocked}
@ -95,7 +95,7 @@ test "it blocks and federates", %{blocker: blocker, blocked: blocked} do
assert User.get_follow_state(blocker, blocked) == :follow_accept assert User.get_follow_state(blocker, blocked) == :follow_accept
refute is_nil(Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(blocker, blocked)) refute is_nil(Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(blocker, blocked))
assert {:ok, block} = CommonAPI.block(blocker, blocked) assert {:ok, block} = CommonAPI.block(blocked, blocker)
assert block.local assert block.local
assert User.blocks?(blocker, blocked) assert User.blocks?(blocker, blocked)
@ -120,7 +120,7 @@ test "it blocks and does not federate if outgoing blocks are disabled", %{
with_mock Pleroma.Web.Federator, with_mock Pleroma.Web.Federator,
publish: fn _ -> nil end do publish: fn _ -> nil end do
assert {:ok, block} = CommonAPI.block(blocker, blocked) assert {:ok, block} = CommonAPI.block(blocked, blocker)
assert block.local assert block.local
assert User.blocks?(blocker, blocked) assert User.blocks?(blocker, blocked)
@ -324,7 +324,7 @@ test "it works even without an existing block activity" do
User.block(blocker, blocked) User.block(blocker, blocked)
assert User.blocks?(blocker, blocked) assert User.blocks?(blocker, blocked)
assert {:ok, :no_activity} == CommonAPI.unblock(blocker, blocked) assert {:ok, :no_activity} == CommonAPI.unblock(blocked, blocker)
refute User.blocks?(blocker, blocked) refute User.blocks?(blocker, blocked)
end end
end end
@ -454,7 +454,7 @@ test "favoriting race condition" do
users_serial users_serial
|> Enum.map(fn user -> |> Enum.map(fn user ->
CommonAPI.favorite(user, activity.id) CommonAPI.favorite(activity.id, user)
end) end)
object = Object.get_by_ap_id(activity.data["object"]) object = Object.get_by_ap_id(activity.data["object"])
@ -463,7 +463,7 @@ test "favoriting race condition" do
users users
|> Enum.map(fn user -> |> Enum.map(fn user ->
Task.async(fn -> Task.async(fn ->
CommonAPI.favorite(user, activity.id) CommonAPI.favorite(activity.id, user)
end) end)
end) end)
|> Enum.map(&Task.await/1) |> Enum.map(&Task.await/1)
@ -955,7 +955,7 @@ test "repeating a status privately" do
test "author can repeat own private statuses" do test "author can repeat own private statuses" do
author = insert(:user) author = insert(:user)
follower = insert(:user) follower = insert(:user)
CommonAPI.follow(follower, author) CommonAPI.follow(author, follower)
{:ok, activity} = CommonAPI.post(author, %{status: "cofe", visibility: "private"}) {:ok, activity} = CommonAPI.post(author, %{status: "cofe", visibility: "private"})
@ -974,7 +974,7 @@ test "favoriting a status" do
{:ok, post_activity} = CommonAPI.post(other_user, %{status: "cofe"}) {:ok, post_activity} = CommonAPI.post(other_user, %{status: "cofe"})
{:ok, %Activity{data: data}} = CommonAPI.favorite(user, post_activity.id) {:ok, %Activity{data: data}} = CommonAPI.favorite(post_activity.id, user)
assert data["type"] == "Like" assert data["type"] == "Like"
assert data["actor"] == user.ap_id assert data["actor"] == user.ap_id
assert data["object"] == post_activity.data["object"] assert data["object"] == post_activity.data["object"]
@ -994,8 +994,8 @@ test "favoriting a status twice returns ok, but without the like activity" do
other_user = insert(:user) other_user = insert(:user)
{:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"}) {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
{:ok, %Activity{}} = CommonAPI.favorite(user, activity.id) {:ok, %Activity{}} = CommonAPI.favorite(activity.id, user)
assert {:ok, :already_liked} = CommonAPI.favorite(user, activity.id) assert {:ok, :already_liked} = CommonAPI.favorite(activity.id, user)
end end
end end
@ -1149,7 +1149,7 @@ test "marks notifications as read after mute" do
} }
) )
{:ok, favorite_activity} = CommonAPI.favorite(friend2, activity.id) {:ok, favorite_activity} = CommonAPI.favorite(activity.id, friend2)
{:ok, repeat_activity} = CommonAPI.repeat(activity.id, friend1) {:ok, repeat_activity} = CommonAPI.repeat(activity.id, friend1)
assert Repo.aggregate( assert Repo.aggregate(
@ -1172,8 +1172,8 @@ test "marks notifications as read after mute" do
n.type == "mention" && n.activity_id == reply_activity.id n.type == "mention" && n.activity_id == reply_activity.id
end) end)
{:ok, _} = CommonAPI.add_mute(author, activity) {:ok, _} = CommonAPI.add_mute(activity, author)
assert CommonAPI.thread_muted?(author, activity) assert CommonAPI.thread_muted?(activity, author)
assert Repo.aggregate( assert Repo.aggregate(
from(n in Notification, where: n.seen == false and n.user_id == ^friend1.id), from(n in Notification, where: n.seen == false and n.user_id == ^friend1.id),
@ -1197,13 +1197,13 @@ test "marks notifications as read after mute" do
end end
test "add mute", %{user: user, activity: activity} do test "add mute", %{user: user, activity: activity} do
{:ok, _} = CommonAPI.add_mute(user, activity) {:ok, _} = CommonAPI.add_mute(activity, user)
assert CommonAPI.thread_muted?(user, activity) assert CommonAPI.thread_muted?(activity, user)
end end
test "add expiring mute", %{user: user, activity: activity} do test "add expiring mute", %{user: user, activity: activity} do
{:ok, _} = CommonAPI.add_mute(user, activity, %{expires_in: 60}) {:ok, _} = CommonAPI.add_mute(activity, user, %{expires_in: 60})
assert CommonAPI.thread_muted?(user, activity) assert CommonAPI.thread_muted?(activity, user)
worker = Pleroma.Workers.MuteExpireWorker worker = Pleroma.Workers.MuteExpireWorker
args = %{"op" => "unmute_conversation", "user_id" => user.id, "activity_id" => activity.id} args = %{"op" => "unmute_conversation", "user_id" => user.id, "activity_id" => activity.id}
@ -1214,24 +1214,24 @@ test "add expiring mute", %{user: user, activity: activity} do
) )
assert :ok = perform_job(worker, args) assert :ok = perform_job(worker, args)
refute CommonAPI.thread_muted?(user, activity) refute CommonAPI.thread_muted?(activity, user)
end end
test "remove mute", %{user: user, activity: activity} do test "remove mute", %{user: user, activity: activity} do
CommonAPI.add_mute(user, activity) CommonAPI.add_mute(activity, user)
{:ok, _} = CommonAPI.remove_mute(user, activity) {:ok, _} = CommonAPI.remove_mute(activity, user)
refute CommonAPI.thread_muted?(user, activity) refute CommonAPI.thread_muted?(activity, user)
end end
test "remove mute by ids", %{user: user, activity: activity} do test "remove mute by ids", %{user: user, activity: activity} do
CommonAPI.add_mute(user, activity) CommonAPI.add_mute(activity, user)
{:ok, _} = CommonAPI.remove_mute(user.id, activity.id) {:ok, _} = CommonAPI.remove_mute(activity.id, user.id)
refute CommonAPI.thread_muted?(user, activity) refute CommonAPI.thread_muted?(activity, user)
end end
test "check that mutes can't be duplicate", %{user: user, activity: activity} do test "check that mutes can't be duplicate", %{user: user, activity: activity} do
CommonAPI.add_mute(user, activity) CommonAPI.add_mute(activity, user)
{:error, _} = CommonAPI.add_mute(user, activity) {:error, _} = CommonAPI.add_mute(activity, user)
end end
end end
@ -1404,14 +1404,14 @@ test "creates a report with provided rules" do
end end
test "add a reblog mute", %{muter: muter, muted: muted} do test "add a reblog mute", %{muter: muter, muted: muted} do
{:ok, _reblog_mute} = CommonAPI.hide_reblogs(muter, muted) {:ok, _reblog_mute} = CommonAPI.hide_reblogs(muted, muter)
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, _reblog_mute} = CommonAPI.hide_reblogs(muter, muted) {:ok, _reblog_mute} = CommonAPI.hide_reblogs(muted, muter)
{:ok, _reblog_mute} = CommonAPI.show_reblogs(muter, muted) {:ok, _reblog_mute} = CommonAPI.show_reblogs(muted, muter)
assert User.showing_reblogs?(muter, muted) == true assert User.showing_reblogs?(muter, muted) == true
end end
@ -1420,7 +1420,7 @@ test "remove a reblog mute", %{muter: muter, muted: muted} do
describe "follow/2" do describe "follow/2" do
test "directly follows a non-locked local user" do test "directly follows a non-locked local user" do
[follower, followed] = insert_pair(:user) [follower, followed] = insert_pair(:user)
{:ok, follower, followed, _} = CommonAPI.follow(follower, followed) {:ok, follower, followed, _} = CommonAPI.follow(followed, follower)
assert User.following?(follower, followed) assert User.following?(follower, followed)
end end
@ -1429,24 +1429,24 @@ test "directly follows a non-locked local user" do
describe "unfollow/2" do describe "unfollow/2" do
test "also unsubscribes a user" do test "also unsubscribes a user" do
[follower, followed] = insert_pair(:user) [follower, followed] = insert_pair(:user)
{:ok, follower, followed, _} = CommonAPI.follow(follower, followed) {:ok, follower, followed, _} = CommonAPI.follow(followed, follower)
{:ok, _subscription} = User.subscribe(follower, followed) {:ok, _subscription} = User.subscribe(follower, followed)
assert User.subscribed_to?(follower, followed) assert User.subscribed_to?(follower, followed)
{:ok, follower} = CommonAPI.unfollow(follower, followed) {:ok, follower} = CommonAPI.unfollow(followed, follower)
refute User.subscribed_to?(follower, followed) refute User.subscribed_to?(follower, followed)
end end
test "also unpins a user" do test "also unpins a user" do
[follower, followed] = insert_pair(:user) [follower, followed] = insert_pair(:user)
{:ok, follower, followed, _} = CommonAPI.follow(follower, followed) {:ok, follower, followed, _} = CommonAPI.follow(followed, follower)
{:ok, _endorsement} = User.endorse(follower, followed) {:ok, _endorsement} = User.endorse(follower, followed)
assert User.endorses?(follower, followed) assert User.endorses?(follower, followed)
{:ok, follower} = CommonAPI.unfollow(follower, followed) {:ok, follower} = CommonAPI.unfollow(followed, follower)
refute User.endorses?(follower, followed) refute User.endorses?(follower, followed)
end end
@ -1456,10 +1456,10 @@ test "cancels a pending follow for a local user" do
followed = insert(:user, is_locked: true) followed = insert(:user, is_locked: true)
assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} = assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
CommonAPI.follow(follower, followed) CommonAPI.follow(followed, follower)
assert User.get_follow_state(follower, followed) == :follow_pending assert User.get_follow_state(follower, followed) == :follow_pending
assert {:ok, follower} = CommonAPI.unfollow(follower, followed) assert {:ok, follower} = CommonAPI.unfollow(followed, follower)
assert User.get_follow_state(follower, followed) == nil assert User.get_follow_state(follower, followed) == nil
assert %{id: ^activity_id, data: %{"state" => "cancelled"}} = assert %{id: ^activity_id, data: %{"state" => "cancelled"}} =
@ -1478,10 +1478,10 @@ test "cancels a pending follow for a remote user" do
followed = insert(:user, is_locked: true, local: false) followed = insert(:user, is_locked: true, local: false)
assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} = assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
CommonAPI.follow(follower, followed) CommonAPI.follow(followed, follower)
assert User.get_follow_state(follower, followed) == :follow_pending assert User.get_follow_state(follower, followed) == :follow_pending
assert {:ok, follower} = CommonAPI.unfollow(follower, followed) assert {:ok, follower} = CommonAPI.unfollow(followed, follower)
assert User.get_follow_state(follower, followed) == nil assert User.get_follow_state(follower, followed) == nil
assert %{id: ^activity_id, data: %{"state" => "cancelled"}} = assert %{id: ^activity_id, data: %{"state" => "cancelled"}} =
@ -1502,9 +1502,9 @@ test "after acceptance, it sets all existing pending follow request states to 'a
follower = insert(:user) follower = insert(:user)
follower_two = insert(:user) follower_two = insert(:user)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, user) {:ok, _, _, follow_activity} = CommonAPI.follow(user, follower)
{:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user) {:ok, _, _, follow_activity_two} = CommonAPI.follow(user, follower)
{:ok, _, _, follow_activity_three} = CommonAPI.follow(follower_two, user) {:ok, _, _, follow_activity_three} = CommonAPI.follow(user, follower_two)
assert follow_activity.data["state"] == "pending" assert follow_activity.data["state"] == "pending"
assert follow_activity_two.data["state"] == "pending" assert follow_activity_two.data["state"] == "pending"
@ -1522,9 +1522,9 @@ test "after rejection, it sets all existing pending follow request states to 're
follower = insert(:user) follower = insert(:user)
follower_two = insert(:user) follower_two = insert(:user)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, user) {:ok, _, _, follow_activity} = CommonAPI.follow(user, follower)
{:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user) {:ok, _, _, follow_activity_two} = CommonAPI.follow(user, follower)
{:ok, _, _, follow_activity_three} = CommonAPI.follow(follower_two, user) {:ok, _, _, follow_activity_three} = CommonAPI.follow(user, follower_two)
assert follow_activity.data["state"] == "pending" assert follow_activity.data["state"] == "pending"
assert follow_activity_two.data["state"] == "pending" assert follow_activity_two.data["state"] == "pending"
@ -1559,9 +1559,9 @@ test "does not allow to vote twice" do
object = Object.normalize(activity, fetch: false) object = Object.normalize(activity, fetch: false)
{:ok, _, object} = CommonAPI.vote(other_user, object, [0]) {:ok, _, object} = CommonAPI.vote(object, other_user, [0])
assert {:error, "Already voted"} == CommonAPI.vote(other_user, object, [1]) assert {:error, "Already voted"} == CommonAPI.vote(object, other_user, [1])
end end
end end
@ -1695,7 +1695,7 @@ test "favorite" do
with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
assert {:ok, %Activity{data: %{"type" => "Like"}} = activity} = assert {:ok, %Activity{data: %{"type" => "Like"}} = activity} =
CommonAPI.favorite(user, activity.id) CommonAPI.favorite(activity.id, user)
assert Visibility.local_public?(activity) assert Visibility.local_public?(activity)
refute called(Pleroma.Web.Federator.publish(activity)) refute called(Pleroma.Web.Federator.publish(activity))
@ -1708,7 +1708,7 @@ test "unfavorite" do
{:ok, activity} = CommonAPI.post(other_user, %{status: "cofe", visibility: "local"}) {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe", visibility: "local"})
{:ok, %Activity{}} = CommonAPI.favorite(user, activity.id) {:ok, %Activity{}} = CommonAPI.favorite(activity.id, user)
with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
assert {:ok, activity} = CommonAPI.unfavorite(activity.id, user) assert {:ok, activity} = CommonAPI.unfavorite(activity.id, user)
@ -1753,7 +1753,7 @@ test "updates a post" do
user = insert(:user) user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: "foo1", spoiler_text: "title 1"}) {:ok, activity} = CommonAPI.post(user, %{status: "foo1", spoiler_text: "title 1"})
{:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2"}) {:ok, updated} = CommonAPI.update(activity, user, %{status: "updated 2"})
updated_object = Object.normalize(updated) updated_object = Object.normalize(updated)
assert updated_object.data["content"] == "updated 2" assert updated_object.data["content"] == "updated 2"
@ -1767,7 +1767,7 @@ test "does not change visibility" do
{:ok, activity} = {:ok, activity} =
CommonAPI.post(user, %{status: "foo1", spoiler_text: "title 1", visibility: "private"}) CommonAPI.post(user, %{status: "foo1", spoiler_text: "title 1", visibility: "private"})
{:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2"}) {:ok, updated} = CommonAPI.update(activity, user, %{status: "updated 2"})
updated_object = Object.normalize(updated) updated_object = Object.normalize(updated)
assert updated_object.data["content"] == "updated 2" assert updated_object.data["content"] == "updated 2"
@ -1784,7 +1784,7 @@ test "updates a post with emoji" do
{:ok, activity} = {:ok, activity} =
CommonAPI.post(user, %{status: "foo1", spoiler_text: "title 1 :#{emoji1}:"}) CommonAPI.post(user, %{status: "foo1", spoiler_text: "title 1 :#{emoji1}:"})
{:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2 :#{emoji2}:"}) {:ok, updated} = CommonAPI.update(activity, user, %{status: "updated 2 :#{emoji2}:"})
updated_object = Object.normalize(updated) updated_object = Object.normalize(updated)
assert updated_object.data["content"] == "updated 2 :#{emoji2}:" assert updated_object.data["content"] == "updated 2 :#{emoji2}:"
@ -1803,7 +1803,7 @@ test "updates a post with emoji and federate properly" do
with_mock Pleroma.Web.Federator, with_mock Pleroma.Web.Federator,
publish: fn _p -> nil end do publish: fn _p -> nil end do
{:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2 :#{emoji2}:"}) {:ok, updated} = CommonAPI.update(activity, user, %{status: "updated 2 :#{emoji2}:"})
assert updated.data["object"]["content"] == "updated 2 :#{emoji2}:" assert updated.data["object"]["content"] == "updated 2 :#{emoji2}:"
assert %{^emoji2 => _} = updated.data["object"]["emoji"] assert %{^emoji2 => _} = updated.data["object"]["emoji"]
@ -1847,7 +1847,7 @@ test "editing a post that copied a remote title with remote emoji should keep th
assert reply.object.data["emoji"]["remoteemoji"] == remote_emoji_uri assert reply.object.data["emoji"]["remoteemoji"] == remote_emoji_uri
{:ok, edit} = {:ok, edit} =
CommonAPI.update(user, reply, %{status: "reply mew mew", spoiler_text: ":remoteemoji:"}) CommonAPI.update(reply, user, %{status: "reply mew mew", spoiler_text: ":remoteemoji:"})
edited_note = Pleroma.Object.normalize(edit) edited_note = Pleroma.Object.normalize(edit)
@ -1863,7 +1863,7 @@ test "respects MRF" do
{:ok, activity} = CommonAPI.post(user, %{status: "foo1", spoiler_text: "updated 1"}) {:ok, activity} = CommonAPI.post(user, %{status: "foo1", spoiler_text: "updated 1"})
assert Object.normalize(activity).data["summary"] == "mewmew 1" assert Object.normalize(activity).data["summary"] == "mewmew 1"
{:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2"}) {:ok, updated} = CommonAPI.update(activity, user, %{status: "updated 2"})
updated_object = Object.normalize(updated) updated_object = Object.normalize(updated)
assert updated_object.data["content"] == "mewmew 2" assert updated_object.data["content"] == "mewmew 2"
@ -1914,7 +1914,7 @@ test "multiple groups mentioned", %{poster: poster, group: group, other_group: o
end end
test "it does not boost if group is blocking poster", %{poster: poster, group: group} do test "it does not boost if group is blocking poster", %{poster: poster, group: group} do
{:ok, _} = CommonAPI.block(group, poster) {:ok, _} = CommonAPI.block(poster, group)
{:ok, post} = CommonAPI.post(poster, %{status: "hey @#{group.nickname}"}) {:ok, post} = CommonAPI.post(poster, %{status: "hey @#{group.nickname}"})
announces = get_announces_of_object(post.object) announces = get_announces_of_object(post.object)
@ -2002,7 +2002,7 @@ test "when unfavoriting posts", %{
CommonAPI.post(remote_user, %{status: "I like turtles!"}) CommonAPI.post(remote_user, %{status: "I like turtles!"})
{:ok, %{data: %{"id" => ap_id}} = _favorite} = {:ok, %{data: %{"id" => ap_id}} = _favorite} =
CommonAPI.favorite(local_user, activity.id) CommonAPI.favorite(activity.id, local_user)
# Generate the publish_one jobs # Generate the publish_one jobs
ObanHelpers.perform_all() ObanHelpers.perform_all()

View file

@ -1120,7 +1120,7 @@ test "view pinned private statuses" do
|> json_response_and_validate_schema(200) |> json_response_and_validate_schema(200)
# Follow the user, then the pinned status can be seen # Follow the user, then the pinned status can be seen
CommonAPI.follow(reader, user) CommonAPI.follow(user, reader)
ObanHelpers.perform_all() ObanHelpers.perform_all()
assert [%{"id" => ^activity_id, "pinned" => true}] = assert [%{"id" => ^activity_id, "pinned" => true}] =
@ -2118,7 +2118,7 @@ test "create a note on a user" do
test "pin account", %{user: user, conn: conn} do test "pin account", %{user: user, conn: conn} do
%{id: id1} = other_user1 = insert(:user) %{id: id1} = other_user1 = insert(:user)
CommonAPI.follow(user, other_user1) CommonAPI.follow(other_user1, user)
assert %{"id" => ^id1, "endorsed" => true} = assert %{"id" => ^id1, "endorsed" => true} =
conn conn
@ -2136,7 +2136,7 @@ test "pin account", %{user: user, conn: conn} do
test "unpin account", %{user: user, conn: conn} do test "unpin account", %{user: user, conn: conn} do
%{id: id1} = other_user1 = insert(:user) %{id: id1} = other_user1 = insert(:user)
CommonAPI.follow(user, other_user1) CommonAPI.follow(other_user1, user)
User.endorse(user, other_user1) User.endorse(user, other_user1)
assert %{"id" => ^id1, "endorsed" => false} = assert %{"id" => ^id1, "endorsed" => false} =
@ -2156,8 +2156,8 @@ test "max pinned accounts", %{user: user, conn: conn} do
%{id: id1} = other_user1 = insert(:user) %{id: id1} = other_user1 = insert(:user)
%{id: id2} = other_user2 = insert(:user) %{id: id2} = other_user2 = insert(:user)
CommonAPI.follow(user, other_user1) CommonAPI.follow(other_user1, user)
CommonAPI.follow(user, other_user2) CommonAPI.follow(other_user2, user)
conn conn
|> put_req_header("content-type", "application/json") |> put_req_header("content-type", "application/json")
@ -2227,7 +2227,7 @@ test "it respects hide_followers", %{user: user, conn: conn} do
test "removing user from followers", %{conn: conn, user: user} do test "removing user from followers", %{conn: conn, user: user} do
%{id: other_user_id} = other_user = insert(:user) %{id: other_user_id} = other_user = insert(:user)
CommonAPI.follow(other_user, user) CommonAPI.follow(user, other_user)
assert %{"id" => ^other_user_id, "followed_by" => false} = assert %{"id" => ^other_user_id, "followed_by" => false} =
conn conn
@ -2240,7 +2240,7 @@ test "removing user from followers", %{conn: conn, user: user} do
test "removing remote user from followers", %{conn: conn, user: user} do test "removing remote user from followers", %{conn: conn, user: user} do
%{id: other_user_id} = other_user = insert(:user, local: false) %{id: other_user_id} = other_user = insert(:user, local: false)
CommonAPI.follow(other_user, user) CommonAPI.follow(user, other_user)
assert User.following?(other_user, user) assert User.following?(other_user, user)

View file

@ -20,7 +20,7 @@ defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
test "/api/v1/follow_requests works", %{user: user, conn: conn} do test "/api/v1/follow_requests works", %{user: user, conn: conn} do
other_user = insert(:user) other_user = insert(:user)
{:ok, _, _, _activity} = CommonAPI.follow(other_user, user) {:ok, _, _, _activity} = CommonAPI.follow(user, other_user)
{:ok, other_user, user} = User.follow(other_user, user, :follow_pending) {:ok, other_user, user} = User.follow(other_user, user, :follow_pending)
assert User.following?(other_user, user) == false assert User.following?(other_user, user) == false
@ -34,7 +34,7 @@ test "/api/v1/follow_requests works", %{user: user, conn: conn} do
test "/api/v1/follow_requests/:id/authorize works", %{user: user, conn: conn} do test "/api/v1/follow_requests/:id/authorize works", %{user: user, conn: conn} do
other_user = insert(:user) other_user = insert(:user)
{:ok, _, _, _activity} = CommonAPI.follow(other_user, user) {:ok, _, _, _activity} = CommonAPI.follow(user, other_user)
{:ok, other_user, user} = User.follow(other_user, user, :follow_pending) {:ok, other_user, user} = User.follow(other_user, user, :follow_pending)
user = User.get_cached_by_id(user.id) user = User.get_cached_by_id(user.id)
@ -56,7 +56,7 @@ test "/api/v1/follow_requests/:id/authorize works", %{user: user, conn: conn} do
test "/api/v1/follow_requests/:id/reject works", %{user: user, conn: conn} do test "/api/v1/follow_requests/:id/reject works", %{user: user, conn: conn} do
other_user = insert(:user) other_user = insert(:user)
{:ok, _, _, _activity} = CommonAPI.follow(other_user, user) {:ok, _, _, _activity} = CommonAPI.follow(user, other_user)
user = User.get_cached_by_id(user.id) user = User.get_cached_by_id(user.id)

View file

@ -148,7 +148,7 @@ test "excludes mentions from blockers when blockers_visible is false" do
%{user: user, conn: conn} = oauth_access(["read:notifications"]) %{user: user, conn: conn} = oauth_access(["read:notifications"])
blocker = insert(:user) blocker = insert(:user)
{:ok, _} = CommonAPI.block(blocker, user) {:ok, _} = CommonAPI.block(user, blocker)
{:ok, activity} = CommonAPI.post(blocker, %{status: "hi @#{user.nickname}"}) {:ok, activity} = CommonAPI.post(blocker, %{status: "hi @#{user.nickname}"})
{:ok, [_notification]} = Notification.create_notifications(activity) {:ok, [_notification]} = Notification.create_notifications(activity)
@ -326,10 +326,10 @@ test "filters notifications for Like activities" do
{:ok, private_activity} = CommonAPI.post(other_user, %{status: ".", visibility: "private"}) {:ok, private_activity} = CommonAPI.post(other_user, %{status: ".", visibility: "private"})
{:ok, _} = CommonAPI.favorite(user, public_activity.id) {:ok, _} = CommonAPI.favorite(public_activity.id, user)
{:ok, _} = CommonAPI.favorite(user, direct_activity.id) {:ok, _} = CommonAPI.favorite(direct_activity.id, user)
{:ok, _} = CommonAPI.favorite(user, unlisted_activity.id) {:ok, _} = CommonAPI.favorite(unlisted_activity.id, user)
{:ok, _} = CommonAPI.favorite(user, private_activity.id) {:ok, _} = CommonAPI.favorite(private_activity.id, user)
activity_ids = activity_ids =
conn conn
@ -414,7 +414,7 @@ test "doesn't return less than the requested amount of records when the user's r
in_reply_to_status_id: activity.id in_reply_to_status_id: activity.id
}) })
{:ok, _favorite} = CommonAPI.favorite(user, reply.id) {:ok, _favorite} = CommonAPI.favorite(reply.id, user)
activity_ids = activity_ids =
conn conn
@ -432,9 +432,9 @@ test "filters notifications using exclude_types" do
{:ok, mention_activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"}) {:ok, mention_activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"})
{:ok, create_activity} = CommonAPI.post(user, %{status: "hey"}) {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})
{:ok, favorite_activity} = CommonAPI.favorite(other_user, create_activity.id) {:ok, favorite_activity} = CommonAPI.favorite(create_activity.id, other_user)
{:ok, reblog_activity} = CommonAPI.repeat(create_activity.id, other_user) {:ok, reblog_activity} = CommonAPI.repeat(create_activity.id, other_user)
{:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user) {:ok, _, _, follow_activity} = CommonAPI.follow(user, other_user)
mention_notification_id = get_notification_id_by_activity(mention_activity) mention_notification_id = get_notification_id_by_activity(mention_activity)
favorite_notification_id = get_notification_id_by_activity(favorite_activity) favorite_notification_id = get_notification_id_by_activity(favorite_activity)
@ -470,9 +470,9 @@ test "filters notifications using types" do
{:ok, mention_activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"}) {:ok, mention_activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"})
{:ok, create_activity} = CommonAPI.post(user, %{status: "hey"}) {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})
{:ok, favorite_activity} = CommonAPI.favorite(other_user, create_activity.id) {:ok, favorite_activity} = CommonAPI.favorite(create_activity.id, other_user)
{:ok, reblog_activity} = CommonAPI.repeat(create_activity.id, other_user) {:ok, reblog_activity} = CommonAPI.repeat(create_activity.id, other_user)
{:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user) {:ok, _, _, follow_activity} = CommonAPI.follow(user, other_user)
mention_notification_id = get_notification_id_by_activity(mention_activity) mention_notification_id = get_notification_id_by_activity(mention_activity)
favorite_notification_id = get_notification_id_by_activity(favorite_activity) favorite_notification_id = get_notification_id_by_activity(favorite_activity)
@ -517,9 +517,9 @@ test "filtering falls back to include_types" do
{:ok, _activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"}) {:ok, _activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"})
{:ok, create_activity} = CommonAPI.post(user, %{status: "hey"}) {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})
{:ok, _activity} = CommonAPI.favorite(other_user, create_activity.id) {:ok, _activity} = CommonAPI.favorite(create_activity.id, other_user)
{:ok, _activity} = CommonAPI.repeat(create_activity.id, other_user) {:ok, _activity} = CommonAPI.repeat(create_activity.id, other_user)
{:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user) {:ok, _, _, follow_activity} = CommonAPI.follow(user, other_user)
follow_notification_id = get_notification_id_by_activity(follow_activity) follow_notification_id = get_notification_id_by_activity(follow_activity)
@ -578,7 +578,7 @@ test "doesn't see notifications after muting user with notifications" do
%{user: user, conn: conn} = oauth_access(["read:notifications"]) %{user: user, conn: conn} = oauth_access(["read:notifications"])
user2 = insert(:user) user2 = insert(:user)
{:ok, _, _, _} = CommonAPI.follow(user, user2) {:ok, _, _, _} = CommonAPI.follow(user2, user)
{:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"}) {:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"})
ret_conn = get(conn, "/api/v1/notifications") ret_conn = get(conn, "/api/v1/notifications")
@ -596,7 +596,7 @@ test "see notifications after muting user without notifications" do
%{user: user, conn: conn} = oauth_access(["read:notifications"]) %{user: user, conn: conn} = oauth_access(["read:notifications"])
user2 = insert(:user) user2 = insert(:user)
{:ok, _, _, _} = CommonAPI.follow(user, user2) {:ok, _, _, _} = CommonAPI.follow(user2, user)
{:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"}) {:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"})
ret_conn = get(conn, "/api/v1/notifications") ret_conn = get(conn, "/api/v1/notifications")
@ -614,7 +614,7 @@ test "see notifications after muting user with notifications and with_muted para
%{user: user, conn: conn} = oauth_access(["read:notifications"]) %{user: user, conn: conn} = oauth_access(["read:notifications"])
user2 = insert(:user) user2 = insert(:user)
{:ok, _, _, _} = CommonAPI.follow(user, user2) {:ok, _, _, _} = CommonAPI.follow(user2, user)
{:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"}) {:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"})
ret_conn = get(conn, "/api/v1/notifications") ret_conn = get(conn, "/api/v1/notifications")

View file

@ -1356,7 +1356,7 @@ test "reblogged status for another user" do
user1 = insert(:user) user1 = insert(:user)
user2 = insert(:user) user2 = insert(:user)
user3 = insert(:user) user3 = insert(:user)
{:ok, _} = CommonAPI.favorite(user2, activity.id) {:ok, _} = CommonAPI.favorite(activity.id, user2)
{:ok, _bookmark} = Pleroma.Bookmark.create(user2.id, activity.id) {:ok, _bookmark} = Pleroma.Bookmark.create(user2.id, activity.id)
{:ok, reblog_activity1} = CommonAPI.repeat(activity.id, user1) {:ok, reblog_activity1} = CommonAPI.repeat(activity.id, user1)
{:ok, _} = CommonAPI.repeat(activity.id, user2) {:ok, _} = CommonAPI.repeat(activity.id, user2)
@ -1483,7 +1483,7 @@ test "returns 404 error for a wrong id", %{conn: conn} do
test "unfavorites a status and returns it", %{user: user, conn: conn} do test "unfavorites a status and returns it", %{user: user, conn: conn} do
activity = insert(:note_activity) activity = insert(:note_activity)
{:ok, _} = CommonAPI.favorite(user, activity.id) {:ok, _} = CommonAPI.favorite(activity.id, user)
conn = conn =
conn conn
@ -1771,7 +1771,7 @@ test "mute conversation", %{conn: conn, activity: activity} do
end end
test "cannot mute already muted conversation", %{conn: conn, user: user, activity: activity} do test "cannot mute already muted conversation", %{conn: conn, user: user, activity: activity} do
{:ok, _} = CommonAPI.add_mute(user, activity) {:ok, _} = CommonAPI.add_mute(activity, user)
conn = conn =
conn conn
@ -1784,7 +1784,7 @@ test "cannot mute already muted conversation", %{conn: conn, user: user, activit
end end
test "unmute conversation", %{conn: conn, user: user, activity: activity} do test "unmute conversation", %{conn: conn, user: user, activity: activity} do
{:ok, _} = CommonAPI.add_mute(user, activity) {:ok, _} = CommonAPI.add_mute(activity, user)
id_str = to_string(activity.id) id_str = to_string(activity.id)
@ -1859,7 +1859,7 @@ test "Repeated posts that are replies incorrectly have in_reply_to_id null", %{c
test "returns users who have favorited the status", %{conn: conn, activity: activity} do test "returns users who have favorited the status", %{conn: conn, activity: activity} do
other_user = insert(:user) other_user = insert(:user)
{:ok, _} = CommonAPI.favorite(other_user, activity.id) {:ok, _} = CommonAPI.favorite(activity.id, other_user)
response = response =
conn conn
@ -1890,7 +1890,7 @@ test "does not return users who have favorited the status but are blocked", %{
other_user = insert(:user) other_user = insert(:user)
{:ok, _user_relationship} = User.block(user, other_user) {:ok, _user_relationship} = User.block(user, other_user)
{:ok, _} = CommonAPI.favorite(other_user, activity.id) {:ok, _} = CommonAPI.favorite(activity.id, other_user)
response = response =
conn conn
@ -1902,7 +1902,7 @@ test "does not return users who have favorited the status but are blocked", %{
test "does not fail on an unauthenticated request", %{activity: activity} do test "does not fail on an unauthenticated request", %{activity: activity} do
other_user = insert(:user) other_user = insert(:user)
{:ok, _} = CommonAPI.favorite(other_user, activity.id) {:ok, _} = CommonAPI.favorite(activity.id, other_user)
response = response =
build_conn() build_conn()
@ -1922,7 +1922,7 @@ test "requires authentication for private posts", %{user: user} do
visibility: "direct" visibility: "direct"
}) })
{:ok, _} = CommonAPI.favorite(other_user, activity.id) {:ok, _} = CommonAPI.favorite(activity.id, other_user)
favourited_by_url = "/api/v1/statuses/#{activity.id}/favourited_by" favourited_by_url = "/api/v1/statuses/#{activity.id}/favourited_by"
@ -1953,7 +1953,7 @@ test "returns empty array when :show_reactions is disabled", %{conn: conn, activ
clear_config([:instance, :show_reactions], false) clear_config([:instance, :show_reactions], false)
other_user = insert(:user) other_user = insert(:user)
{:ok, _} = CommonAPI.favorite(other_user, activity.id) {:ok, _} = CommonAPI.favorite(activity.id, other_user)
response = response =
conn conn
@ -2096,9 +2096,9 @@ test "favorites paginate correctly" do
{:ok, second_post} = CommonAPI.post(other_user, %{status: "bla"}) {:ok, second_post} = CommonAPI.post(other_user, %{status: "bla"})
{:ok, third_post} = CommonAPI.post(other_user, %{status: "bla"}) {:ok, third_post} = CommonAPI.post(other_user, %{status: "bla"})
{:ok, _first_favorite} = CommonAPI.favorite(user, third_post.id) {:ok, _first_favorite} = CommonAPI.favorite(third_post.id, user)
{:ok, _second_favorite} = CommonAPI.favorite(user, first_post.id) {:ok, _second_favorite} = CommonAPI.favorite(first_post.id, user)
{:ok, third_favorite} = CommonAPI.favorite(user, second_post.id) {:ok, third_favorite} = CommonAPI.favorite(second_post.id, user)
result = result =
conn conn
@ -2134,7 +2134,7 @@ test "returns the favorites of a user" do
{:ok, _} = CommonAPI.post(other_user, %{status: "bla"}) {:ok, _} = CommonAPI.post(other_user, %{status: "bla"})
{:ok, activity} = CommonAPI.post(other_user, %{status: "trees are happy"}) {:ok, activity} = CommonAPI.post(other_user, %{status: "trees are happy"})
{:ok, last_like} = CommonAPI.favorite(user, activity.id) {:ok, last_like} = CommonAPI.favorite(activity.id, user)
first_conn = get(conn, "/api/v1/favourites") first_conn = get(conn, "/api/v1/favourites")
@ -2150,7 +2150,7 @@ test "returns the favorites of a user" do
status: "Trees Are Never Sad Look At Them Every Once In Awhile They're Quite Beautiful." status: "Trees Are Never Sad Look At Them Every Once In Awhile They're Quite Beautiful."
}) })
{:ok, _} = CommonAPI.favorite(user, second_activity.id) {:ok, _} = CommonAPI.favorite(second_activity.id, user)
second_conn = get(conn, "/api/v1/favourites?since_id=#{last_like.id}") second_conn = get(conn, "/api/v1/favourites?since_id=#{last_like.id}")

View file

@ -47,7 +47,7 @@ test "returns v2 suggestions excluding dismissed accounts", %{conn: conn} do
test "returns v2 suggestions excluding blocked accounts", %{conn: conn, user: blocker} do test "returns v2 suggestions excluding blocked accounts", %{conn: conn, user: blocker} do
blocked = insert(:user, is_suggested: true) blocked = insert(:user, is_suggested: true)
{:ok, _} = CommonAPI.block(blocker, blocked) {:ok, _} = CommonAPI.block(blocked, blocker)
res = res =
conn conn
@ -59,7 +59,7 @@ test "returns v2 suggestions excluding blocked accounts", %{conn: conn, user: bl
test "returns v2 suggestions excluding followed accounts", %{conn: conn, user: follower} do test "returns v2 suggestions excluding followed accounts", %{conn: conn, user: follower} do
followed = insert(:user, is_suggested: true) followed = insert(:user, is_suggested: true)
{:ok, _, _, _} = CommonAPI.follow(follower, followed) {:ok, _, _, _} = CommonAPI.follow(followed, follower)
res = res =
conn conn

View file

@ -436,7 +436,7 @@ test "represent a relationship for the following and followed user" do
{:ok, other_user, user} = User.follow(other_user, user) {:ok, other_user, user} = User.follow(other_user, user)
{:ok, _subscription} = User.subscribe(user, other_user) {:ok, _subscription} = User.subscribe(user, other_user)
{:ok, _user_relationships} = User.mute(user, other_user, %{notifications: true}) {:ok, _user_relationships} = User.mute(user, other_user, %{notifications: true})
{:ok, _reblog_mute} = CommonAPI.hide_reblogs(user, other_user) {:ok, _reblog_mute} = CommonAPI.hide_reblogs(other_user, user)
expected = expected =
Map.merge( Map.merge(
@ -493,7 +493,7 @@ test "represent a relationship for the user with a pending follow request" do
user = insert(:user) user = insert(:user)
other_user = insert(:user, is_locked: true) other_user = insert(:user, is_locked: true)
{:ok, user, other_user, _} = CommonAPI.follow(user, other_user) {:ok, user, other_user, _} = CommonAPI.follow(other_user, user)
user = User.get_cached_by_id(user.id) user = User.get_cached_by_id(user.id)
other_user = User.get_cached_by_id(other_user.id) other_user = User.get_cached_by_id(other_user.id)
@ -547,8 +547,8 @@ test "shows when follows/followers stats are hidden and sets follow/follower cou
}) })
other_user = insert(:user) other_user = insert(:user)
{:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, other_user, _activity} = CommonAPI.follow(other_user, user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user)
assert %{ assert %{
followers_count: 0, followers_count: 0,
@ -560,8 +560,8 @@ test "shows when follows/followers stats are hidden and sets follow/follower cou
test "shows when follows/followers are hidden" do test "shows when follows/followers are hidden" do
user = insert(:user, hide_followers: true, hide_follows: true) user = insert(:user, hide_followers: true, hide_follows: true)
other_user = insert(:user) other_user = insert(:user)
{:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, other_user, _activity} = CommonAPI.follow(other_user, user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user)
assert %{ assert %{
followers_count: 1, followers_count: 1,
@ -573,11 +573,11 @@ test "shows when follows/followers are hidden" do
test "shows actual follower/following count to the account owner" do test "shows actual follower/following count to the account owner" do
user = insert(:user, hide_followers: true, hide_follows: true) user = insert(:user, hide_followers: true, hide_follows: true)
other_user = insert(:user) other_user = insert(:user)
{:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, other_user, _activity} = CommonAPI.follow(other_user, user)
assert User.following?(user, other_user) assert User.following?(user, other_user)
assert Pleroma.FollowingRelationship.follower_count(other_user) == 1 assert Pleroma.FollowingRelationship.follower_count(other_user) == 1
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user)
assert %{ assert %{
followers_count: 1, followers_count: 1,
@ -684,7 +684,7 @@ test "shows zero when no follow requests are pending" do
AccountView.render("show.json", %{user: user, for: user}) AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user) other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user)
assert %{follow_requests_count: 0} = assert %{follow_requests_count: 0} =
AccountView.render("show.json", %{user: user, for: user}) AccountView.render("show.json", %{user: user, for: user})
@ -696,7 +696,7 @@ test "shows non-zero when follow requests are pending" do
assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user}) assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user) other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user)
assert %{locked: true, follow_requests_count: 1} = assert %{locked: true, follow_requests_count: 1} =
AccountView.render("show.json", %{user: user, for: user}) AccountView.render("show.json", %{user: user, for: user})
@ -708,7 +708,7 @@ test "decreases when accepting a follow request" do
assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user}) assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user) other_user = insert(:user)
{:ok, other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, other_user, user, _activity} = CommonAPI.follow(user, other_user)
assert %{locked: true, follow_requests_count: 1} = assert %{locked: true, follow_requests_count: 1} =
AccountView.render("show.json", %{user: user, for: user}) AccountView.render("show.json", %{user: user, for: user})
@ -725,7 +725,7 @@ test "decreases when rejecting a follow request" do
assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user}) assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user) other_user = insert(:user)
{:ok, other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, other_user, user, _activity} = CommonAPI.follow(user, other_user)
assert %{locked: true, follow_requests_count: 1} = assert %{locked: true, follow_requests_count: 1} =
AccountView.render("show.json", %{user: user, for: user}) AccountView.render("show.json", %{user: user, for: user})
@ -742,7 +742,7 @@ test "shows non-zero when historical unapproved requests are present" do
assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user}) assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user) other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user)
{:ok, user} = User.update_and_set_cache(user, %{is_locked: false}) {:ok, user} = User.update_and_set_cache(user, %{is_locked: false})

View file

@ -93,7 +93,7 @@ test "Favourite notification" do
user = insert(:user) user = insert(:user)
another_user = insert(:user) another_user = insert(:user)
{:ok, create_activity} = CommonAPI.post(user, %{status: "hey"}) {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})
{:ok, favorite_activity} = CommonAPI.favorite(another_user, create_activity.id) {:ok, favorite_activity} = CommonAPI.favorite(create_activity.id, another_user)
{:ok, [notification]} = Notification.create_notifications(favorite_activity) {:ok, [notification]} = Notification.create_notifications(favorite_activity)
create_activity = Activity.get_by_id(create_activity.id) create_activity = Activity.get_by_id(create_activity.id)
@ -132,7 +132,7 @@ test "Reblog notification" do
test "Follow notification" do test "Follow notification" do
follower = insert(:user) follower = insert(:user)
followed = insert(:user) followed = insert(:user)
{:ok, follower, followed, _activity} = CommonAPI.follow(follower, followed) {:ok, follower, followed, _activity} = CommonAPI.follow(followed, follower)
notification = Notification |> Repo.one() |> Repo.preload(:activity) notification = Notification |> Repo.one() |> Repo.preload(:activity)
expected = %{ expected = %{
@ -290,7 +290,7 @@ test "Edit notification" do
{:ok, activity} = CommonAPI.post(user, %{status: "mew"}) {:ok, activity} = CommonAPI.post(user, %{status: "mew"})
{:ok, _} = CommonAPI.repeat(activity.id, repeat_user) {:ok, _} = CommonAPI.repeat(activity.id, repeat_user)
{:ok, update} = CommonAPI.update(user, activity, %{status: "mew mew"}) {:ok, update} = CommonAPI.update(activity, user, %{status: "mew mew"})
user = Pleroma.User.get_by_ap_id(user.ap_id) user = Pleroma.User.get_by_ap_id(user.ap_id)
activity = Pleroma.Activity.normalize(activity) activity = Pleroma.Activity.normalize(activity)
@ -316,7 +316,7 @@ test "muted notification" do
{:ok, _} = Pleroma.UserRelationship.create_mute(user, another_user) {:ok, _} = Pleroma.UserRelationship.create_mute(user, another_user)
{:ok, create_activity} = CommonAPI.post(user, %{status: "hey"}) {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})
{:ok, favorite_activity} = CommonAPI.favorite(another_user, create_activity.id) {:ok, favorite_activity} = CommonAPI.favorite(create_activity.id, another_user)
{:ok, [notification]} = Notification.create_notifications(favorite_activity) {:ok, [notification]} = Notification.create_notifications(favorite_activity)
create_activity = Activity.get_by_id(create_activity.id) create_activity = Activity.get_by_id(create_activity.id)

View file

@ -74,7 +74,7 @@ test "detects if it is multiple choice" do
object = Object.normalize(activity, fetch: false) object = Object.normalize(activity, fetch: false)
{:ok, _votes, object} = CommonAPI.vote(voter, object, [0, 1]) {:ok, _votes, object} = CommonAPI.vote(object, voter, [0, 1])
assert match?( assert match?(
%{ %{
@ -119,7 +119,7 @@ test "detects vote status" do
object = Object.normalize(activity, fetch: false) object = Object.normalize(activity, fetch: false)
{:ok, _, object} = CommonAPI.vote(other_user, object, [1, 2]) {:ok, _, object} = CommonAPI.vote(object, other_user, [1, 2])
result = PollView.render("show.json", %{object: object, for: other_user}) result = PollView.render("show.json", %{object: object, for: other_user})

View file

@ -388,7 +388,7 @@ test "tells if the message is thread muted" do
assert status.pleroma.thread_muted == false assert status.pleroma.thread_muted == false
{:ok, activity} = CommonAPI.add_mute(user, activity) {:ok, activity} = CommonAPI.add_mute(activity, user)
status = StatusView.render("show.json", %{activity: activity, for: user}) status = StatusView.render("show.json", %{activity: activity, for: user})
@ -479,7 +479,7 @@ test "quoted private post" do
# After following the user, the quote is rendered # After following the user, the quote is rendered
follower = insert(:user) follower = insert(:user)
CommonAPI.follow(follower, user) CommonAPI.follow(user, follower)
status = StatusView.render("show.json", %{activity: quote_private, for: follower}) status = StatusView.render("show.json", %{activity: quote_private, for: follower})
assert status.pleroma.quote.id == to_string(private.id) assert status.pleroma.quote.id == to_string(private.id)
@ -938,7 +938,7 @@ test "it shows edited_at" do
status = StatusView.render("show.json", activity: post) status = StatusView.render("show.json", activity: post)
refute status.edited_at refute status.edited_at
{:ok, _} = CommonAPI.update(poster, post, %{status: "mew mew"}) {:ok, _} = CommonAPI.update(post, poster, %{status: "mew mew"})
edited = Pleroma.Activity.normalize(post) edited = Pleroma.Activity.normalize(post)
status = StatusView.render("show.json", activity: edited) status = StatusView.render("show.json", activity: edited)

View file

@ -81,7 +81,7 @@ test "it does not return old content after editing" do
object = Pleroma.Object.normalize(activity) object = Pleroma.Object.normalize(activity)
assert Utils.scrub_html_and_truncate(object) == "mew mew #def" assert Utils.scrub_html_and_truncate(object) == "mew mew #def"
{:ok, update} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "mew mew #abc"}) {:ok, update} = Pleroma.Web.CommonAPI.update(activity, user, %{status: "mew mew #abc"})
update = Pleroma.Activity.normalize(update) update = Pleroma.Activity.normalize(update)
object = Pleroma.Object.normalize(update) object = Pleroma.Object.normalize(update)
assert Utils.scrub_html_and_truncate(object) == "mew mew #abc" assert Utils.scrub_html_and_truncate(object) == "mew mew #abc"

View file

@ -186,7 +186,7 @@ test "render html for redirect for html format", %{conn: conn} do
user = insert(:user) user = insert(:user)
{:ok, like_activity} = CommonAPI.favorite(user, note_activity.id) {:ok, like_activity} = CommonAPI.favorite(note_activity.id, user)
assert like_activity.data["type"] == "Like" assert like_activity.data["type"] == "Like"

View file

@ -78,7 +78,7 @@ test "returns list of statuses favorited by specified user", %{
user: user user: user
} do } do
[activity | _] = insert_pair(:note_activity) [activity | _] = insert_pair(:note_activity)
CommonAPI.favorite(user, activity.id) CommonAPI.favorite(activity.id, user)
response = response =
conn conn
@ -95,7 +95,7 @@ test "returns favorites for specified user_id when requester is not logged in",
user: user user: user
} do } do
activity = insert(:note_activity) activity = insert(:note_activity)
CommonAPI.favorite(user, activity.id) CommonAPI.favorite(activity.id, user)
response = response =
build_conn() build_conn()
@ -115,7 +115,7 @@ test "returns favorited DM only when user is logged in and he is one of recipien
visibility: "direct" visibility: "direct"
}) })
CommonAPI.favorite(user, direct.id) CommonAPI.favorite(direct.id, user)
for u <- [user, current_user] do for u <- [user, current_user] do
response = response =
@ -148,7 +148,7 @@ test "does not return others' favorited DM when user is not one of recipients",
visibility: "direct" visibility: "direct"
}) })
CommonAPI.favorite(user, direct.id) CommonAPI.favorite(direct.id, user)
response = response =
conn conn
@ -165,7 +165,7 @@ test "paginates favorites using since_id and max_id", %{
activities = insert_list(10, :note_activity) activities = insert_list(10, :note_activity)
Enum.each(activities, fn activity -> Enum.each(activities, fn activity ->
CommonAPI.favorite(user, activity.id) CommonAPI.favorite(activity.id, user)
end) end)
third_activity = Enum.at(activities, 2) third_activity = Enum.at(activities, 2)
@ -190,7 +190,7 @@ test "limits favorites using limit parameter", %{
7 7
|> insert_list(:note_activity) |> insert_list(:note_activity)
|> Enum.each(fn activity -> |> Enum.each(fn activity ->
CommonAPI.favorite(user, activity.id) CommonAPI.favorite(activity.id, user)
end) end)
response = response =
@ -222,7 +222,7 @@ test "returns 404 error when specified user is not exist", %{conn: conn} do
test "returns 403 error when user has hidden own favorites", %{conn: conn} do test "returns 403 error when user has hidden own favorites", %{conn: conn} do
user = insert(:user, hide_favorites: true) user = insert(:user, hide_favorites: true)
activity = insert(:note_activity) activity = insert(:note_activity)
CommonAPI.favorite(user, activity.id) CommonAPI.favorite(activity.id, user)
conn = get(conn, "/api/v1/pleroma/accounts/#{user.id}/favourites") conn = get(conn, "/api/v1/pleroma/accounts/#{user.id}/favourites")
@ -232,7 +232,7 @@ test "returns 403 error when user has hidden own favorites", %{conn: conn} do
test "hides favorites for new users by default", %{conn: conn} do test "hides favorites for new users by default", %{conn: conn} do
user = insert(:user) user = insert(:user)
activity = insert(:note_activity) activity = insert(:note_activity)
CommonAPI.favorite(user, activity.id) CommonAPI.favorite(activity.id, user)
assert user.hide_favorites assert user.hide_favorites
conn = get(conn, "/api/v1/pleroma/accounts/#{user.id}/favourites") conn = get(conn, "/api/v1/pleroma/accounts/#{user.id}/favourites")
@ -286,8 +286,8 @@ test "returns a list of pinned accounts", %{conn: conn} do
%{id: id2} = user2 = insert(:user) %{id: id2} = user2 = insert(:user)
%{id: id3} = user3 = insert(:user) %{id: id3} = user3 = insert(:user)
CommonAPI.follow(user1, user2) CommonAPI.follow(user2, user1)
CommonAPI.follow(user1, user3) CommonAPI.follow(user3, user1)
User.endorse(user1, user2) User.endorse(user1, user2)
User.endorse(user1, user3) User.endorse(user1, user3)
@ -324,9 +324,9 @@ test "returns a list of friends having birthday on specified day" do
user3 = insert(:user) user3 = insert(:user)
CommonAPI.follow(user, user1) CommonAPI.follow(user1, user)
CommonAPI.follow(user, user2) CommonAPI.follow(user2, user)
CommonAPI.follow(user, user3) CommonAPI.follow(user3, user)
[%{"id" => ^id1}] = [%{"id" => ^id1}] =
conn conn
@ -350,8 +350,8 @@ test "the list doesn't list friends with hidden birth date" do
show_birthday: true show_birthday: true
}) })
CommonAPI.follow(user, user1) CommonAPI.follow(user1, user)
CommonAPI.follow(user, user2) CommonAPI.follow(user2, user)
[%{"id" => ^id2}] = [%{"id" => ^id2}] =
conn conn

View file

@ -78,7 +78,7 @@ test "fail message sending" do
) )
other_user = insert(:user) other_user = insert(:user)
{:ok, _, _, activity} = CommonAPI.follow(user, other_user) {:ok, _, _, activity} = CommonAPI.follow(other_user, user)
notif = notif =
insert(:notification, insert(:notification,
@ -103,7 +103,7 @@ test "delete subscription if result send message between 400..500" do
) )
other_user = insert(:user) other_user = insert(:user)
{:ok, _, _, activity} = CommonAPI.follow(user, other_user) {:ok, _, _, activity} = CommonAPI.follow(other_user, user)
notif = notif =
insert(:notification, insert(:notification,
@ -154,7 +154,7 @@ test "renders title and body for create activity" do
test "renders title and body for follow activity" do test "renders title and body for follow activity" do
user = insert(:user, nickname: "Bob") user = insert(:user, nickname: "Bob")
other_user = insert(:user) other_user = insert(:user)
{:ok, _, _, activity} = CommonAPI.follow(user, other_user) {:ok, _, _, activity} = CommonAPI.follow(other_user, user)
object = Object.normalize(activity, fetch: false) object = Object.normalize(activity, fetch: false)
assert Impl.format_body(%{activity: activity, type: "follow"}, user, object) == assert Impl.format_body(%{activity: activity, type: "follow"}, user, object) ==
@ -192,7 +192,7 @@ test "renders title and body for like activity" do
"<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis." "<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
}) })
{:ok, activity} = CommonAPI.favorite(user, activity.id) {:ok, activity} = CommonAPI.favorite(activity.id, user)
object = Object.normalize(activity, fetch: false) object = Object.normalize(activity, fetch: false)
assert Impl.format_body(%{activity: activity, type: "favourite"}, user, object) == assert Impl.format_body(%{activity: activity, type: "favourite"}, user, object) ==
@ -225,7 +225,7 @@ test "renders title and body for update activity" do
{:ok, activity} = CommonAPI.post(user, %{status: "lorem ipsum"}) {:ok, activity} = CommonAPI.post(user, %{status: "lorem ipsum"})
{:ok, activity} = CommonAPI.update(user, activity, %{status: "edited status"}) {:ok, activity} = CommonAPI.update(activity, user, %{status: "edited status"})
object = Object.normalize(activity, fetch: false) object = Object.normalize(activity, fetch: false)
assert Impl.format_body(%{activity: activity, type: "update"}, user, object) == assert Impl.format_body(%{activity: activity, type: "update"}, user, object) ==
@ -351,7 +351,7 @@ test "hides contents of notifications when option enabled" do
body: "New Mention" body: "New Mention"
} }
{:ok, activity} = CommonAPI.favorite(user, activity.id) {:ok, activity} = CommonAPI.favorite(activity.id, user)
notif = insert(:notification, user: user2, activity: activity, type: "favourite") notif = insert(:notification, user: user2, activity: activity, type: "favourite")
@ -408,7 +408,7 @@ test "returns regular content when hiding contents option disabled" do
title: "New Mention" title: "New Mention"
} }
{:ok, activity} = CommonAPI.favorite(user, activity.id) {:ok, activity} = CommonAPI.favorite(activity.id, user)
notif = insert(:notification, user: user2, activity: activity, type: "favourite") notif = insert(:notification, user: user2, activity: activity, type: "favourite")

View file

@ -70,7 +70,7 @@ test "recrawls URLs on status edits/updates" do
Card.get_by_activity(activity) Card.get_by_activity(activity)
) )
{:ok, _} = CommonAPI.update(user, activity, %{status: "I like this site #{updated_url}"}) {:ok, _} = CommonAPI.update(activity, user, %{status: "I like this site #{updated_url}"})
activity = Pleroma.Activity.get_by_id(activity.id) activity = Pleroma.Activity.get_by_id(activity.id)

View file

@ -418,7 +418,7 @@ test "it doesn't send notify to the 'user:notification' stream when a user is bl
Streamer.get_topic_and_add_socket("user:notification", user, oauth_token) Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
{:ok, activity} = CommonAPI.post(user, %{status: ":("}) {:ok, activity} = CommonAPI.post(user, %{status: ":("})
{:ok, _} = CommonAPI.favorite(blocked, activity.id) {:ok, _} = CommonAPI.favorite(activity.id, blocked)
refute_receive _ refute_receive _
end end
@ -430,11 +430,11 @@ test "it doesn't send notify to the 'user:notification' stream when a thread is
user2 = insert(:user) user2 = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: "super hot take"}) {:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
{:ok, _} = CommonAPI.add_mute(user, activity) {:ok, _} = CommonAPI.add_mute(activity, user)
Streamer.get_topic_and_add_socket("user:notification", user, oauth_token) Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
{:ok, favorite_activity} = CommonAPI.favorite(user2, activity.id) {:ok, favorite_activity} = CommonAPI.favorite(activity.id, user2)
refute_receive _ refute_receive _
assert Streamer.filtered_by_user?(user, favorite_activity) assert Streamer.filtered_by_user?(user, favorite_activity)
@ -448,7 +448,7 @@ test "it sends favorite to 'user:notification' stream'", %{
{:ok, activity} = CommonAPI.post(user, %{status: "super hot take"}) {:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
Streamer.get_topic_and_add_socket("user:notification", user, oauth_token) Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
{:ok, favorite_activity} = CommonAPI.favorite(user2, activity.id) {:ok, favorite_activity} = CommonAPI.favorite(activity.id, user2)
assert_receive {:render_with_user, _, "notification.json", notif, _} assert_receive {:render_with_user, _, "notification.json", notif, _}
assert notif.activity.id == favorite_activity.id assert notif.activity.id == favorite_activity.id
@ -464,7 +464,7 @@ test "it doesn't send the 'user:notification' stream' when a domain is blocked",
{:ok, user} = User.block_domain(user, "hecking-lewd-place.com") {:ok, user} = User.block_domain(user, "hecking-lewd-place.com")
{:ok, activity} = CommonAPI.post(user, %{status: "super hot take"}) {:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
Streamer.get_topic_and_add_socket("user:notification", user, oauth_token) Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
{:ok, favorite_activity} = CommonAPI.favorite(user2, activity.id) {:ok, favorite_activity} = CommonAPI.favorite(activity.id, user2)
refute_receive _ refute_receive _
assert Streamer.filtered_by_user?(user, favorite_activity) assert Streamer.filtered_by_user?(user, favorite_activity)
@ -477,7 +477,7 @@ test "it sends follow activities to the 'user:notification' stream", %{
user2 = insert(:user) user2 = insert(:user)
Streamer.get_topic_and_add_socket("user:notification", user, oauth_token) Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
{:ok, _follower, _followed, follow_activity} = CommonAPI.follow(user2, user) {:ok, _follower, _followed, follow_activity} = CommonAPI.follow(user, user2)
assert_receive {:render_with_user, _, "notification.json", notif, _} assert_receive {:render_with_user, _, "notification.json", notif, _}
assert notif.activity.id == follow_activity.id assert notif.activity.id == follow_activity.id
@ -493,7 +493,7 @@ test "it sends follow relationships updates to the 'user' stream", %{
other_user_id = other_user.id other_user_id = other_user.id
Streamer.get_topic_and_add_socket("user", user, oauth_token) Streamer.get_topic_and_add_socket("user", user, oauth_token)
{:ok, _follower, _followed, _follow_activity} = CommonAPI.follow(user, other_user) {:ok, _follower, _followed, _follow_activity} = CommonAPI.follow(other_user, user)
assert_receive {:text, event} assert_receive {:text, event}
@ -536,12 +536,12 @@ test "it sends follow relationships updates to the 'user' stream", %{
test "it streams edits in the 'user' stream", %{user: user, token: oauth_token} do test "it streams edits in the 'user' stream", %{user: user, token: oauth_token} do
sender = insert(:user) sender = insert(:user)
{:ok, _, _, _} = CommonAPI.follow(user, sender) {:ok, _, _, _} = CommonAPI.follow(sender, user)
{:ok, activity} = CommonAPI.post(sender, %{status: "hey"}) {:ok, activity} = CommonAPI.post(sender, %{status: "hey"})
Streamer.get_topic_and_add_socket("user", user, oauth_token) Streamer.get_topic_and_add_socket("user", user, oauth_token)
{:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"}) {:ok, edited} = CommonAPI.update(activity, sender, %{status: "mew mew"})
create = Pleroma.Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"]) create = Pleroma.Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"])
assert_receive {:render_with_user, _, "status_update.json", ^create, _} assert_receive {:render_with_user, _, "status_update.json", ^create, _}
@ -552,7 +552,7 @@ test "it streams own edits in the 'user' stream", %{user: user, token: oauth_tok
{:ok, activity} = CommonAPI.post(user, %{status: "hey"}) {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
Streamer.get_topic_and_add_socket("user", user, oauth_token) Streamer.get_topic_and_add_socket("user", user, oauth_token)
{:ok, edited} = CommonAPI.update(user, activity, %{status: "mew mew"}) {:ok, edited} = CommonAPI.update(activity, user, %{status: "mew mew"})
create = Pleroma.Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"]) create = Pleroma.Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"])
assert_receive {:render_with_user, _, "status_update.json", ^create, _} assert_receive {:render_with_user, _, "status_update.json", ^create, _}
@ -608,7 +608,7 @@ test "it streams edits in the 'public' stream" do
{:ok, activity} = CommonAPI.post(sender, %{status: "hey"}) {:ok, activity} = CommonAPI.post(sender, %{status: "hey"})
assert_receive {:text, _} assert_receive {:text, _}
{:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"}) {:ok, edited} = CommonAPI.update(activity, sender, %{status: "mew mew"})
edited = Pleroma.Activity.normalize(edited) edited = Pleroma.Activity.normalize(edited)
@ -627,7 +627,7 @@ test "it streams multiple edits in the 'public' stream correctly" do
{:ok, activity} = CommonAPI.post(sender, %{status: "hey"}) {:ok, activity} = CommonAPI.post(sender, %{status: "hey"})
assert_receive {:text, _} assert_receive {:text, _}
{:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"}) {:ok, edited} = CommonAPI.update(activity, sender, %{status: "mew mew"})
edited = Pleroma.Activity.normalize(edited) edited = Pleroma.Activity.normalize(edited)
@ -638,7 +638,7 @@ test "it streams multiple edits in the 'public' stream correctly" do
assert %{"id" => ^activity_id} = Jason.decode!(payload) assert %{"id" => ^activity_id} = Jason.decode!(payload)
refute Streamer.filtered_by_user?(sender, edited) refute Streamer.filtered_by_user?(sender, edited)
{:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew 2"}) {:ok, edited} = CommonAPI.update(activity, sender, %{status: "mew mew 2"})
edited = Pleroma.Activity.normalize(edited) edited = Pleroma.Activity.normalize(edited)
@ -826,8 +826,8 @@ test "it sends wanted private posts to list", %{user: user_a, token: user_a_toke
test "it filters muted reblogs", %{user: user1, token: user1_token} do test "it filters muted reblogs", %{user: user1, token: user1_token} do
user2 = insert(:user) user2 = insert(:user)
user3 = insert(:user) user3 = insert(:user)
CommonAPI.follow(user1, user2) CommonAPI.follow(user2, user1)
CommonAPI.hide_reblogs(user1, user2) CommonAPI.hide_reblogs(user2, user1)
{:ok, create_activity} = CommonAPI.post(user3, %{status: "I'm kawen"}) {:ok, create_activity} = CommonAPI.post(user3, %{status: "I'm kawen"})
@ -842,8 +842,8 @@ test "it filters reblog notification for reblog-muted actors", %{
token: user1_token token: user1_token
} do } do
user2 = insert(:user) user2 = insert(:user)
CommonAPI.follow(user1, user2) CommonAPI.follow(user2, user1)
CommonAPI.hide_reblogs(user1, user2) CommonAPI.hide_reblogs(user2, user1)
{:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"}) {:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"})
Streamer.get_topic_and_add_socket("user", user1, user1_token) Streamer.get_topic_and_add_socket("user", user1, user1_token)
@ -858,12 +858,12 @@ test "it send non-reblog notification for reblog-muted actors", %{
token: user1_token token: user1_token
} do } do
user2 = insert(:user) user2 = insert(:user)
CommonAPI.follow(user1, user2) CommonAPI.follow(user2, user1)
CommonAPI.hide_reblogs(user1, user2) CommonAPI.hide_reblogs(user2, user1)
{:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"}) {:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"})
Streamer.get_topic_and_add_socket("user", user1, user1_token) Streamer.get_topic_and_add_socket("user", user1, user1_token)
{:ok, _favorite_activity} = CommonAPI.favorite(user2, create_activity.id) {:ok, _favorite_activity} = CommonAPI.favorite(create_activity.id, user2)
assert_receive {:render_with_user, _, "notification.json", notif, _} assert_receive {:render_with_user, _, "notification.json", notif, _}
refute Streamer.filtered_by_user?(user1, notif) refute Streamer.filtered_by_user?(user1, notif)
@ -876,9 +876,9 @@ test "it filters posts from muted threads" do
%{user: user2, token: user2_token} = oauth_access(["read"]) %{user: user2, token: user2_token} = oauth_access(["read"])
Streamer.get_topic_and_add_socket("user", user2, user2_token) Streamer.get_topic_and_add_socket("user", user2, user2_token)
{:ok, user2, user, _activity} = CommonAPI.follow(user2, user) {:ok, user2, user, _activity} = CommonAPI.follow(user, user2)
{:ok, activity} = CommonAPI.post(user, %{status: "super hot take"}) {:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
{:ok, _} = CommonAPI.add_mute(user2, activity) {:ok, _} = CommonAPI.add_mute(activity, user2)
assert_receive {:render_with_user, _, _, ^activity, _} assert_receive {:render_with_user, _, _, ^activity, _}
assert Streamer.filtered_by_user?(user2, activity) assert Streamer.filtered_by_user?(user2, activity)
@ -1026,8 +1026,8 @@ test "do not revoke other tokens", %{
%{user: user2, token: user2_token} = oauth_access(["read"]) %{user: user2, token: user2_token} = oauth_access(["read"])
post_user = insert(:user) post_user = insert(:user)
CommonAPI.follow(user, post_user) CommonAPI.follow(post_user, user)
CommonAPI.follow(user2, post_user) CommonAPI.follow(post_user, user2)
tasks = [ tasks = [
Task.async(child_proc.(starter.(user, token), hit)), Task.async(child_proc.(starter.(user, token), hit)),
@ -1058,7 +1058,7 @@ test "revoke all streams for this token", %{
%{user: user, token: token} = oauth_access(["read"]) %{user: user, token: token} = oauth_access(["read"])
post_user = insert(:user) post_user = insert(:user)
CommonAPI.follow(user, post_user) CommonAPI.follow(post_user, user)
tasks = [ tasks = [
Task.async(child_proc.(starter.(user, token), hit)), Task.async(child_proc.(starter.(user, token), hit)),

View file

@ -216,7 +216,7 @@ test "returns error when followee not found", %{conn: conn} do
test "returns success result when user already in followers", %{conn: conn} do test "returns success result when user already in followers", %{conn: conn} do
user = insert(:user) user = insert(:user)
user2 = insert(:user) user2 = insert(:user)
{:ok, _, _, _} = CommonAPI.follow(user, user2) {:ok, _, _, _} = CommonAPI.follow(user2, user)
conn = conn =
conn conn