Merge branch '1910-migration-fix' into 'develop'
Notification Backfill: Explicitly select the needed fields. Closes #1910 See merge request pleroma/pleroma!2715
This commit is contained in:
commit
86151b23a6
1 changed files with 12 additions and 4 deletions
|
@ -3,7 +3,6 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.MigrationHelper.NotificationBackfill do
|
defmodule Pleroma.MigrationHelper.NotificationBackfill do
|
||||||
alias Pleroma.Notification
|
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
@ -25,18 +24,27 @@ def fill_in_notification_types do
|
||||||
|> type_from_activity()
|
|> type_from_activity()
|
||||||
|
|
||||||
notification
|
notification
|
||||||
|> Notification.changeset(%{type: type})
|
|> Ecto.Changeset.change(%{type: type})
|
||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp get_by_ap_id(ap_id) do
|
||||||
|
q =
|
||||||
|
from(u in User,
|
||||||
|
select: u.id
|
||||||
|
)
|
||||||
|
|
||||||
|
Repo.get_by(q, ap_id: ap_id)
|
||||||
|
end
|
||||||
|
|
||||||
# This is copied over from Notifications to keep this stable.
|
# This is copied over from Notifications to keep this stable.
|
||||||
defp type_from_activity(%{data: %{"type" => type}} = activity) do
|
defp type_from_activity(%{data: %{"type" => type}} = activity) do
|
||||||
case type do
|
case type do
|
||||||
"Follow" ->
|
"Follow" ->
|
||||||
accepted_function = fn activity ->
|
accepted_function = fn activity ->
|
||||||
with %User{} = follower <- User.get_by_ap_id(activity.data["actor"]),
|
with %User{} = follower <- get_by_ap_id(activity.data["actor"]),
|
||||||
%User{} = followed <- User.get_by_ap_id(activity.data["object"]) do
|
%User{} = followed <- get_by_ap_id(activity.data["object"]) do
|
||||||
Pleroma.FollowingRelationship.following?(follower, followed)
|
Pleroma.FollowingRelationship.following?(follower, followed)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue