Migrations: Add a migration to backfill notification types.
This commit is contained in:
parent
38dce485c4
commit
6cd2fa2a4c
@ -49,7 +49,7 @@ def fill_in_notification_types() do
|
|||||||
|> Enum.each(fn notification ->
|
|> Enum.each(fn notification ->
|
||||||
type =
|
type =
|
||||||
notification.activity
|
notification.activity
|
||||||
|> type_from_activity()
|
|> type_from_activity(no_cachex: true)
|
||||||
|
|
||||||
notification
|
notification
|
||||||
|> changeset(%{type: type})
|
|> changeset(%{type: type})
|
||||||
@ -364,10 +364,23 @@ defp do_create_notifications(%Activity{} = activity) do
|
|||||||
{:ok, notifications}
|
{:ok, notifications}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp type_from_activity(%{data: %{"type" => type}} = activity) do
|
defp type_from_activity(%{data: %{"type" => type}} = activity, opts \\ []) do
|
||||||
case type do
|
case type do
|
||||||
"Follow" ->
|
"Follow" ->
|
||||||
if Activity.follow_accepted?(activity) do
|
accepted_function =
|
||||||
|
if Keyword.get(opts, :no_cachex, false) do
|
||||||
|
# A special function to make this usable in a migration.
|
||||||
|
fn activity ->
|
||||||
|
with %User{} = follower <- User.get_by_ap_id(activity.data["actor"]),
|
||||||
|
%User{} = followed <- User.get_by_ap_id(activity.data["object"]) do
|
||||||
|
Pleroma.FollowingRelationship.following?(follower, followed)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
&Activity.follow_accepted?/1
|
||||||
|
end
|
||||||
|
|
||||||
|
if accepted_function.(activity) do
|
||||||
"follow"
|
"follow"
|
||||||
else
|
else
|
||||||
"follow_request"
|
"follow_request"
|
||||||
@ -394,8 +407,10 @@ defp type_from_activity(%{data: %{"type" => type}} = activity) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp type_from_activity_object(%{data: %{"type" => "Create", "object" => %{}}}), do: "mention"
|
||||||
|
|
||||||
defp type_from_activity_object(%{data: %{"type" => "Create"}} = activity) do
|
defp type_from_activity_object(%{data: %{"type" => "Create"}} = activity) do
|
||||||
object = Object.normalize(activity, false)
|
object = Object.get_by_ap_id(activity.data["object"])
|
||||||
|
|
||||||
case object.data["type"] do
|
case object.data["type"] do
|
||||||
"ChatMessage" -> "pleroma:chat_mention"
|
"ChatMessage" -> "pleroma:chat_mention"
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
defmodule Pleroma.Repo.Migrations.BackfillNotificationTypes do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def up do
|
||||||
|
Pleroma.Notification.fill_in_notification_types()
|
||||||
|
end
|
||||||
|
|
||||||
|
def down do
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user