defp opts_for_home_timeline(user) do
%{
- "blocking_user" => user,
- "count" => "20",
- "muting_user" => user,
- "type" => ["Create", "Announce"],
- "user" => user,
- "with_muted" => "true"
+ blocking_user: user,
+ count: "20",
+ muting_user: user,
+ type: ["Create", "Announce"],
+ user: user,
+ with_muted: true
}
end
ActivityPub.fetch_activities(recipients, opts) |> Enum.reverse() |> List.last()
second_page_last =
- ActivityPub.fetch_activities(recipients, Map.put(opts, "max_id", first_page_last.id))
+ ActivityPub.fetch_activities(recipients, Map.put(opts, :max_id, first_page_last.id))
|> Enum.reverse()
|> List.last()
third_page_last =
- ActivityPub.fetch_activities(recipients, Map.put(opts, "max_id", second_page_last.id))
+ ActivityPub.fetch_activities(recipients, Map.put(opts, :max_id, second_page_last.id))
|> Enum.reverse()
|> List.last()
forth_page_last =
- ActivityPub.fetch_activities(recipients, Map.put(opts, "max_id", third_page_last.id))
+ ActivityPub.fetch_activities(recipients, Map.put(opts, :max_id, third_page_last.id))
|> Enum.reverse()
|> List.last()
},
inputs: %{
"1 page" => opts,
- "2 page" => Map.put(opts, "max_id", first_page_last.id),
- "3 page" => Map.put(opts, "max_id", second_page_last.id),
- "4 page" => Map.put(opts, "max_id", third_page_last.id),
- "5 page" => Map.put(opts, "max_id", forth_page_last.id),
- "1 page only media" => Map.put(opts, "only_media", "true"),
+ "2 page" => Map.put(opts, :max_id, first_page_last.id),
+ "3 page" => Map.put(opts, :max_id, second_page_last.id),
+ "4 page" => Map.put(opts, :max_id, third_page_last.id),
+ "5 page" => Map.put(opts, :max_id, forth_page_last.id),
+ "1 page only media" => Map.put(opts, :only_media, true),
"2 page only media" =>
- Map.put(opts, "max_id", first_page_last.id) |> Map.put("only_media", "true"),
+ Map.put(opts, :max_id, first_page_last.id) |> Map.put(:only_media, true),
"3 page only media" =>
- Map.put(opts, "max_id", second_page_last.id) |> Map.put("only_media", "true"),
+ Map.put(opts, :max_id, second_page_last.id) |> Map.put(:only_media, true),
"4 page only media" =>
- Map.put(opts, "max_id", third_page_last.id) |> Map.put("only_media", "true"),
+ Map.put(opts, :max_id, third_page_last.id) |> Map.put(:only_media, true),
"5 page only media" =>
- Map.put(opts, "max_id", forth_page_last.id) |> Map.put("only_media", "true")
+ Map.put(opts, :max_id, forth_page_last.id) |> Map.put(:only_media, true)
},
formatters: formatters()
)
defp opts_for_direct_timeline(user) do
%{
- :visibility => "direct",
- "blocking_user" => user,
- "count" => "20",
- "type" => "Create",
- "user" => user,
- "with_muted" => "true"
+ visibility: "direct",
+ blocking_user: user,
+ count: "20",
+ type: "Create",
+ user: user,
+ with_muted: true
}
end
|> Pagination.fetch_paginated(opts)
|> List.last()
- opts2 = Map.put(opts, "max_id", first_page_last.id)
+ opts2 = Map.put(opts, :max_id, first_page_last.id)
second_page_last =
recipients
|> Pagination.fetch_paginated(opts2)
|> List.last()
- opts3 = Map.put(opts, "max_id", second_page_last.id)
+ opts3 = Map.put(opts, :max_id, second_page_last.id)
third_page_last =
recipients
|> Pagination.fetch_paginated(opts3)
|> List.last()
- opts4 = Map.put(opts, "max_id", third_page_last.id)
+ opts4 = Map.put(opts, :max_id, third_page_last.id)
forth_page_last =
recipients
"2 page" => opts2,
"3 page" => opts3,
"4 page" => opts4,
- "5 page" => Map.put(opts4, "max_id", forth_page_last.id)
+ "5 page" => Map.put(opts4, :max_id, forth_page_last.id)
},
formatters: formatters()
)
defp opts_for_public_timeline(user) do
%{
- "type" => ["Create", "Announce"],
- "local_only" => false,
- "blocking_user" => user,
- "muting_user" => user
+ type: ["Create", "Announce"],
+ local_only: false,
+ blocking_user: user,
+ muting_user: user
}
end
defp opts_for_public_timeline(user, :local) do
%{
- "type" => ["Create", "Announce"],
- "local_only" => true,
- "blocking_user" => user,
- "muting_user" => user
+ type: ["Create", "Announce"],
+ local_only: true,
+ blocking_user: user,
+ muting_user: user
}
end
defp opts_for_public_timeline(user, :tag) do
%{
- "blocking_user" => user,
- "count" => "20",
- "local_only" => nil,
- "muting_user" => user,
- "tag" => ["tag"],
- "tag_all" => [],
- "tag_reject" => [],
- "type" => "Create",
- "user" => user,
- "with_muted" => "true"
+ blocking_user: user,
+ count: "20",
+ local_only: nil,
+ muting_user: user,
+ tag: ["tag"],
+ tag_all: [],
+ tag_reject: [],
+ type: "Create",
+ user: user,
+ with_muted: true
}
end
end
defp fetch_public_timeline(user, :only_media) do
- opts = opts_for_public_timeline(user) |> Map.put("only_media", "true")
+ opts = opts_for_public_timeline(user) |> Map.put(:only_media, true)
fetch_public_timeline(opts, "public timeline only media")
end
user = User.get_by_id(user.id)
- opts = Map.put(opts, "blocking_user", user)
+ opts = Map.put(opts, :blocking_user, user)
- Benchee.run(
- %{
- "public timeline with user block" => fn ->
- ActivityPub.fetch_public_activities(opts)
- end
- },
- )
+ Benchee.run(%{
+ "public timeline with user block" => fn ->
+ ActivityPub.fetch_public_activities(opts)
+ end
+ })
domains =
Enum.reduce(remote_non_friends, [], fn non_friend, domains ->
end)
user = User.get_by_id(user.id)
- opts = Map.put(opts, "blocking_user", user)
+ opts = Map.put(opts, :blocking_user, user)
- Benchee.run(
- %{
- "public timeline with domain block" => fn opts ->
- ActivityPub.fetch_public_activities(opts)
- end
- }
- )
+ Benchee.run(%{
+ "public timeline with domain block" => fn ->
+ ActivityPub.fetch_public_activities(opts)
+ end
+ })
end
defp fetch_public_timeline(opts, title) when is_binary(title) do
first_page_last = ActivityPub.fetch_public_activities(opts) |> List.last()
second_page_last =
- ActivityPub.fetch_public_activities(Map.put(opts, "max_id", first_page_last.id))
+ ActivityPub.fetch_public_activities(Map.put(opts, :max_id, first_page_last.id))
|> List.last()
third_page_last =
- ActivityPub.fetch_public_activities(Map.put(opts, "max_id", second_page_last.id))
+ ActivityPub.fetch_public_activities(Map.put(opts, :max_id, second_page_last.id))
|> List.last()
forth_page_last =
- ActivityPub.fetch_public_activities(Map.put(opts, "max_id", third_page_last.id))
+ ActivityPub.fetch_public_activities(Map.put(opts, :max_id, third_page_last.id))
|> List.last()
Benchee.run(
},
inputs: %{
"1 page" => opts,
- "2 page" => Map.put(opts, "max_id", first_page_last.id),
- "3 page" => Map.put(opts, "max_id", second_page_last.id),
- "4 page" => Map.put(opts, "max_id", third_page_last.id),
- "5 page" => Map.put(opts, "max_id", forth_page_last.id)
+ "2 page" => Map.put(opts, :max_id, first_page_last.id),
+ "3 page" => Map.put(opts, :max_id, second_page_last.id),
+ "4 page" => Map.put(opts, :max_id, third_page_last.id),
+ "5 page" => Map.put(opts, :max_id, forth_page_last.id)
},
formatters: formatters()
)
end
defp opts_for_notifications do
- %{"count" => "20", "with_muted" => "true"}
+ %{count: "20", with_muted: true}
end
defp fetch_notifications(user) do
first_page_last = MastodonAPI.get_notifications(user, opts) |> List.last()
second_page_last =
- MastodonAPI.get_notifications(user, Map.put(opts, "max_id", first_page_last.id))
+ MastodonAPI.get_notifications(user, Map.put(opts, :max_id, first_page_last.id))
|> List.last()
third_page_last =
- MastodonAPI.get_notifications(user, Map.put(opts, "max_id", second_page_last.id))
+ MastodonAPI.get_notifications(user, Map.put(opts, :max_id, second_page_last.id))
|> List.last()
forth_page_last =
- MastodonAPI.get_notifications(user, Map.put(opts, "max_id", third_page_last.id))
+ MastodonAPI.get_notifications(user, Map.put(opts, :max_id, third_page_last.id))
|> List.last()
Benchee.run(
},
inputs: %{
"1 page" => opts,
- "2 page" => Map.put(opts, "max_id", first_page_last.id),
- "3 page" => Map.put(opts, "max_id", second_page_last.id),
- "4 page" => Map.put(opts, "max_id", third_page_last.id),
- "5 page" => Map.put(opts, "max_id", forth_page_last.id)
+ "2 page" => Map.put(opts, :max_id, first_page_last.id),
+ "3 page" => Map.put(opts, :max_id, second_page_last.id),
+ "4 page" => Map.put(opts, :max_id, third_page_last.id),
+ "5 page" => Map.put(opts, :max_id, forth_page_last.id)
},
formatters: formatters()
)
first_page_last = ActivityPub.fetch_favourites(user) |> List.last()
second_page_last =
- ActivityPub.fetch_favourites(user, %{"max_id" => first_page_last.id}) |> List.last()
+ ActivityPub.fetch_favourites(user, %{:max_id => first_page_last.id}) |> List.last()
third_page_last =
- ActivityPub.fetch_favourites(user, %{"max_id" => second_page_last.id}) |> List.last()
+ ActivityPub.fetch_favourites(user, %{:max_id => second_page_last.id}) |> List.last()
forth_page_last =
- ActivityPub.fetch_favourites(user, %{"max_id" => third_page_last.id}) |> List.last()
+ ActivityPub.fetch_favourites(user, %{:max_id => third_page_last.id}) |> List.last()
Benchee.run(
%{
},
inputs: %{
"1 page" => %{},
- "2 page" => %{"max_id" => first_page_last.id},
- "3 page" => %{"max_id" => second_page_last.id},
- "4 page" => %{"max_id" => third_page_last.id},
- "5 page" => %{"max_id" => forth_page_last.id}
+ "2 page" => %{:max_id => first_page_last.id},
+ "3 page" => %{:max_id => second_page_last.id},
+ "4 page" => %{:max_id => third_page_last.id},
+ "5 page" => %{:max_id => forth_page_last.id}
},
formatters: formatters()
)
defp opts_for_long_thread(user) do
%{
- "blocking_user" => user,
- "user" => user
+ blocking_user: user,
+ user: user
}
end
opts = opts_for_long_thread(user)
- private_input = {private.data["context"], Map.put(opts, "exclude_id", private.id)}
+ private_input = {private.data["context"], Map.put(opts, :exclude_id, private.id)}
- public_input = {public.data["context"], Map.put(opts, "exclude_id", public.id)}
+ public_input = {public.data["context"], Map.put(opts, :exclude_id, public.id)}
Benchee.run(
%{
public_context =
ActivityPub.fetch_activities_for_context(
public.data["context"],
- Map.put(fetch_opts, "exclude_id", public.id)
+ Map.put(fetch_opts, :exclude_id, public.id)
)
private_context =
ActivityPub.fetch_activities_for_context(
private.data["context"],
- Map.put(fetch_opts, "exclude_id", private.id)
+ Map.put(fetch_opts, :exclude_id, private.id)
)
Benchee.run(
end,
"Public timeline with reply filtering - following" => fn ->
public_params
- |> Map.put("reply_visibility", "following")
- |> Map.put("reply_filtering_user", user)
+ |> Map.put(:reply_visibility, "following")
+ |> Map.put(:reply_filtering_user, user)
|> ActivityPub.fetch_public_activities()
end,
"Public timeline with reply filtering - self" => fn ->
public_params
- |> Map.put("reply_visibility", "self")
- |> Map.put("reply_filtering_user", user)
+ |> Map.put(:reply_visibility, "self")
+ |> Map.put(:reply_filtering_user, user)
|> ActivityPub.fetch_public_activities()
end
},
"Home timeline with reply filtering - following" => fn ->
private_params =
private_params
- |> Map.put("reply_filtering_user", user)
- |> Map.put("reply_visibility", "following")
+ |> Map.put(:reply_filtering_user, user)
+ |> Map.put(:reply_visibility, "following")
ActivityPub.fetch_activities(recipients, private_params)
end,
"Home timeline with reply filtering - self" => fn ->
private_params =
private_params
- |> Map.put("reply_filtering_user", user)
- |> Map.put("reply_visibility", "self")
+ |> Map.put(:reply_filtering_user, user)
+ |> Map.put(:reply_visibility, "self")
ActivityPub.fetch_activities(recipients, private_params)
end
_activities =
params
- |> Map.put("type", "Create")
- |> Map.put("local_only", local_only)
- |> Map.put("blocking_user", user)
- |> Map.put("muting_user", user)
- |> Map.put("user", user)
- |> Map.put("tag", tags)
- |> Map.put("tag_all", tag_all)
- |> Map.put("tag_reject", tag_reject)
+ |> Map.put(:type, "Create")
+ |> Map.put(:local_only, local_only)
+ |> Map.put(:blocking_user, user)
+ |> Map.put(:muting_user, user)
+ |> Map.put(:user, user)
+ |> Map.put(:tag, tags)
+ |> Map.put(:tag_all, tag_all)
+ |> Map.put(:tag_reject, tag_reject)
|> Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities()
end
end
params =
%{}
- |> Map.put("type", ["Create"])
- |> Map.put("blocking_user", user)
- |> Map.put("muting_user", user)
- |> Map.put("user", user)
+ |> Map.put(:type, ["Create"])
+ |> Map.put(:blocking_user, user)
+ |> Map.put(:muting_user, user)
+ |> Map.put(:user, user)
activities =
[user.ap_id | Pleroma.User.following(user)]
|> Enum.map(fn participation ->
activity_id =
ActivityPub.fetch_latest_activity_id_for_context(participation.conversation.ap_id, %{
- "user" => user,
- "blocking_user" => user
+ user: user,
+ blocking_user: user
})
%{
@default_limit 20
@max_limit 40
- @page_keys ["max_id", "min_id", "limit", "since_id", "order"]
-
- def page_keys, do: @page_keys
@spec fetch_paginated(Ecto.Query.t(), map(), type(), atom() | nil) :: [Ecto.Schema.t()]
def fetch_paginated(query, params, type \\ :keyset, table_binding \\ nil)
- def fetch_paginated(query, %{"total" => true} = params, :keyset, table_binding) do
+ def fetch_paginated(query, %{total: true} = params, :keyset, table_binding) do
total = Repo.aggregate(query, :count, :id)
%{
total: total,
- items: fetch_paginated(query, Map.drop(params, ["total"]), :keyset, table_binding)
+ items: fetch_paginated(query, Map.drop(params, [:total]), :keyset, table_binding)
}
end
|> enforce_order(options)
end
- def fetch_paginated(query, %{"total" => true} = params, :offset, table_binding) do
+ def fetch_paginated(query, %{total: true} = params, :offset, table_binding) do
total =
query
|> Ecto.Query.exclude(:left_join)
%{
total: total,
- items: fetch_paginated(query, Map.drop(params, ["total"]), :offset, table_binding)
+ items: fetch_paginated(query, Map.drop(params, [:total]), :offset, table_binding)
}
end
skip_order: :boolean
}
- params =
- Enum.reduce(params, %{}, fn
- {key, _value}, acc when is_atom(key) -> Map.drop(acc, [key])
- {key, value}, acc -> Map.put(acc, key, value)
- end)
-
changeset = cast({%{}, param_types}, params, Map.keys(param_types))
changeset.changes
end
{recipients, to, cc}
end
- defp check_actor_is_active(actor) do
- if not is_nil(actor) do
- with user <- User.get_cached_by_ap_id(actor),
- false <- user.deactivated do
- true
- else
- _e -> false
- end
- else
- true
+ defp check_actor_is_active(nil), do: true
+
+ defp check_actor_is_active(actor) when is_binary(actor) do
+ case User.get_cached_by_ap_id(actor) do
+ %User{deactivated: deactivated} -> not deactivated
+ _ -> false
end
end
defp check_remote_limit(_), do: true
- def increase_note_count_if_public(actor, object) do
+ defp increase_note_count_if_public(actor, object) do
if is_public?(object), do: User.increase_note_count(actor), else: {:ok, actor}
end
if is_public?(object), do: User.decrease_note_count(actor), else: {:ok, actor}
end
- def increase_replies_count_if_reply(%{
- "object" => %{"inReplyTo" => reply_ap_id} = object,
- "type" => "Create"
- }) do
+ defp increase_replies_count_if_reply(%{
+ "object" => %{"inReplyTo" => reply_ap_id} = object,
+ "type" => "Create"
+ }) do
if is_public?(object) do
Object.increase_replies_count(reply_ap_id)
end
end
- def increase_replies_count_if_reply(_create_data), do: :noop
-
- def decrease_replies_count_if_reply(%Object{
- data: %{"inReplyTo" => reply_ap_id} = object
- }) do
- if is_public?(object) do
- Object.decrease_replies_count(reply_ap_id)
- end
- end
-
- def decrease_replies_count_if_reply(_object), do: :noop
+ defp increase_replies_count_if_reply(_create_data), do: :noop
- def increase_poll_votes_if_vote(%{
- "object" => %{"inReplyTo" => reply_ap_id, "name" => name},
- "type" => "Create",
- "actor" => actor
- }) do
+ defp increase_poll_votes_if_vote(%{
+ "object" => %{"inReplyTo" => reply_ap_id, "name" => name},
+ "type" => "Create",
+ "actor" => actor
+ }) do
Object.increase_vote_count(reply_ap_id, name, actor)
end
- def increase_poll_votes_if_vote(_create_data), do: :noop
+ defp increase_poll_votes_if_vote(_create_data), do: :noop
@spec persist(map(), keyword()) :: {:ok, Activity.t() | Object.t()}
def persist(object, meta) do
defp create_or_bump_conversation(activity, actor) do
with {:ok, conversation} <- Conversation.create_or_bump_for(activity),
- %User{} = user <- User.get_cached_by_ap_id(actor),
- Participation.mark_as_read(user, conversation) do
+ %User{} = user <- User.get_cached_by_ap_id(actor) do
+ Participation.mark_as_read(user, conversation)
{:ok, conversation}
end
end
end
def stream_out_participations(%Object{data: %{"context" => context}}, user) do
- with %Conversation{} = conversation <- Conversation.get_for_ap_id(context),
- conversation = Repo.preload(conversation, :participations),
- last_activity_id =
- fetch_latest_activity_id_for_context(conversation.ap_id, %{
- "user" => user,
- "blocking_user" => user
- }) do
+ with %Conversation{} = conversation <- Conversation.get_for_ap_id(context) do
+ conversation = Repo.preload(conversation, :participations)
+
+ last_activity_id =
+ fetch_latest_activity_id_for_context(conversation.ap_id, %{
+ user: user,
+ blocking_user: user
+ })
+
if last_activity_id do
stream_out_participations(conversation.participations)
end
published = params[:published]
quick_insert? = Config.get([:env]) == :benchmark
- with create_data <-
- make_create_data(
- %{to: to, actor: actor, published: published, context: context, object: object},
- additional
- ),
- {:ok, activity} <- insert(create_data, local, fake),
+ create_data =
+ make_create_data(
+ %{to: to, actor: actor, published: published, context: context, object: object},
+ additional
+ )
+
+ with {:ok, activity} <- insert(create_data, local, fake),
{:fake, false, activity} <- {:fake, fake, activity},
_ <- increase_replies_count_if_reply(create_data),
_ <- increase_poll_votes_if_vote(create_data),
local = !(params[:local] == false)
published = params[:published]
- with listen_data <-
- make_listen_data(
- %{to: to, actor: actor, published: published, context: context, object: object},
- additional
- ),
- {:ok, activity} <- insert(listen_data, local),
+ listen_data =
+ make_listen_data(
+ %{to: to, actor: actor, published: published, context: context, object: object},
+ additional
+ )
+
+ with {:ok, activity} <- insert(listen_data, local),
_ <- notify_and_stream(activity),
:ok <- maybe_federate(activity) do
{:ok, activity}
end
@spec accept_or_reject(String.t(), map()) :: {:ok, Activity.t()} | {:error, any()}
- def accept_or_reject(type, %{to: to, actor: actor, object: object} = params) do
+ defp accept_or_reject(type, %{to: to, actor: actor, object: object} = params) do
local = Map.get(params, :local, true)
activity_id = Map.get(params, :activity_id, nil)
- with data <-
- %{"to" => to, "type" => type, "actor" => actor.ap_id, "object" => object}
- |> Utils.maybe_put("id", activity_id),
- {:ok, activity} <- insert(data, local),
+ data =
+ %{"to" => to, "type" => type, "actor" => actor.ap_id, "object" => object}
+ |> Utils.maybe_put("id", activity_id)
+
+ with {:ok, activity} <- insert(data, local),
_ <- notify_and_stream(activity),
:ok <- maybe_federate(activity) do
{:ok, activity}
local = !(params[:local] == false)
activity_id = params[:activity_id]
- with data <- %{
- "to" => to,
- "cc" => cc,
- "type" => "Update",
- "actor" => actor,
- "object" => object
- },
- data <- Utils.maybe_put(data, "id", activity_id),
- {:ok, activity} <- insert(data, local),
+ data =
+ %{
+ "to" => to,
+ "cc" => cc,
+ "type" => "Update",
+ "actor" => actor,
+ "object" => object
+ }
+ |> Utils.maybe_put("id", activity_id)
+
+ with {:ok, activity} <- insert(data, local),
_ <- notify_and_stream(activity),
:ok <- maybe_federate(activity) do
{:ok, activity}
end
defp do_follow(follower, followed, activity_id, local) do
- with data <- make_follow_data(follower, followed, activity_id),
- {:ok, activity} <- insert(data, local),
+ data = make_follow_data(follower, followed, activity_id)
+
+ with {:ok, activity} <- insert(data, local),
_ <- notify_and_stream(activity),
:ok <- maybe_federate(activity) do
{:ok, activity}
defp do_block(blocker, blocked, activity_id, local) do
unfollow_blocked = Config.get([:activitypub, :unfollow_blocked])
- if unfollow_blocked do
- follow_activity = fetch_latest_follow(blocker, blocked)
- if follow_activity, do: unfollow(blocker, blocked, nil, local)
+ if unfollow_blocked and fetch_latest_follow(blocker, blocked) do
+ unfollow(blocker, blocked, nil, local)
end
- with block_data <- make_block_data(blocker, blocked, activity_id),
- {:ok, activity} <- insert(block_data, local),
+ block_data = make_block_data(blocker, blocked, activity_id)
+
+ with {:ok, activity} <- insert(block_data, local),
_ <- notify_and_stream(activity),
:ok <- maybe_federate(activity) do
{:ok, activity}
public = [Constants.as_public()]
recipients =
- if opts["user"],
- do: [opts["user"].ap_id | User.following(opts["user"])] ++ public,
+ if opts[:user],
+ do: [opts[:user].ap_id | User.following(opts[:user])] ++ public,
else: public
from(activity in Activity)
|> maybe_preload_bookmarks(opts)
|> maybe_set_thread_muted_field(opts)
|> restrict_blocked(opts)
- |> restrict_recipients(recipients, opts["user"])
+ |> restrict_recipients(recipients, opts[:user])
|> where(
[activity],
fragment(
FlakeId.Ecto.CompatType.t() | nil
def fetch_latest_activity_id_for_context(context, opts \\ %{}) do
context
- |> fetch_activities_for_context_query(Map.merge(%{"skip_preload" => true}, opts))
+ |> fetch_activities_for_context_query(Map.merge(%{skip_preload: true}, opts))
|> limit(1)
|> select([a], a.id)
|> Repo.one()
@spec fetch_public_or_unlisted_activities(map(), Pagination.type()) :: [Activity.t()]
def fetch_public_or_unlisted_activities(opts \\ %{}, pagination \\ :keyset) do
- opts = Map.drop(opts, ["user"])
-
- query = fetch_activities_query([Constants.as_public()], opts)
-
- query =
- if opts["restrict_unlisted"] do
- restrict_unlisted(query)
- else
- query
- end
+ opts = Map.delete(opts, :user)
- Pagination.fetch_paginated(query, opts, pagination)
+ [Constants.as_public()]
+ |> fetch_activities_query(opts)
+ |> restrict_unlisted(opts)
+ |> Pagination.fetch_paginated(opts, pagination)
end
@spec fetch_public_activities(map(), Pagination.type()) :: [Activity.t()]
def fetch_public_activities(opts \\ %{}, pagination \\ :keyset) do
opts
- |> Map.put("restrict_unlisted", true)
+ |> Map.put(:restrict_unlisted, true)
|> fetch_public_or_unlisted_activities(pagination)
end
defp restrict_visibility(query, %{visibility: visibility})
when is_list(visibility) do
if Enum.all?(visibility, &(&1 in @valid_visibilities)) do
- query =
- from(
- a in query,
- where:
- fragment(
- "activity_visibility(?, ?, ?) = ANY (?)",
- a.actor,
- a.recipients,
- a.data,
- ^visibility
- )
- )
-
- query
+ from(
+ a in query,
+ where:
+ fragment(
+ "activity_visibility(?, ?, ?) = ANY (?)",
+ a.actor,
+ a.recipients,
+ a.data,
+ ^visibility
+ )
+ )
else
Logger.error("Could not restrict visibility to #{visibility}")
end
defp restrict_visibility(query, _visibility), do: query
- defp exclude_visibility(query, %{"exclude_visibilities" => visibility})
+ defp exclude_visibility(query, %{exclude_visibilities: visibility})
when is_list(visibility) do
if Enum.all?(visibility, &(&1 in @valid_visibilities)) do
from(
end
end
- defp exclude_visibility(query, %{"exclude_visibilities" => visibility})
+ defp exclude_visibility(query, %{exclude_visibilities: visibility})
when visibility in @valid_visibilities do
from(
a in query,
)
end
- defp exclude_visibility(query, %{"exclude_visibilities" => visibility})
+ defp exclude_visibility(query, %{exclude_visibilities: visibility})
when visibility not in [nil | @valid_visibilities] do
Logger.error("Could not exclude visibility to #{visibility}")
query
defp restrict_thread_visibility(query, _, %{skip_thread_containment: true} = _),
do: query
- defp restrict_thread_visibility(
- query,
- %{"user" => %User{skip_thread_containment: true}},
- _
- ),
- do: query
+ defp restrict_thread_visibility(query, %{user: %User{skip_thread_containment: true}}, _),
+ do: query
- defp restrict_thread_visibility(query, %{"user" => %User{ap_id: ap_id}}, _) do
+ defp restrict_thread_visibility(query, %{user: %User{ap_id: ap_id}}, _) do
from(
a in query,
where: fragment("thread_visibility(?, (?)->>'id') = true", ^ap_id, a.data)
def fetch_user_abstract_activities(user, reading_user, params \\ %{}) do
params =
params
- |> Map.put("user", reading_user)
- |> Map.put("actor_id", user.ap_id)
-
- recipients =
- user_activities_recipients(%{
- "godmode" => params["godmode"],
- "reading_user" => reading_user
- })
+ |> Map.put(:user, reading_user)
+ |> Map.put(:actor_id, user.ap_id)
- fetch_activities(recipients, params)
+ %{
+ godmode: params[:godmode],
+ reading_user: reading_user
+ }
+ |> user_activities_recipients()
+ |> fetch_activities(params)
|> Enum.reverse()
end
def fetch_user_activities(user, reading_user, params \\ %{}) do
params =
params
- |> Map.put("type", ["Create", "Announce"])
- |> Map.put("user", reading_user)
- |> Map.put("actor_id", user.ap_id)
- |> Map.put("pinned_activity_ids", user.pinned_activities)
+ |> Map.put(:type, ["Create", "Announce"])
+ |> Map.put(:user, reading_user)
+ |> Map.put(:actor_id, user.ap_id)
+ |> Map.put(:pinned_activity_ids, user.pinned_activities)
params =
if User.blocks?(reading_user, user) do
params
else
params
- |> Map.put("blocking_user", reading_user)
- |> Map.put("muting_user", reading_user)
+ |> Map.put(:blocking_user, reading_user)
+ |> Map.put(:muting_user, reading_user)
end
- recipients =
- user_activities_recipients(%{
- "godmode" => params["godmode"],
- "reading_user" => reading_user
- })
-
- fetch_activities(recipients, params)
+ %{
+ godmode: params[:godmode],
+ reading_user: reading_user
+ }
+ |> user_activities_recipients()
+ |> fetch_activities(params)
|> Enum.reverse()
end
def fetch_statuses(reading_user, params) do
- params =
- params
- |> Map.put("type", ["Create", "Announce"])
+ params = Map.put(params, :type, ["Create", "Announce"])
- recipients =
- user_activities_recipients(%{
- "godmode" => params["godmode"],
- "reading_user" => reading_user
- })
-
- fetch_activities(recipients, params, :offset)
+ %{
+ godmode: params[:godmode],
+ reading_user: reading_user
+ }
+ |> user_activities_recipients()
+ |> fetch_activities(params, :offset)
|> Enum.reverse()
end
- defp user_activities_recipients(%{"godmode" => true}) do
- []
- end
+ defp user_activities_recipients(%{godmode: true}), do: []
- defp user_activities_recipients(%{"reading_user" => reading_user}) do
+ defp user_activities_recipients(%{reading_user: reading_user}) do
if reading_user do
- [Constants.as_public()] ++ [reading_user.ap_id | User.following(reading_user)]
+ [Constants.as_public(), reading_user.ap_id | User.following(reading_user)]
else
[Constants.as_public()]
end
end
- defp restrict_since(query, %{"since_id" => ""}), do: query
+ defp restrict_since(query, %{since_id: ""}), do: query
- defp restrict_since(query, %{"since_id" => since_id}) do
+ defp restrict_since(query, %{since_id: since_id}) do
from(activity in query, where: activity.id > ^since_id)
end
defp restrict_since(query, _), do: query
- defp restrict_tag_reject(_query, %{"tag_reject" => _tag_reject, "skip_preload" => true}) do
+ defp restrict_tag_reject(_query, %{tag_reject: _tag_reject, skip_preload: true}) do
raise "Can't use the child object without preloading!"
end
- defp restrict_tag_reject(query, %{"tag_reject" => tag_reject})
- when is_list(tag_reject) and tag_reject != [] do
+ defp restrict_tag_reject(query, %{tag_reject: [_ | _] = tag_reject}) do
from(
[_activity, object] in query,
where: fragment("not (?)->'tag' \\?| (?)", object.data, ^tag_reject)
defp restrict_tag_reject(query, _), do: query
- defp restrict_tag_all(_query, %{"tag_all" => _tag_all, "skip_preload" => true}) do
+ defp restrict_tag_all(_query, %{tag_all: _tag_all, skip_preload: true}) do
raise "Can't use the child object without preloading!"
end
- defp restrict_tag_all(query, %{"tag_all" => tag_all})
- when is_list(tag_all) and tag_all != [] do
+ defp restrict_tag_all(query, %{tag_all: [_ | _] = tag_all}) do
from(
[_activity, object] in query,
where: fragment("(?)->'tag' \\?& (?)", object.data, ^tag_all)
defp restrict_tag_all(query, _), do: query
- defp restrict_tag(_query, %{"tag" => _tag, "skip_preload" => true}) do
+ defp restrict_tag(_query, %{tag: _tag, skip_preload: true}) do
raise "Can't use the child object without preloading!"
end
- defp restrict_tag(query, %{"tag" => tag}) when is_list(tag) do
+ defp restrict_tag(query, %{tag: tag}) when is_list(tag) do
from(
[_activity, object] in query,
where: fragment("(?)->'tag' \\?| (?)", object.data, ^tag)
)
end
- defp restrict_tag(query, %{"tag" => tag}) when is_binary(tag) do
+ defp restrict_tag(query, %{tag: tag}) when is_binary(tag) do
from(
[_activity, object] in query,
where: fragment("(?)->'tag' \\? (?)", object.data, ^tag)
)
end
- defp restrict_local(query, %{"local_only" => true}) do
+ defp restrict_local(query, %{local_only: true}) do
from(activity in query, where: activity.local == true)
end
defp restrict_local(query, _), do: query
- defp restrict_actor(query, %{"actor_id" => actor_id}) do
+ defp restrict_actor(query, %{actor_id: actor_id}) do
from(activity in query, where: activity.actor == ^actor_id)
end
defp restrict_actor(query, _), do: query
- defp restrict_type(query, %{"type" => type}) when is_binary(type) do
+ defp restrict_type(query, %{type: type}) when is_binary(type) do
from(activity in query, where: fragment("?->>'type' = ?", activity.data, ^type))
end
- defp restrict_type(query, %{"type" => type}) do
+ defp restrict_type(query, %{type: type}) do
from(activity in query, where: fragment("?->>'type' = ANY(?)", activity.data, ^type))
end
defp restrict_type(query, _), do: query
- defp restrict_state(query, %{"state" => state}) do
+ defp restrict_state(query, %{state: state}) do
from(activity in query, where: fragment("?->>'state' = ?", activity.data, ^state))
end
defp restrict_state(query, _), do: query
- defp restrict_favorited_by(query, %{"favorited_by" => ap_id}) do
+ defp restrict_favorited_by(query, %{favorited_by: ap_id}) do
from(
[_activity, object] in query,
where: fragment("(?)->'likes' \\? (?)", object.data, ^ap_id)
defp restrict_favorited_by(query, _), do: query
- defp restrict_media(_query, %{"only_media" => _val, "skip_preload" => true}) do
+ defp restrict_media(_query, %{only_media: _val, skip_preload: true}) do
raise "Can't use the child object without preloading!"
end
- defp restrict_media(query, %{"only_media" => val}) when val in [true, "true", "1"] do
+ defp restrict_media(query, %{only_media: true}) do
from(
[_activity, object] in query,
where: fragment("not (?)->'attachment' = (?)", object.data, ^[])
defp restrict_media(query, _), do: query
- defp restrict_replies(query, %{"exclude_replies" => val}) when val in [true, "true", "1"] do
+ defp restrict_replies(query, %{exclude_replies: true}) do
from(
[_activity, object] in query,
where: fragment("?->>'inReplyTo' is null", object.data)
end
defp restrict_replies(query, %{
- "reply_filtering_user" => user,
- "reply_visibility" => "self"
+ reply_filtering_user: user,
+ reply_visibility: "self"
}) do
from(
[activity, object] in query,
end
defp restrict_replies(query, %{
- "reply_filtering_user" => user,
- "reply_visibility" => "following"
+ reply_filtering_user: user,
+ reply_visibility: "following"
}) do
from(
[activity, object] in query,
defp restrict_replies(query, _), do: query
- defp restrict_reblogs(query, %{"exclude_reblogs" => val}) when val in [true, "true", "1"] do
+ defp restrict_reblogs(query, %{exclude_reblogs: true}) do
from(activity in query, where: fragment("?->>'type' != 'Announce'", activity.data))
end
defp restrict_reblogs(query, _), do: query
- defp restrict_muted(query, %{"with_muted" => val}) when val in [true, "true", "1"], do: query
+ defp restrict_muted(query, %{with_muted: true}), do: query
- defp restrict_muted(query, %{"muting_user" => %User{} = user} = opts) do
- mutes = opts["muted_users_ap_ids"] || User.muted_users_ap_ids(user)
+ defp restrict_muted(query, %{muting_user: %User{} = user} = opts) do
+ mutes = opts[:muted_users_ap_ids] || User.muted_users_ap_ids(user)
query =
from([activity] in query,
where: fragment("not (?->'to' \\?| ?)", activity.data, ^mutes)
)
- unless opts["skip_preload"] do
+ unless opts[:skip_preload] do
from([thread_mute: tm] in query, where: is_nil(tm.user_id))
else
query
defp restrict_muted(query, _), do: query
- defp restrict_blocked(query, %{"blocking_user" => %User{} = user} = opts) do
- blocked_ap_ids = opts["blocked_users_ap_ids"] || User.blocked_users_ap_ids(user)
+ defp restrict_blocked(query, %{blocking_user: %User{} = user} = opts) do
+ blocked_ap_ids = opts[:blocked_users_ap_ids] || User.blocked_users_ap_ids(user)
domain_blocks = user.domain_blocks || []
following_ap_ids = User.get_friends_ap_ids(user)
defp restrict_blocked(query, _), do: query
- defp restrict_unlisted(query) do
+ defp restrict_unlisted(query, %{restrict_unlisted: true}) do
from(
activity in query,
where:
)
end
- # TODO: when all endpoints migrated to OpenAPI compare `pinned` with `true` (boolean) only,
- # the same for `restrict_media/2`, `restrict_replies/2`, 'restrict_reblogs/2'
- # and `restrict_muted/2`
+ defp restrict_unlisted(query, _), do: query
- defp restrict_pinned(query, %{"pinned" => pinned, "pinned_activity_ids" => ids})
- when pinned in [true, "true", "1"] do
+ defp restrict_pinned(query, %{pinned: true, pinned_activity_ids: ids}) do
from(activity in query, where: activity.id in ^ids)
end
defp restrict_pinned(query, _), do: query
- defp restrict_muted_reblogs(query, %{"muting_user" => %User{} = user} = opts) do
- muted_reblogs = opts["reblog_muted_users_ap_ids"] || User.reblog_muted_users_ap_ids(user)
+ defp restrict_muted_reblogs(query, %{muting_user: %User{} = user} = opts) do
+ muted_reblogs = opts[:reblog_muted_users_ap_ids] || User.reblog_muted_users_ap_ids(user)
from(
activity in query,
defp restrict_muted_reblogs(query, _), do: query
- defp restrict_instance(query, %{"instance" => instance}) do
+ defp restrict_instance(query, %{instance: instance}) do
users =
from(
u in User,
defp restrict_instance(query, _), do: query
- defp exclude_poll_votes(query, %{"include_poll_votes" => true}), do: query
+ defp exclude_poll_votes(query, %{include_poll_votes: true}), do: query
defp exclude_poll_votes(query, _) do
if has_named_binding?(query, :object) do
end
end
- defp exclude_invisible_actors(query, %{"invisible_actors" => true}), do: query
+ defp exclude_invisible_actors(query, %{invisible_actors: true}), do: query
defp exclude_invisible_actors(query, _opts) do
invisible_ap_ids =
from([activity] in query, where: activity.actor not in ^invisible_ap_ids)
end
- defp exclude_id(query, %{"exclude_id" => id}) when is_binary(id) do
+ defp exclude_id(query, %{exclude_id: id}) when is_binary(id) do
from(activity in query, where: activity.id != ^id)
end
defp exclude_id(query, _), do: query
- defp maybe_preload_objects(query, %{"skip_preload" => true}), do: query
+ defp maybe_preload_objects(query, %{skip_preload: true}), do: query
defp maybe_preload_objects(query, _) do
query
|> Activity.with_preloaded_object()
end
- defp maybe_preload_bookmarks(query, %{"skip_preload" => true}), do: query
+ defp maybe_preload_bookmarks(query, %{skip_preload: true}), do: query
defp maybe_preload_bookmarks(query, opts) do
query
- |> Activity.with_preloaded_bookmark(opts["user"])
+ |> Activity.with_preloaded_bookmark(opts[:user])
end
- defp maybe_preload_report_notes(query, %{"preload_report_notes" => true}) do
+ defp maybe_preload_report_notes(query, %{preload_report_notes: true}) do
query
|> Activity.with_preloaded_report_notes()
end
defp maybe_preload_report_notes(query, _), do: query
- defp maybe_set_thread_muted_field(query, %{"skip_preload" => true}), do: query
+ defp maybe_set_thread_muted_field(query, %{skip_preload: true}), do: query
defp maybe_set_thread_muted_field(query, opts) do
query
- |> Activity.with_set_thread_muted_field(opts["muting_user"] || opts["user"])
+ |> Activity.with_set_thread_muted_field(opts[:muting_user] || opts[:user])
end
defp maybe_order(query, %{order: :desc}) do
defp maybe_order(query, _), do: query
defp fetch_activities_query_ap_ids_ops(opts) do
- source_user = opts["muting_user"]
+ source_user = opts[:muting_user]
ap_id_relationships = if source_user, do: [:mute, :reblog_mute], else: []
ap_id_relationships =
- ap_id_relationships ++
- if opts["blocking_user"] && opts["blocking_user"] == source_user do
- [:block]
- else
- []
- end
+ if opts[:blocking_user] && opts[:blocking_user] == source_user do
+ [:block | ap_id_relationships]
+ else
+ ap_id_relationships
+ end
preloaded_ap_ids = User.outgoing_relationships_ap_ids(source_user, ap_id_relationships)
- restrict_blocked_opts = Map.merge(%{"blocked_users_ap_ids" => preloaded_ap_ids[:block]}, opts)
- restrict_muted_opts = Map.merge(%{"muted_users_ap_ids" => preloaded_ap_ids[:mute]}, opts)
+ restrict_blocked_opts = Map.merge(%{blocked_users_ap_ids: preloaded_ap_ids[:block]}, opts)
+ restrict_muted_opts = Map.merge(%{muted_users_ap_ids: preloaded_ap_ids[:mute]}, opts)
restrict_muted_reblogs_opts =
- Map.merge(%{"reblog_muted_users_ap_ids" => preloaded_ap_ids[:reblog_mute]}, opts)
+ Map.merge(%{reblog_muted_users_ap_ids: preloaded_ap_ids[:reblog_mute]}, opts)
{restrict_blocked_opts, restrict_muted_opts, restrict_muted_reblogs_opts}
end
|> maybe_preload_report_notes(opts)
|> maybe_set_thread_muted_field(opts)
|> maybe_order(opts)
- |> restrict_recipients(recipients, opts["user"])
+ |> restrict_recipients(recipients, opts[:user])
|> restrict_replies(opts)
|> restrict_tag(opts)
|> restrict_tag_reject(opts)
end
def fetch_activities(recipients, opts \\ %{}, pagination \\ :keyset) do
- list_memberships = Pleroma.List.memberships(opts["user"])
+ list_memberships = Pleroma.List.memberships(opts[:user])
fetch_activities_query(recipients ++ list_memberships, opts)
|> Pagination.fetch_paginated(opts, pagination)
|> Enum.reverse()
- |> maybe_update_cc(list_memberships, opts["user"])
+ |> maybe_update_cc(list_memberships, opts[:user])
end
@doc """
|> select([_like, object, activity], %{activity | object: object})
|> order_by([like, _, _], desc_nulls_last: like.id)
|> Pagination.fetch_paginated(
- Map.merge(params, %{"skip_order" => true}),
+ Map.merge(params, %{skip_order: true}),
pagination,
:object_activity
)
end
- defp maybe_update_cc(activities, list_memberships, %User{ap_id: user_ap_id})
- when is_list(list_memberships) and length(list_memberships) > 0 do
+ defp maybe_update_cc(activities, [_ | _] = list_memberships, %User{ap_id: user_ap_id}) do
Enum.map(activities, fn
- %{data: %{"bcc" => bcc}} = activity when is_list(bcc) and length(bcc) > 0 ->
+ %{data: %{"bcc" => [_ | _] = bcc}} = activity ->
if Enum.any?(bcc, &(&1 in list_memberships)) do
update_in(activity.data["cc"], &[user_ap_id | &1])
else
defp maybe_update_cc(activities, _, _), do: activities
- def fetch_activities_bounded_query(query, recipients, recipients_with_public) do
+ defp fetch_activities_bounded_query(query, recipients, recipients_with_public) do
from(activity in query,
where:
fragment("? && ?", activity.recipients, ^recipients) or
%{"type" => "Emoji"} -> true
_ -> false
end)
- |> Enum.reduce(%{}, fn %{"icon" => %{"url" => url}, "name" => name}, acc ->
- Map.put(acc, String.trim(name, ":"), url)
+ |> Map.new(fn %{"icon" => %{"url" => url}, "name" => name} ->
+ {String.trim(name, ":"), url}
end)
locked = data["manuallyApprovesFollowers"] || false
}
# nickname can be nil because of virtual actors
- user_data =
- if data["preferredUsername"] do
- Map.put(
- user_data,
- :nickname,
- "#{data["preferredUsername"]}@#{URI.parse(data["id"]).host}"
- )
- else
- Map.put(user_data, :nickname, nil)
- end
-
- {:ok, user_data}
+ if data["preferredUsername"] do
+ Map.put(
+ user_data,
+ :nickname,
+ "#{data["preferredUsername"]}@#{URI.parse(data["id"]).host}"
+ )
+ else
+ Map.put(user_data, :nickname, nil)
+ end
end
def fetch_follow_information_for_user(user) do
defp collection_private(_data), do: {:ok, true}
def user_data_from_user_object(data) do
- with {:ok, data} <- MRF.filter(data),
- {:ok, data} <- object_to_user_data(data) do
- {:ok, data}
+ with {:ok, data} <- MRF.filter(data) do
+ {:ok, object_to_user_data(data)}
else
e -> {:error, e}
end
def fetch_and_prepare_user_from_ap_id(ap_id) do
with {:ok, data} <- Fetcher.fetch_and_contain_remote_object_from_id(ap_id),
- {:ok, data} <- user_data_from_user_object(data),
- data <- maybe_update_follow_information(data) do
- {:ok, data}
+ {:ok, data} <- user_data_from_user_object(data) do
+ {:ok, maybe_update_follow_information(data)}
else
- {:error, "Object has been deleted"} = e ->
+ {:error, "Object has been deleted" = e} ->
Logger.debug("Could not decode user at fetch #{ap_id}, #{inspect(e)}")
{:error, e}
- e ->
+ {:error, e} ->
Logger.error("Could not decode user at fetch #{ap_id}, #{inspect(e)}")
{:error, e}
end
|> Repo.insert()
|> User.set_cache()
end
- else
- e -> {:error, e}
end
end
end
end
# filter out broken threads
- def contain_broken_threads(%Activity{} = activity, %User{} = user) do
+ defp contain_broken_threads(%Activity{} = activity, %User{} = user) do
entire_thread_visible_for_user?(activity, user)
end
def fetch_direct_messages_query do
Activity
- |> restrict_type(%{"type" => "Create"})
+ |> restrict_type(%{type: "Create"})
|> restrict_visibility(%{visibility: "direct"})
|> order_by([activity], asc: activity.id)
end
activities =
if params["max_id"] do
ActivityPub.fetch_user_activities(user, for_user, %{
- "max_id" => params["max_id"],
+ max_id: params["max_id"],
# This is a hack because postgres generates inefficient queries when filtering by
# 'Answer', poll votes will be hidden by the visibility filter in this case anyway
- "include_poll_votes" => true,
- "limit" => 10
+ include_poll_votes: true,
+ limit: 10
})
else
ActivityPub.fetch_user_activities(user, for_user, %{
- "limit" => 10,
- "include_poll_votes" => true
+ limit: 10,
+ include_poll_votes: true
})
end
activities =
if params["max_id"] do
ActivityPub.fetch_activities([user.ap_id | User.following(user)], %{
- "max_id" => params["max_id"],
- "limit" => 10
+ max_id: params["max_id"],
+ limit: 10
})
else
- ActivityPub.fetch_activities([user.ap_id | User.following(user)], %{"limit" => 10})
+ ActivityPub.fetch_activities([user.ap_id | User.following(user)], %{limit: 10})
end
conn
Inserts a full object if it is contained in an activity.
"""
def insert_full_object(%{"object" => %{"type" => type} = object_data} = map)
- when is_map(object_data) and type in @supported_object_types do
+ when type in @supported_object_types do
with {:ok, object} <- Object.create(object_data) do
map = Map.put(map, "object", object.data["id"])
def get_reports(params, page, page_size) do
params =
params
- |> Map.new(fn {key, value} -> {to_string(key), value} end)
- |> Map.put("type", "Flag")
- |> Map.put("skip_preload", true)
- |> Map.put("preload_report_notes", true)
- |> Map.put("total", true)
- |> Map.put("limit", page_size)
- |> Map.put("offset", (page - 1) * page_size)
+ |> Map.put(:type, "Flag")
+ |> Map.put(:skip_preload, true)
+ |> Map.put(:preload_report_notes, true)
+ |> Map.put(:total, true)
+ |> Map.put(:limit, page_size)
+ |> Map.put(:offset, (page - 1) * page_size)
ActivityPub.fetch_activities([], params, :offset)
end
activities =
ActivityPub.fetch_statuses(nil, %{
- "instance" => instance,
- "limit" => page_size,
- "offset" => (page - 1) * page_size,
- "exclude_reblogs" => !with_reblogs && "true"
+ instance: instance,
+ limit: page_size,
+ offset: (page - 1) * page_size,
+ exclude_reblogs: not with_reblogs
})
conn
activities =
ActivityPub.fetch_user_activities(user, nil, %{
- "limit" => page_size,
- "godmode" => godmode,
- "exclude_reblogs" => !with_reblogs && "true"
+ limit: page_size,
+ godmode: godmode,
+ exclude_reblogs: not with_reblogs
})
conn
def index(%{assigns: %{user: _admin}} = conn, params) do
activities =
ActivityPub.fetch_statuses(nil, %{
- "godmode" => params.godmode,
- "local_only" => params.local_only,
- "limit" => params.page_size,
- "offset" => (params.page - 1) * params.page_size,
- "exclude_reblogs" => not params.with_reblogs
+ godmode: params.godmode,
+ local_only: params.local_only,
+ limit: params.page_size,
+ offset: (params.page - 1) * params.page_size,
+ exclude_reblogs: not params.with_reblogs
})
render(conn, "index.json", activities: activities, as: :activity)
%{
reports:
reports[:items]
- |> Enum.map(&Report.extract_report_info(&1))
+ |> Enum.map(&Report.extract_report_info/1)
|> Enum.map(&render(__MODULE__, "show.json", &1))
|> Enum.reverse(),
total: reports[:total]
end
def assign_account_by_id(conn, _) do
- # TODO: use `conn.params[:id]` only after moving to OpenAPI
- case Pleroma.User.get_cached_by_id(conn.params[:id] || conn.params["id"]) do
+ case Pleroma.User.get_cached_by_id(conn.params.id) do
%Pleroma.User{} = account -> assign(conn, :account, account)
nil -> Pleroma.Web.MastodonAPI.FallbackController.call(conn, {:error, :not_found}) |> halt()
end
{format, tag} = parse_tag(raw_tag)
activities =
- %{"type" => ["Create"], "tag" => tag}
- |> put_if_exist("max_id", params["max_id"])
+ %{type: ["Create"], tag: tag}
+ |> put_if_exist(:max_id, params["max_id"])
|> ActivityPub.fetch_public_activities()
conn
with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)} do
activities =
%{
- "type" => ["Create"],
- "actor_id" => user.ap_id
+ type: ["Create"],
+ actor_id: user.ap_id
}
- |> put_if_exist("max_id", params["max_id"])
+ |> put_if_exist(:max_id, params["max_id"])
|> ActivityPub.fetch_public_or_unlisted_activities()
conn
params =
params
|> Map.delete(:tagged)
- |> Enum.filter(&(not is_nil(&1)))
- |> Map.new(fn {key, value} -> {to_string(key), value} end)
- |> Map.put("tag", params[:tagged])
+ |> Map.put(:tag, params[:tagged])
activities = ActivityPub.fetch_user_activities(user, reading_user, params)
@doc "GET /api/v1/conversations"
def index(%{assigns: %{user: user}} = conn, params) do
- params = stringify_pagination_params(params)
participations = Participation.for_user_with_last_activity_id(user, params)
conn
render(conn, "participation.json", participation: participation, for: user)
end
end
-
- defp stringify_pagination_params(params) do
- atom_keys =
- Pleroma.Pagination.page_keys()
- |> Enum.map(&String.to_atom(&1))
-
- str_keys =
- params
- |> Map.take(atom_keys)
- |> Enum.map(fn {key, value} -> {to_string(key), value} end)
- |> Enum.into(%{})
-
- params
- |> Map.delete(atom_keys)
- |> Map.merge(str_keys)
- end
end
with %Activity{} = activity <- Activity.get_by_id(id) do
activities =
ActivityPub.fetch_activities_for_context(activity.data["context"], %{
- "blocking_user" => user,
- "user" => user,
- "exclude_id" => activity.id
+ blocking_user: user,
+ user: user,
+ exclude_id: activity.id
})
render(conn, "context.json", activity: activity, activities: activities, user: user)
@doc "GET /api/v1/favourites"
def favourites(%{assigns: %{user: %User{} = user}} = conn, params) do
- params =
- params
- |> Map.new(fn {key, value} -> {to_string(key), value} end)
- |> Map.take(Pleroma.Pagination.page_keys())
-
activities = ActivityPub.fetch_favourites(user, params)
conn
def home(%{assigns: %{user: user}} = conn, params) do
params =
params
- |> Map.new(fn {key, value} -> {to_string(key), value} end)
- |> Map.put("type", ["Create", "Announce"])
- |> Map.put("blocking_user", user)
- |> Map.put("muting_user", user)
- |> Map.put("reply_filtering_user", user)
- |> Map.put("user", user)
+ |> Map.put(:type, ["Create", "Announce"])
+ |> Map.put(:blocking_user, user)
+ |> Map.put(:muting_user, user)
+ |> Map.put(:reply_filtering_user, user)
+ |> Map.put(:user, user)
recipients = [user.ap_id | User.following(user)]
def direct(%{assigns: %{user: user}} = conn, params) do
params =
params
- |> Map.new(fn {key, value} -> {to_string(key), value} end)
- |> Map.put("type", "Create")
- |> Map.put("blocking_user", user)
- |> Map.put("user", user)
+ |> Map.put(:type, "Create")
+ |> Map.put(:blocking_user, user)
+ |> Map.put(:user, user)
|> Map.put(:visibility, "direct")
activities =
# GET /api/v1/timelines/public
def public(%{assigns: %{user: user}} = conn, params) do
- params = Map.new(params, fn {key, value} -> {to_string(key), value} end)
-
- local_only = params["local"]
+ local_only = params[:local]
cfg_key =
if local_only do
else
activities =
params
- |> Map.put("type", ["Create"])
- |> Map.put("local_only", local_only)
- |> Map.put("blocking_user", user)
- |> Map.put("muting_user", user)
- |> Map.put("reply_filtering_user", user)
+ |> Map.put(:type, ["Create"])
+ |> Map.put(:local_only, local_only)
+ |> Map.put(:blocking_user, user)
+ |> Map.put(:muting_user, user)
+ |> Map.put(:reply_filtering_user, user)
|> ActivityPub.fetch_public_activities()
conn
defp hashtag_fetching(params, user, local_only) do
tags =
- [params["tag"], params["any"]]
+ [params[:tag], params[:any]]
|> List.flatten()
|> Enum.uniq()
- |> Enum.filter(& &1)
- |> Enum.map(&String.downcase(&1))
+ |> Enum.reject(&is_nil/1)
+ |> Enum.map(&String.downcase/1)
tag_all =
params
- |> Map.get("all", [])
- |> Enum.map(&String.downcase(&1))
+ |> Map.get(:all, [])
+ |> Enum.map(&String.downcase/1)
tag_reject =
params
- |> Map.get("none", [])
- |> Enum.map(&String.downcase(&1))
+ |> Map.get(:none, [])
+ |> Enum.map(&String.downcase/1)
_activities =
params
- |> Map.put("type", "Create")
- |> Map.put("local_only", local_only)
- |> Map.put("blocking_user", user)
- |> Map.put("muting_user", user)
- |> Map.put("user", user)
- |> Map.put("tag", tags)
- |> Map.put("tag_all", tag_all)
- |> Map.put("tag_reject", tag_reject)
+ |> Map.put(:type, "Create")
+ |> Map.put(:local_only, local_only)
+ |> Map.put(:blocking_user, user)
+ |> Map.put(:muting_user, user)
+ |> Map.put(:user, user)
+ |> Map.put(:tag, tags)
+ |> Map.put(:tag_all, tag_all)
+ |> Map.put(:tag_reject, tag_reject)
|> ActivityPub.fetch_public_activities()
end
# GET /api/v1/timelines/tag/:tag
def hashtag(%{assigns: %{user: user}} = conn, params) do
- params = Map.new(params, fn {key, value} -> {to_string(key), value} end)
- local_only = params["local"]
+ local_only = params[:local]
activities = hashtag_fetching(params, user, local_only)
conn
last_activity_id =
with nil <- participation.last_activity_id do
ActivityPub.fetch_latest_activity_id_for_context(participation.conversation.ap_id, %{
- "user" => user,
- "blocking_user" => user
+ user: user,
+ blocking_user: user
})
end
def favourites(%{assigns: %{user: for_user, account: user}} = conn, params) do
params =
params
- |> Map.new(fn {key, value} -> {to_string(key), value} end)
- |> Map.put("type", "Create")
- |> Map.put("favorited_by", user.ap_id)
- |> Map.put("blocking_user", for_user)
+ |> Map.put(:type, "Create")
+ |> Map.put(:favorited_by, user.ap_id)
+ |> Map.put(:blocking_user, for_user)
recipients =
if for_user do
Participation.get(participation_id, preload: [:conversation]) do
params =
params
- |> Map.new(fn {key, value} -> {to_string(key), value} end)
- |> Map.put("blocking_user", user)
- |> Map.put("muting_user", user)
- |> Map.put("user", user)
+ |> Map.put(:blocking_user, user)
+ |> Map.put(:muting_user, user)
+ |> Map.put(:user, user)
activities =
participation.conversation.ap_id
|> ActivityPub.fetch_activities_for_context_query(params)
- |> Pleroma.Pagination.fetch_paginated(Map.put(params, "total", false))
+ |> Pleroma.Pagination.fetch_paginated(Map.put(params, :total, false))
|> Enum.reverse()
conn
def index(%{assigns: %{user: reading_user}} = conn, %{id: id} = params) do
with %User{} = user <- User.get_cached_by_nickname_or_id(id, for: reading_user) do
- params =
- params
- |> Map.new(fn {key, value} -> {to_string(key), value} end)
- |> Map.put("type", ["Listen"])
+ params = Map.put(params, :type, ["Listen"])
activities = ActivityPub.fetch_user_abstract_activities(user, reading_user, params)
%User{} = user ->
meta = Metadata.build_tags(%{user: user})
+ params =
+ params
+ |> Map.take(@page_keys)
+ |> Map.new(fn {k, v} -> {String.to_existing_atom(k), v} end)
+
timeline =
- ActivityPub.fetch_user_activities(user, nil, Map.take(params, @page_keys))
+ user
+ |> ActivityPub.fetch_user_activities(nil, params)
|> Enum.map(&represent/1)
prev_page_id =
id = Enum.at(notes, 2).id |> Integer.to_string()
%{total: total, items: paginated} =
- Pagination.fetch_paginated(Object, %{"min_id" => id, "total" => true})
+ Pagination.fetch_paginated(Object, %{min_id: id, total: true})
assert length(paginated) == 2
assert total == 5
id = Enum.at(notes, 2).id |> Integer.to_string()
%{total: total, items: paginated} =
- Pagination.fetch_paginated(Object, %{"since_id" => id, "total" => true})
+ Pagination.fetch_paginated(Object, %{since_id: id, total: true})
assert length(paginated) == 2
assert total == 5
id = Enum.at(notes, 1).id |> Integer.to_string()
%{total: total, items: paginated} =
- Pagination.fetch_paginated(Object, %{"max_id" => id, "total" => true})
+ Pagination.fetch_paginated(Object, %{max_id: id, total: true})
assert length(paginated) == 1
assert total == 5
test "paginates by min_id & limit", %{notes: notes} do
id = Enum.at(notes, 2).id |> Integer.to_string()
- paginated = Pagination.fetch_paginated(Object, %{"min_id" => id, "limit" => 1})
+ paginated = Pagination.fetch_paginated(Object, %{min_id: id, limit: 1})
assert length(paginated) == 1
end
end
test "paginates by limit" do
- paginated = Pagination.fetch_paginated(Object, %{"limit" => 2}, :offset)
+ paginated = Pagination.fetch_paginated(Object, %{limit: 2}, :offset)
assert length(paginated) == 2
end
test "paginates by limit & offset" do
- paginated = Pagination.fetch_paginated(Object, %{"limit" => 2, "offset" => 4}, :offset)
+ paginated = Pagination.fetch_paginated(Object, %{limit: 2, offset: 4}, :offset)
assert length(paginated) == 1
end
[undo_activity] =
ActivityPub.fetch_activities([], %{
- "type" => "Undo",
- "actor_id" => follower_id,
- "limit" => 1,
- "skip_preload" => true,
- "invisible_actors" => true
+ type: "Undo",
+ actor_id: follower_id,
+ limit: 1,
+ skip_preload: true,
+ invisible_actors: true
})
assert undo_activity.data["type"] == "Undo"
assert [%{activity | thread_muted?: CommonAPI.thread_muted?(user2, activity)}] ==
ActivityPub.fetch_activities([user2.ap_id | User.following(user2)], %{
- "user" => user2
+ user: user2
})
{:ok, _user} = User.deactivate(user)
assert [] ==
ActivityPub.fetch_activities([user2.ap_id | User.following(user2)], %{
- "user" => user2
+ user: user2
})
end
end
{:ok, private_activity} = CommonAPI.post(user, %{status: ".", visibility: "private"})
- activities =
- ActivityPub.fetch_activities([], %{:visibility => "direct", "actor_id" => user.ap_id})
+ activities = ActivityPub.fetch_activities([], %{visibility: "direct", actor_id: user.ap_id})
assert activities == [direct_activity]
activities =
- ActivityPub.fetch_activities([], %{:visibility => "unlisted", "actor_id" => user.ap_id})
+ ActivityPub.fetch_activities([], %{visibility: "unlisted", actor_id: user.ap_id})
assert activities == [unlisted_activity]
activities =
- ActivityPub.fetch_activities([], %{:visibility => "private", "actor_id" => user.ap_id})
+ ActivityPub.fetch_activities([], %{visibility: "private", actor_id: user.ap_id})
assert activities == [private_activity]
- activities =
- ActivityPub.fetch_activities([], %{:visibility => "public", "actor_id" => user.ap_id})
+ activities = ActivityPub.fetch_activities([], %{visibility: "public", actor_id: user.ap_id})
assert activities == [public_activity]
activities =
ActivityPub.fetch_activities([], %{
- :visibility => ~w[private public],
- "actor_id" => user.ap_id
+ visibility: ~w[private public],
+ actor_id: user.ap_id
})
assert activities == [public_activity, private_activity]
activities =
ActivityPub.fetch_activities([], %{
- "exclude_visibilities" => "direct",
- "actor_id" => user.ap_id
+ exclude_visibilities: "direct",
+ actor_id: user.ap_id
})
assert public_activity in activities
activities =
ActivityPub.fetch_activities([], %{
- "exclude_visibilities" => "unlisted",
- "actor_id" => user.ap_id
+ exclude_visibilities: "unlisted",
+ actor_id: user.ap_id
})
assert public_activity in activities
activities =
ActivityPub.fetch_activities([], %{
- "exclude_visibilities" => "private",
- "actor_id" => user.ap_id
+ exclude_visibilities: "private",
+ actor_id: user.ap_id
})
assert public_activity in activities
activities =
ActivityPub.fetch_activities([], %{
- "exclude_visibilities" => "public",
- "actor_id" => user.ap_id
+ exclude_visibilities: "public",
+ actor_id: user.ap_id
})
refute public_activity in activities
{:ok, status_two} = CommonAPI.post(user, %{status: ". #essais"})
{:ok, status_three} = CommonAPI.post(user, %{status: ". #test #reject"})
- fetch_one = ActivityPub.fetch_activities([], %{"type" => "Create", "tag" => "test"})
+ fetch_one = ActivityPub.fetch_activities([], %{type: "Create", tag: "test"})
- fetch_two =
- ActivityPub.fetch_activities([], %{"type" => "Create", "tag" => ["test", "essais"]})
+ fetch_two = ActivityPub.fetch_activities([], %{type: "Create", tag: ["test", "essais"]})
fetch_three =
ActivityPub.fetch_activities([], %{
- "type" => "Create",
- "tag" => ["test", "essais"],
- "tag_reject" => ["reject"]
+ type: "Create",
+ tag: ["test", "essais"],
+ tag_reject: ["reject"]
})
fetch_four =
ActivityPub.fetch_activities([], %{
- "type" => "Create",
- "tag" => ["test"],
- "tag_all" => ["test", "reject"]
+ type: "Create",
+ tag: ["test"],
+ tag_all: ["test", "reject"]
})
assert fetch_one == [status_one, status_three]
_listen_activity_2 = insert(:listen)
_listen_activity_3 = insert(:listen)
- timeline = ActivityPub.fetch_activities([], %{"type" => ["Listen"]})
+ timeline = ActivityPub.fetch_activities([], %{type: ["Listen"]})
assert length(timeline) == 3
end
{:ok, _user_relationship} = User.block(user, %{ap_id: activity_five.data["actor"]})
- activities = ActivityPub.fetch_activities_for_context("2hu", %{"blocking_user" => user})
+ activities = ActivityPub.fetch_activities_for_context("2hu", %{blocking_user: user})
assert activities == [activity_two, activity]
end
end
booster = insert(:user)
{:ok, _user_relationship} = User.block(user, %{ap_id: activity_one.data["actor"]})
- activities =
- ActivityPub.fetch_activities([], %{"blocking_user" => user, "skip_preload" => true})
+ activities = ActivityPub.fetch_activities([], %{blocking_user: user, skip_preload: true})
assert Enum.member?(activities, activity_two)
assert Enum.member?(activities, activity_three)
{:ok, _user_block} = User.unblock(user, %{ap_id: activity_one.data["actor"]})
- activities =
- ActivityPub.fetch_activities([], %{"blocking_user" => user, "skip_preload" => true})
+ activities = ActivityPub.fetch_activities([], %{blocking_user: user, skip_preload: true})
assert Enum.member?(activities, activity_two)
assert Enum.member?(activities, activity_three)
%Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id)
activity_three = Activity.get_by_id(activity_three.id)
- activities =
- ActivityPub.fetch_activities([], %{"blocking_user" => user, "skip_preload" => true})
+ activities = ActivityPub.fetch_activities([], %{blocking_user: user, skip_preload: true})
assert Enum.member?(activities, activity_two)
refute Enum.member?(activities, activity_three)
refute Enum.member?(activities, boost_activity)
assert Enum.member?(activities, activity_one)
- activities =
- ActivityPub.fetch_activities([], %{"blocking_user" => nil, "skip_preload" => true})
+ activities = ActivityPub.fetch_activities([], %{blocking_user: nil, skip_preload: true})
assert Enum.member?(activities, activity_two)
assert Enum.member?(activities, activity_three)
{:ok, activity_four} = CommonAPI.post(blockee, %{status: "hey! @#{blocker.nickname}"})
- activities = ActivityPub.fetch_activities([], %{"blocking_user" => blocker})
+ activities = ActivityPub.fetch_activities([], %{blocking_user: blocker})
assert Enum.member?(activities, activity_one)
refute Enum.member?(activities, activity_two)
{:ok, activity_three} = CommonAPI.repeat(activity_two.id, friend)
activities =
- ActivityPub.fetch_activities([], %{"blocking_user" => blocker})
+ ActivityPub.fetch_activities([], %{blocking_user: blocker})
|> Enum.map(fn act -> act.id end)
assert Enum.member?(activities, activity_one.id)
user = insert(:user)
{:ok, user} = User.block_domain(user, domain)
- activities =
- ActivityPub.fetch_activities([], %{"blocking_user" => user, "skip_preload" => true})
+ activities = ActivityPub.fetch_activities([], %{blocking_user: user, skip_preload: true})
refute activity in activities
ActivityPub.follow(user, 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})
refute repeat_activity in activities
end
note = insert(:note, %{data: %{"actor" => domain_user.ap_id}})
activity = insert(:note_activity, %{note: note})
- activities =
- ActivityPub.fetch_activities([], %{"blocking_user" => blocker, "skip_preload" => true})
+ activities = ActivityPub.fetch_activities([], %{blocking_user: blocker, skip_preload: true})
assert activity in activities
bad_activity = insert(:note_activity, %{note: bad_note})
{:ok, repeat_activity} = CommonAPI.repeat(bad_activity.id, domain_user)
- activities =
- ActivityPub.fetch_activities([], %{"blocking_user" => blocker, "skip_preload" => true})
+ activities = ActivityPub.fetch_activities([], %{blocking_user: blocker, skip_preload: true})
refute repeat_activity in activities
end
activity_one_actor = User.get_by_ap_id(activity_one.data["actor"])
{:ok, _user_relationships} = User.mute(user, activity_one_actor)
- activities =
- ActivityPub.fetch_activities([], %{"muting_user" => user, "skip_preload" => true})
+ activities = ActivityPub.fetch_activities([], %{muting_user: user, skip_preload: true})
assert Enum.member?(activities, activity_two)
assert Enum.member?(activities, activity_three)
# Calling with 'with_muted' will deliver muted activities, too.
activities =
ActivityPub.fetch_activities([], %{
- "muting_user" => user,
- "with_muted" => true,
- "skip_preload" => true
+ muting_user: user,
+ with_muted: true,
+ skip_preload: true
})
assert Enum.member?(activities, activity_two)
{:ok, _user_mute} = User.unmute(user, activity_one_actor)
- activities =
- ActivityPub.fetch_activities([], %{"muting_user" => user, "skip_preload" => true})
+ activities = ActivityPub.fetch_activities([], %{muting_user: user, skip_preload: true})
assert Enum.member?(activities, activity_two)
assert Enum.member?(activities, activity_three)
%Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id)
activity_three = Activity.get_by_id(activity_three.id)
- activities =
- ActivityPub.fetch_activities([], %{"muting_user" => user, "skip_preload" => true})
+ activities = ActivityPub.fetch_activities([], %{muting_user: user, skip_preload: true})
assert Enum.member?(activities, activity_two)
refute Enum.member?(activities, activity_three)
refute Enum.member?(activities, boost_activity)
assert Enum.member?(activities, activity_one)
- activities = ActivityPub.fetch_activities([], %{"muting_user" => nil, "skip_preload" => true})
+ activities = ActivityPub.fetch_activities([], %{muting_user: nil, skip_preload: true})
assert Enum.member?(activities, activity_two)
assert Enum.member?(activities, activity_three)
{:ok, _activity_two} = CommonAPI.add_mute(user, activity_two)
- assert [_activity_one] = ActivityPub.fetch_activities([], %{"muting_user" => user})
+ assert [_activity_one] = ActivityPub.fetch_activities([], %{muting_user: user})
end
test "returns thread muted activities when with_muted is set" do
{:ok, _activity_two} = CommonAPI.add_mute(user, activity_two)
assert [_activity_two, _activity_one] =
- ActivityPub.fetch_activities([], %{"muting_user" => user, "with_muted" => true})
+ ActivityPub.fetch_activities([], %{muting_user: user, with_muted: true})
end
test "does include announces on request" do
{:ok, expected_activity} = ActivityBuilder.insert(%{"type" => "Create"}, %{:user => user})
{:ok, _} = ActivityBuilder.insert(%{"type" => "Announce"}, %{:user => user})
- [activity] = ActivityPub.fetch_user_activities(user, nil, %{"exclude_reblogs" => "true"})
+ [activity] = ActivityPub.fetch_user_activities(user, nil, %{exclude_reblogs: true})
assert activity == expected_activity
end
expected_activities = ActivityBuilder.insert_list(10)
since_id = List.last(activities).id
- activities = ActivityPub.fetch_public_activities(%{"since_id" => since_id})
+ activities = ActivityPub.fetch_public_activities(%{since_id: since_id})
assert collect_ids(activities) == collect_ids(expected_activities)
assert length(activities) == 10
|> ActivityBuilder.insert_list()
|> List.first()
- activities = ActivityPub.fetch_public_activities(%{"max_id" => max_id})
+ activities = ActivityPub.fetch_public_activities(%{max_id: max_id})
assert length(activities) == 20
assert collect_ids(activities) == collect_ids(expected_activities)
later_activities = ActivityBuilder.insert_list(10)
- activities =
- ActivityPub.fetch_public_activities(%{"page" => "2", "page_size" => "20"}, :offset)
+ activities = ActivityPub.fetch_public_activities(%{page: "2", page_size: "20"}, :offset)
assert length(activities) == 20
{:ok, activity} = CommonAPI.repeat(activity.id, booster)
- activities = ActivityPub.fetch_activities([], %{"muting_user" => user})
+ activities = ActivityPub.fetch_activities([], %{muting_user: user})
refute Enum.any?(activities, fn %{id: id} -> id == activity.id end)
end
{:ok, activity} = CommonAPI.repeat(activity.id, booster)
- activities = ActivityPub.fetch_activities([], %{"muting_user" => user})
+ activities = ActivityPub.fetch_activities([], %{muting_user: user})
assert Enum.any?(activities, fn %{id: id} -> id == activity.id end)
end
assert length(activities) == 3
activities =
- ActivityPub.fetch_activities([user1.ap_id | User.following(user1)], %{"user" => user1})
+ ActivityPub.fetch_activities([user1.ap_id | User.following(user1)], %{user: user1})
|> Enum.map(fn a -> a.id end)
assert [public_activity.id, private_activity_1.id] == activities
CommonAPI.pin(activity_three.id, user)
user = refresh_record(user)
- activities = ActivityPub.fetch_user_activities(user, nil, %{"pinned" => "true"})
+ activities = ActivityPub.fetch_user_activities(user, nil, %{pinned: true})
assert 3 = length(activities)
end
activity = Repo.preload(activity, :bookmark)
activity = %Activity{activity | thread_muted?: !!activity.thread_muted?}
- assert ActivityPub.fetch_activities([], %{"user" => user}) == [activity]
+ assert ActivityPub.fetch_activities([], %{user: user}) == [activity]
end
def data_uri do
assert Enum.map(result, & &1.id) == [a1.id, a5.id, a3.id, a4.id]
- result = ActivityPub.fetch_favourites(user, %{"limit" => 2})
+ result = ActivityPub.fetch_favourites(user, %{limit: 2})
assert Enum.map(result, & &1.id) == [a1.id, a5.id]
end
end
{:ok, _reply} = CommonAPI.post(user, %{status: "yeah", in_reply_to_status_id: activity.id})
- [result] = ActivityPub.fetch_public_activities(%{"exclude_replies" => "true"})
+ [result] = ActivityPub.fetch_public_activities(%{exclude_replies: true})
assert result.id == activity.id
test "public timeline", %{users: %{u1: user}} do
activities_ids =
%{}
- |> Map.put("type", ["Create", "Announce"])
- |> Map.put("local_only", false)
- |> Map.put("blocking_user", user)
- |> Map.put("muting_user", user)
- |> Map.put("reply_filtering_user", user)
+ |> Map.put(:type, ["Create", "Announce"])
+ |> Map.put(:local_only, false)
+ |> Map.put(:blocking_user, user)
+ |> Map.put(:muting_user, user)
+ |> Map.put(:reply_filtering_user, user)
|> ActivityPub.fetch_public_activities()
|> Enum.map(& &1.id)
} do
activities_ids =
%{}
- |> Map.put("type", ["Create", "Announce"])
- |> Map.put("local_only", false)
- |> Map.put("blocking_user", user)
- |> Map.put("muting_user", user)
- |> Map.put("reply_visibility", "following")
- |> Map.put("reply_filtering_user", user)
+ |> Map.put(:type, ["Create", "Announce"])
+ |> Map.put(:local_only, false)
+ |> Map.put(:blocking_user, user)
+ |> Map.put(:muting_user, user)
+ |> Map.put(:reply_visibility, "following")
+ |> Map.put(:reply_filtering_user, user)
|> ActivityPub.fetch_public_activities()
|> Enum.map(& &1.id)
} do
activities_ids =
%{}
- |> Map.put("type", ["Create", "Announce"])
- |> Map.put("local_only", false)
- |> Map.put("blocking_user", user)
- |> Map.put("muting_user", user)
- |> Map.put("reply_visibility", "self")
- |> Map.put("reply_filtering_user", user)
+ |> Map.put(:type, ["Create", "Announce"])
+ |> Map.put(:local_only, false)
+ |> Map.put(:blocking_user, user)
+ |> Map.put(:muting_user, user)
+ |> Map.put(:reply_visibility, "self")
+ |> Map.put(:reply_filtering_user, user)
|> ActivityPub.fetch_public_activities()
|> Enum.map(& &1.id)
} do
params =
%{}
- |> Map.put("type", ["Create", "Announce"])
- |> Map.put("blocking_user", user)
- |> Map.put("muting_user", user)
- |> Map.put("user", user)
- |> Map.put("reply_filtering_user", user)
+ |> Map.put(:type, ["Create", "Announce"])
+ |> Map.put(:blocking_user, user)
+ |> Map.put(:muting_user, user)
+ |> Map.put(:user, user)
+ |> Map.put(:reply_filtering_user, user)
activities_ids =
ActivityPub.fetch_activities([user.ap_id | User.following(user)], params)
} do
params =
%{}
- |> Map.put("type", ["Create", "Announce"])
- |> Map.put("blocking_user", user)
- |> Map.put("muting_user", user)
- |> Map.put("user", user)
- |> Map.put("reply_visibility", "following")
- |> Map.put("reply_filtering_user", user)
+ |> Map.put(:type, ["Create", "Announce"])
+ |> Map.put(:blocking_user, user)
+ |> Map.put(:muting_user, user)
+ |> Map.put(:user, user)
+ |> Map.put(:reply_visibility, "following")
+ |> Map.put(:reply_filtering_user, user)
activities_ids =
ActivityPub.fetch_activities([user.ap_id | User.following(user)], params)
} do
params =
%{}
- |> Map.put("type", ["Create", "Announce"])
- |> Map.put("blocking_user", user)
- |> Map.put("muting_user", user)
- |> Map.put("user", user)
- |> Map.put("reply_visibility", "self")
- |> Map.put("reply_filtering_user", user)
+ |> Map.put(:type, ["Create", "Announce"])
+ |> Map.put(:blocking_user, user)
+ |> Map.put(:muting_user, user)
+ |> Map.put(:user, user)
+ |> Map.put(:reply_visibility, "self")
+ |> Map.put(:reply_filtering_user, user)
activities_ids =
ActivityPub.fetch_activities([user.ap_id | User.following(user)], params)
test "public timeline", %{users: %{u1: user}} do
activities_ids =
%{}
- |> Map.put("type", ["Create", "Announce"])
- |> Map.put("local_only", false)
- |> Map.put("blocking_user", user)
- |> Map.put("muting_user", user)
- |> Map.put("user", user)
+ |> Map.put(:type, ["Create", "Announce"])
+ |> Map.put(:local_only, false)
+ |> Map.put(:blocking_user, user)
+ |> Map.put(:muting_user, user)
+ |> Map.put(:user, user)
|> ActivityPub.fetch_public_activities()
|> Enum.map(& &1.id)
test "public timeline with default reply_visibility `following`", %{users: %{u1: user}} do
activities_ids =
%{}
- |> Map.put("type", ["Create", "Announce"])
- |> Map.put("local_only", false)
- |> Map.put("blocking_user", user)
- |> Map.put("muting_user", user)
- |> Map.put("reply_visibility", "following")
- |> Map.put("reply_filtering_user", user)
- |> Map.put("user", user)
+ |> Map.put(:type, ["Create", "Announce"])
+ |> Map.put(:local_only, false)
+ |> Map.put(:blocking_user, user)
+ |> Map.put(:muting_user, user)
+ |> Map.put(:reply_visibility, "following")
+ |> Map.put(:reply_filtering_user, user)
+ |> Map.put(:user, user)
|> ActivityPub.fetch_public_activities()
|> Enum.map(& &1.id)
test "public timeline with default reply_visibility `self`", %{users: %{u1: user}} do
activities_ids =
%{}
- |> Map.put("type", ["Create", "Announce"])
- |> Map.put("local_only", false)
- |> Map.put("blocking_user", user)
- |> Map.put("muting_user", user)
- |> Map.put("reply_visibility", "self")
- |> Map.put("reply_filtering_user", user)
- |> Map.put("user", user)
+ |> Map.put(:type, ["Create", "Announce"])
+ |> Map.put(:local_only, false)
+ |> Map.put(:blocking_user, user)
+ |> Map.put(:muting_user, user)
+ |> Map.put(:reply_visibility, "self")
+ |> Map.put(:reply_filtering_user, user)
+ |> Map.put(:user, user)
|> ActivityPub.fetch_public_activities()
|> Enum.map(& &1.id)
test "home timeline", %{users: %{u1: user}} do
params =
%{}
- |> Map.put("type", ["Create", "Announce"])
- |> Map.put("blocking_user", user)
- |> Map.put("muting_user", user)
- |> Map.put("user", user)
+ |> Map.put(:type, ["Create", "Announce"])
+ |> Map.put(:blocking_user, user)
+ |> Map.put(:muting_user, user)
+ |> Map.put(:user, user)
activities_ids =
ActivityPub.fetch_activities([user.ap_id | User.following(user)], params)
test "home timeline with default reply_visibility `following`", %{users: %{u1: user}} do
params =
%{}
- |> Map.put("type", ["Create", "Announce"])
- |> Map.put("blocking_user", user)
- |> Map.put("muting_user", user)
- |> Map.put("user", user)
- |> Map.put("reply_visibility", "following")
- |> Map.put("reply_filtering_user", user)
+ |> Map.put(:type, ["Create", "Announce"])
+ |> Map.put(:blocking_user, user)
+ |> Map.put(:muting_user, user)
+ |> Map.put(:user, user)
+ |> Map.put(:reply_visibility, "following")
+ |> Map.put(:reply_filtering_user, user)
activities_ids =
ActivityPub.fetch_activities([user.ap_id | User.following(user)], params)
} do
params =
%{}
- |> Map.put("type", ["Create", "Announce"])
- |> Map.put("blocking_user", user)
- |> Map.put("muting_user", user)
- |> Map.put("user", user)
- |> Map.put("reply_visibility", "self")
- |> Map.put("reply_filtering_user", user)
+ |> Map.put(:type, ["Create", "Announce"])
+ |> Map.put(:blocking_user, user)
+ |> Map.put(:muting_user, user)
+ |> Map.put(:user, user)
+ |> Map.put(:reply_visibility, "self")
+ |> Map.put(:reply_filtering_user, user)
activities_ids =
ActivityPub.fetch_activities([user.ap_id | User.following(user)], params)