insert object defaults for fake activities and make credo happy

This commit is contained in:
rinpatch 2019-04-01 12:16:51 +03:00
parent d866b59eea
commit 975482f091
2 changed files with 24 additions and 14 deletions

View File

@ -49,7 +49,7 @@ def get_cached_stripped_html_for_object(content, object, module) do
def ensure_scrubbed_html(
content,
scrubbers,
_fake = false
false = _fake
) do
{:commit, filter_tags(content, scrubbers)}
end
@ -57,7 +57,7 @@ def ensure_scrubbed_html(
def ensure_scrubbed_html(
content,
scrubbers,
_fake = true
true = _fake
) do
{:ignore, filter_tags(content, scrubbers)}
end

View File

@ -176,22 +176,15 @@ def maybe_federate(_), do: :ok
also adds it to an included object
"""
def lazy_put_activity_defaults(map, fake \\ false) do
map =
unless fake do
%{data: %{"id" => context}, id: context_id} = create_context(map["context"])
map =
map
|> Map.put_new_lazy("id", &generate_activity_id/0)
|> Map.put_new_lazy("published", &make_date/0)
|> Map.put_new("context", context)
|> Map.put_new("context_id", context_id)
if is_map(map["object"]) do
object = lazy_put_object_defaults(map["object"], map)
%{map | "object" => object}
else
map
end
else
map
|> Map.put_new("id", "pleroma:fakeid")
@ -199,12 +192,29 @@ def lazy_put_activity_defaults(map, fake \\ false) do
|> Map.put_new("context", "pleroma:fakecontext")
|> Map.put_new("context_id", -1)
end
if is_map(map["object"]) do
object = lazy_put_object_defaults(map["object"], map, fake)
%{map | "object" => object}
else
map
end
end
@doc """
Adds an id and published date if they aren't there.
"""
def lazy_put_object_defaults(map, activity \\ %{}) do
def lazy_put_object_defaults(map, activity \\ %{}, fake)
def lazy_put_object_defaults(map, activity, true = _fake) do
map
|> Map.put_new_lazy("published", &make_date/0)
|> Map.put_new("id", "pleroma:fakeid")
|> Map.put_new("context", activity["context"])
|> Map.put_new("context_id", activity["context_id"])
end
def lazy_put_object_defaults(map, activity, _fake) do
map
|> Map.put_new_lazy("id", &generate_object_id/0)
|> Map.put_new_lazy("published", &make_date/0)