# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.MigrationHelper.NotificationBackfill do
- alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.User
query
|> Repo.chunk_stream(100)
|> Enum.each(fn notification ->
- type =
- notification.activity
- |> type_from_activity()
+ if notification.activity do
+ type = type_from_activity(notification.activity)
- notification
- |> Ecto.Changeset.change(%{type: type})
- |> Repo.update()
+ notification
+ |> Ecto.Changeset.change(%{type: type})
+ |> Repo.update()
+ end
end)
end
"pleroma:emoji_reaction"
"Create" ->
- activity
- |> type_from_activity_object()
+ type_from_activity_object(activity)
t ->
raise "No notification type for activity type #{t}"
end
end
- defp type_from_activity_object(%{data: %{"type" => "Create", "object" => %{}}}), do: "mention"
-
- defp type_from_activity_object(%{data: %{"type" => "Create"}} = activity) do
- object = Object.get_by_ap_id(activity.data["object"])
-
- case object && object.data["type"] do
- "ChatMessage" -> "pleroma:chat_mention"
- _ -> "mention"
- end
- end
+ defp type_from_activity_object(%{data: %{"type" => "Create"}}), do: "mention"
end