Refactors.

This commit is contained in:
lain 2020-03-26 15:33:10 +01:00
parent ee979dd6d7
commit eaacc64839
2 changed files with 4 additions and 5 deletions

View File

@ -125,8 +125,6 @@ def increase_poll_votes_if_vote(%{
def increase_poll_votes_if_vote(_create_data), do: :noop def increase_poll_votes_if_vote(_create_data), do: :noop
@spec insert(map(), boolean(), boolean(), boolean()) :: {:ok, Activity.t()} | {:error, any()}
# TODO rewrite in with style
@spec persist(map(), keyword()) :: {:ok, Activity.t() | Object.t()} @spec persist(map(), keyword()) :: {:ok, Activity.t() | Object.t()}
def persist(object, meta) do def persist(object, meta) do
with local <- Keyword.fetch!(meta, :local), with local <- Keyword.fetch!(meta, :local),
@ -142,6 +140,7 @@ def persist(object, meta) do
end end
end end
@spec insert(map(), boolean(), boolean(), boolean()) :: {:ok, Activity.t()} | {:error, any()}
def insert(map, local \\ true, fake \\ false, bypass_actor_check \\ false) when is_map(map) do def insert(map, local \\ true, fake \\ false, bypass_actor_check \\ false) when is_map(map) do
with nil <- Activity.normalize(map), with nil <- Activity.normalize(map),
map <- lazy_put_activity_defaults(map, fake), map <- lazy_put_activity_defaults(map, fake),

View File

@ -21,11 +21,11 @@ def validate_actor_presence(cng, field_name \\ :actor) do
def validate_object_presence(cng, field_name \\ :object) do def validate_object_presence(cng, field_name \\ :object) do
cng cng
|> validate_change(field_name, fn field_name, actor -> |> validate_change(field_name, fn field_name, object ->
if Object.get_cached_by_ap_id(actor) do if Object.get_cached_by_ap_id(object) do
[] []
else else
[{field_name, "can't find user"}] [{field_name, "can't find object"}]
end end
end) end)
end end