mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-14 05:04:49 +00:00
Oh no! More fixes!
This commit is contained in:
parent
01d5ef65fa
commit
541a4cbbb6
2 changed files with 25 additions and 17 deletions
|
@ -14,7 +14,7 @@ defmodule Mix.Tasks.FixApUsers do
|
||||||
|
|
||||||
Enum.each(users, fn(user) ->
|
Enum.each(users, fn(user) ->
|
||||||
IO.puts("Fetching #{user.nickname}")
|
IO.puts("Fetching #{user.nickname}")
|
||||||
Pleroma.Web.ActivityPub.Transmogrifier.upgrade_user_from_ap_id(user.ap_id)
|
Pleroma.Web.ActivityPub.Transmogrifier.upgrade_user_from_ap_id(user.ap_id, false)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -197,18 +197,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
||||||
|> Map.put("attachment", attachments)
|
|> Map.put("attachment", attachments)
|
||||||
end
|
end
|
||||||
|
|
||||||
def upgrade_user_from_ap_id(ap_id) do
|
defp user_upgrade_task(user) do
|
||||||
with %User{} = user <- User.get_by_ap_id(ap_id),
|
|
||||||
{:ok, data} <- ActivityPub.fetch_and_prepare_user_from_ap_id(ap_id) do
|
|
||||||
data = data
|
|
||||||
|> Map.put(:info, Map.merge(user.info, data[:info]))
|
|
||||||
|
|
||||||
old_follower_address = User.ap_followers(user)
|
old_follower_address = User.ap_followers(user)
|
||||||
{:ok, user} = User.upgrade_changeset(user, data)
|
|
||||||
|> Repo.update()
|
|
||||||
|
|
||||||
# This could potentially take a long time, do it in the background
|
|
||||||
Task.start(fn ->
|
|
||||||
q = from u in User,
|
q = from u in User,
|
||||||
where: ^old_follower_address in u.following,
|
where: ^old_follower_address in u.following,
|
||||||
update: [set: [following: fragment("array_replace(?,?,?)", u.following, ^old_follower_address, ^user.follower_address)]]
|
update: [set: [following: fragment("array_replace(?,?,?)", u.following, ^old_follower_address, ^user.follower_address)]]
|
||||||
|
@ -221,7 +211,25 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
||||||
where: a.id > ^since,
|
where: a.id > ^since,
|
||||||
update: [set: [recipients: fragment("array_replace(?,?,?)", a.recipients, ^old_follower_address, ^user.follower_address)]]
|
update: [set: [recipients: fragment("array_replace(?,?,?)", a.recipients, ^old_follower_address, ^user.follower_address)]]
|
||||||
Repo.update_all(q, [])
|
Repo.update_all(q, [])
|
||||||
|
end
|
||||||
|
|
||||||
|
def upgrade_user_from_ap_id(ap_id, async \\ true) do
|
||||||
|
with %User{} = user <- User.get_by_ap_id(ap_id),
|
||||||
|
{:ok, data} <- ActivityPub.fetch_and_prepare_user_from_ap_id(ap_id) do
|
||||||
|
data = data
|
||||||
|
|> Map.put(:info, Map.merge(user.info, data[:info]))
|
||||||
|
|
||||||
|
{:ok, user} = User.upgrade_changeset(user, data)
|
||||||
|
|> Repo.update()
|
||||||
|
|
||||||
|
# This could potentially take a long time, do it in the background
|
||||||
|
if async do
|
||||||
|
Task.start(fn ->
|
||||||
|
user_upgrade_task(user)
|
||||||
end)
|
end)
|
||||||
|
else
|
||||||
|
user_upgrade_task(user)
|
||||||
|
end
|
||||||
|
|
||||||
{:ok, user}
|
{:ok, user}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue