@@ -52,12 +52,12 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
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 | |||
@@ -70,17 +70,17 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
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() | |||
@@ -90,19 +90,19 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
}, | |||
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() | |||
) | |||
@@ -110,12 +110,12 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
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 | |||
@@ -130,7 +130,7 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
|> 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 | |||
@@ -138,7 +138,7 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
|> 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 | |||
@@ -146,7 +146,7 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
|> 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 | |||
@@ -165,7 +165,7 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
"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() | |||
) | |||
@@ -173,34 +173,34 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
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 | |||
@@ -223,7 +223,7 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
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 | |||
@@ -245,15 +245,13 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
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 -> | |||
@@ -269,30 +267,28 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
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( | |||
@@ -303,17 +299,17 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
}, | |||
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 | |||
@@ -322,15 +318,15 @@ defmodule Pleroma.LoadTesting.Fetcher 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( | |||
@@ -341,10 +337,10 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
}, | |||
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() | |||
) | |||
@@ -354,13 +350,13 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
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( | |||
%{ | |||
@@ -370,10 +366,10 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
}, | |||
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() | |||
) | |||
@@ -381,8 +377,8 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
defp opts_for_long_thread(user) do | |||
%{ | |||
"blocking_user" => user, | |||
"user" => user | |||
blocking_user: user, | |||
user: user | |||
} | |||
end | |||
@@ -392,9 +388,9 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
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( | |||
%{ | |||
@@ -514,13 +510,13 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
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( | |||
@@ -551,14 +547,14 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
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 | |||
}, | |||
@@ -577,16 +573,16 @@ defmodule Pleroma.LoadTesting.Fetcher do | |||
"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 | |||
@@ -100,14 +100,14 @@ defmodule Mix.Tasks.Pleroma.Benchmarks.Tags do | |||
_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 |
@@ -92,10 +92,10 @@ defmodule Pleroma.BBS.Handler do | |||
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)] | |||
@@ -163,8 +163,8 @@ defmodule Pleroma.Conversation.Participation do | |||
|> 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 | |||
}) | |||
%{ | |||
@@ -16,19 +16,16 @@ defmodule Pleroma.Pagination do | |||
@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 | |||
@@ -41,7 +38,7 @@ defmodule Pleroma.Pagination do | |||
|> 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) | |||
@@ -49,7 +46,7 @@ defmodule Pleroma.Pagination do | |||
%{ | |||
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 | |||
@@ -90,12 +87,6 @@ defmodule Pleroma.Pagination do | |||
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 | |||
@@ -67,16 +67,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
{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 | |||
@@ -87,7 +83,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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 | |||
@@ -95,36 +91,26 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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 | |||
@@ -203,8 +189,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub 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 | |||
@@ -226,13 +212,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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 | |||
@@ -266,12 +254,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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), | |||
@@ -299,12 +288,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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} | |||
@@ -322,14 +312,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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} | |||
@@ -341,15 +332,17 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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} | |||
@@ -366,8 +359,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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} | |||
@@ -411,13 +405,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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} | |||
@@ -496,8 +490,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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) | |||
@@ -505,7 +499,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
|> 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( | |||
@@ -532,7 +526,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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() | |||
@@ -540,24 +534,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
@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 | |||
@@ -566,20 +554,17 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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 | |||
@@ -601,7 +586,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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( | |||
@@ -621,7 +606,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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, | |||
@@ -636,7 +621,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
) | |||
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 | |||
@@ -647,14 +632,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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) | |||
@@ -666,87 +647,79 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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) | |||
@@ -755,12 +728,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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) | |||
@@ -769,18 +741,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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) | |||
@@ -803,35 +775,35 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
) | |||
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) | |||
@@ -840,11 +812,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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, ^[]) | |||
@@ -853,7 +825,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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) | |||
@@ -861,8 +833,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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, | |||
@@ -877,8 +849,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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, | |||
@@ -897,16 +869,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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, | |||
@@ -914,7 +886,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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 | |||
@@ -923,8 +895,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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) | |||
@@ -970,7 +942,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
defp restrict_blocked(query, _), do: query | |||
defp restrict_unlisted(query) do | |||
defp restrict_unlisted(query, %{restrict_unlisted: true}) do | |||
from( | |||
activity in query, | |||
where: | |||
@@ -982,19 +954,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
) | |||
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, | |||
@@ -1010,7 +979,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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, | |||
@@ -1024,7 +993,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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 | |||
@@ -1036,7 +1005,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub 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 = | |||
@@ -1047,38 +1016,38 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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 | |||
@@ -1094,24 +1063,23 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub 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 | |||
@@ -1130,7 +1098,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
|> 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) | |||
@@ -1157,12 +1125,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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 """ | |||
@@ -1178,16 +1146,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
|> 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 | |||
@@ -1201,7 +1168,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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 | |||
@@ -1276,8 +1243,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
%{"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 | |||
@@ -1323,18 +1290,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
} | |||
# 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 | |||
@@ -1409,9 +1373,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub 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 | |||
@@ -1419,15 +1382,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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 | |||
@@ -1450,8 +1412,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
|> Repo.insert() | |||
|> User.set_cache() | |||
end | |||
else | |||
e -> {:error, e} | |||
end | |||
end | |||
end | |||
@@ -1465,7 +1425,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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 | |||
@@ -1476,7 +1436,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do | |||
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 | |||
@@ -233,16 +233,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do | |||
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 | |||
@@ -356,11 +356,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do | |||
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 | |||
@@ -244,7 +244,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do | |||
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"]) | |||
@@ -740,13 +740,12 @@ defmodule Pleroma.Web.ActivityPub.Utils do | |||
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 | |||
@@ -228,10 +228,10 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do | |||
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 | |||
@@ -248,9 +248,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do | |||
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 | |||
@@ -29,11 +29,11 @@ defmodule Pleroma.Web.AdminAPI.StatusController do | |||
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) | |||
@@ -18,7 +18,7 @@ defmodule Pleroma.Web.AdminAPI.ReportView do | |||
%{ | |||
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] | |||
@@ -81,8 +81,7 @@ defmodule Pleroma.Web.ControllerHelper do | |||
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 | |||
@@ -15,8 +15,8 @@ defmodule Pleroma.Web.Feed.TagController do | |||
{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 | |||
@@ -52,10 +52,10 @@ defmodule Pleroma.Web.Feed.UserController do | |||
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 | |||
@@ -254,9 +254,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do | |||
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) | |||
@@ -21,7 +21,6 @@ defmodule Pleroma.Web.MastodonAPI.ConversationController do | |||
@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 | |||
@@ -37,20 +36,4 @@ defmodule Pleroma.Web.MastodonAPI.ConversationController do | |||
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 |
@@ -359,9 +359,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do | |||
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) | |||
@@ -370,11 +370,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do | |||
@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 | |||
@@ -44,12 +44,11 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do | |||
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)] | |||
@@ -71,10 +70,9 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do | |||
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 = | |||
@@ -93,9 +91,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do | |||
# 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 | |||
@@ -111,11 +107,11 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController 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 | |||
@@ -130,39 +126,38 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do | |||
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 | |||
@@ -24,8 +24,8 @@ defmodule Pleroma.Web.MastodonAPI.ConversationView do | |||
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 | |||
@@ -126,10 +126,9 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do | |||
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 | |||
@@ -42,15 +42,14 @@ defmodule Pleroma.Web.PleromaAPI.ConversationController 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 | |||
@@ -36,10 +36,7 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleController do | |||
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) | |||
@@ -111,8 +111,14 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do | |||
%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 = | |||
@@ -21,7 +21,7 @@ defmodule Pleroma.PaginationTest do | |||
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 | |||
@@ -31,7 +31,7 @@ defmodule Pleroma.PaginationTest do | |||
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 | |||
@@ -41,7 +41,7 @@ defmodule Pleroma.PaginationTest do | |||
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 | |||
@@ -50,7 +50,7 @@ defmodule Pleroma.PaginationTest do | |||
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 | |||
@@ -64,13 +64,13 @@ defmodule Pleroma.PaginationTest do | |||
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 | |||
@@ -62,11 +62,11 @@ defmodule Mix.Tasks.Pleroma.RelayTest do | |||
[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" | |||
@@ -1122,7 +1122,7 @@ defmodule Pleroma.UserTest do | |||
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) | |||
@@ -1132,7 +1132,7 @@ defmodule Pleroma.UserTest do | |||
assert [] == | |||
ActivityPub.fetch_activities([user2.ap_id | User.following(user2)], %{ | |||
"user" => user2 | |||
user: user2 | |||
}) | |||
end | |||
end | |||
@@ -82,30 +82,28 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
{: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] | |||
@@ -126,8 +124,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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 | |||
@@ -137,8 +135,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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 | |||
@@ -148,8 +146,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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 | |||
@@ -159,8 +157,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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 | |||
@@ -193,23 +191,22 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
{: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] | |||
@@ -375,7 +372,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
_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 | |||
@@ -507,7 +504,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
{: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 | |||
@@ -520,8 +517,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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) | |||
@@ -529,8 +525,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
{: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) | |||
@@ -541,16 +536,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
%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) | |||
@@ -573,7 +566,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
{: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) | |||
@@ -595,7 +588,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
{: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) | |||
@@ -611,8 +604,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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 | |||
@@ -620,8 +612,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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 | |||
@@ -641,8 +632,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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 | |||
@@ -653,8 +643,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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 | |||
@@ -669,8 +658,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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) | |||
@@ -679,9 +667,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
# 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) | |||
@@ -690,8 +678,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
{: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) | |||
@@ -703,15 +690,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
%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) | |||
@@ -727,7 +713,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
{: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 | |||
@@ -739,7 +725,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest 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 | |||
@@ -761,7 +747,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest 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 | |||
@@ -804,7 +790,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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 | |||
@@ -819,7 +805,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
|> 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) | |||
@@ -831,8 +817,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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 | |||
@@ -848,7 +833,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
{: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 | |||
@@ -862,7 +847,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
{: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 | |||
@@ -1066,7 +1051,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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 | |||
@@ -1115,7 +1100,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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 | |||
@@ -1226,7 +1211,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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 | |||
@@ -1400,7 +1385,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest 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 | |||
@@ -1470,7 +1455,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
{: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 | |||
@@ -1483,11 +1468,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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) | |||
@@ -1504,12 +1489,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
} 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) | |||
@@ -1531,12 +1516,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
} 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) | |||
@@ -1555,11 +1540,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
} 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) | |||
@@ -1593,12 +1578,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
} 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) | |||
@@ -1632,12 +1617,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
} 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) | |||
@@ -1666,11 +1651,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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) | |||
@@ -1680,13 +1665,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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) | |||
@@ -1696,13 +1681,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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) | |||
@@ -1712,10 +1697,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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) | |||
@@ -1727,12 +1712,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
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) | |||
@@ -1751,12 +1736,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do | |||
} 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) | |||