Apply suggestion to lib/pleroma/web/activity_pub/utils.ex

This commit is contained in:
Maksim 2019-09-04 17:31:14 +00:00
parent a890451187
commit 8306078de1
1 changed files with 13 additions and 20 deletions

View File

@ -356,26 +356,19 @@ def update_follow_state_for_all(
%Activity{data: %{"actor" => actor, "object" => object}} = activity, %Activity{data: %{"actor" => actor, "object" => object}} = activity,
state state
) do ) do
query = "Follow"
from(activity in Activity, |> Activity.Queries.by_type()
where: fragment("data->>'type' = 'Follow'"), |> Activity.Queries.by_actor(actor)
where: fragment("data->>'state' = 'pending'"), |> Activity.Queries.by_object_id(object["id"])
where: fragment("data->>'actor' = ?", ^actor), |> where(fragment("data->>'state' = 'pending'"))
where: fragment("data->>'object' = ?", ^object), |> update(set: [data: fragment("jsonb_set(data, '{state}', ?)", ^state)])
update: [ |> Repo.update_all([])
set: [
data: fragment("jsonb_set(data, '{state}', ?)", ^state)
]
]
)
with {_, _} <- Repo.update_all(query, []), User.set_follow_state_cache(actor, object, state)
{_, _} <- User.set_follow_state_cache(actor, object, state),
%Activity{} = activity <- Activity.get_by_id(activity.id) do activity = Activity.get_by_id(activity.id)
{:ok, activity}
else {:ok, activity}
e -> {:error, e}
end
end end
def update_follow_state( def update_follow_state(