From c70df5fb2aeffa91a6dcdf7fe2ecb63b3fffc701 Mon Sep 17 00:00:00 2001 From: Erin Shepherd Date: Sat, 2 Mar 2024 22:34:59 +0100 Subject: [PATCH] bites you --- README.md | 4 +++- lib/pleroma/notification.ex | 9 +++++++-- lib/pleroma/web/activity_pub/side_effects.ex | 7 +++++++ lib/pleroma/web/activity_pub/transmogrifier.ex | 2 +- lib/pleroma/web/federator.ex | 2 +- .../web/mastodon_api/views/notification_view.ex | 2 +- ...0302224115_add_bite_to_notifications_enum.exs | 16 ++++++++++++++++ 7 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 priv/repo/migrations/20240302224115_add_bite_to_notifications_enum.exs diff --git a/README.md b/README.md index e4aa25715..5394e4a60 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -## akkoma +## snaccoma: akkoma with bites + +this is a silly little fork which can receive [Bite](https://ns.mia.jetzt/as/) activities *a smallish microblogging platform, aka the cooler pleroma* diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 885d61233..aaa8cf3ac 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -72,6 +72,7 @@ defmodule Pleroma.Notification do pleroma:report reblog poll + bite } def changeset(%Notification{} = notification, attrs) do @@ -402,7 +403,7 @@ defmodule Pleroma.Notification do end def create_notifications(%Activity{data: %{"type" => type}} = activity, options) - when type in ["Follow", "Like", "Announce", "Move", "EmojiReact", "Flag", "Update"] do + when type in ["Follow", "Like", "Announce", "Move", "EmojiReact", "Flag", "Update", "Bite"] do do_create_notifications(activity, options) end @@ -459,6 +460,9 @@ defmodule Pleroma.Notification do "Update" -> "update" + "Bite" -> + "bite" + t -> raise "No notification type for activity type #{t}" end @@ -532,7 +536,8 @@ defmodule Pleroma.Notification do "Move", "EmojiReact", "Flag", - "Update" + "Update", + "Bite" ] do potential_receiver_ap_ids = get_potential_receiver_ap_ids(activity) diff --git a/lib/pleroma/web/activity_pub/side_effects.ex b/lib/pleroma/web/activity_pub/side_effects.ex index 963c6d8c6..405e6d04c 100644 --- a/lib/pleroma/web/activity_pub/side_effects.ex +++ b/lib/pleroma/web/activity_pub/side_effects.ex @@ -186,6 +186,13 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do {:ok, object, meta} end + # Tasks this handles + # - Set up bite notification + def handle(%{data: %{"type" => "Bite"}} = object, meta) do + Notification.create_notifications(object) + {:ok, object, meta} + end + # Tasks this handles # - Actually create object # - Rollback if we couldn't create it diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index a72a431b2..806323dd9 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -485,7 +485,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do %{"type" => type} = data, _options ) - when type in ~w{Update Block Follow Accept Reject} do + when type in ~w{Update Block Follow Accept Reject Bite} do with {:ok, %User{}} <- ObjectValidator.fetch_actor(data), {:ok, activity, _} <- Pipeline.common_pipeline(data, local: false) do diff --git a/lib/pleroma/web/federator.ex b/lib/pleroma/web/federator.ex index 3a00424c6..e71ccd2fa 100644 --- a/lib/pleroma/web/federator.ex +++ b/lib/pleroma/web/federator.ex @@ -118,7 +118,7 @@ defmodule Pleroma.Web.Federator do e -> # Just drop those for now - Logger.debug(fn -> "Unhandled activity\n" <> Jason.encode!(params, pretty: true) end) + Logger.debug(fn -> "Unhandled activity (error: #{inspect(e)})\n" <> Jason.encode!(params, pretty: true) end) {:error, e} end end diff --git a/lib/pleroma/web/mastodon_api/views/notification_view.ex b/lib/pleroma/web/mastodon_api/views/notification_view.ex index e527ff608..2ab725d6a 100644 --- a/lib/pleroma/web/mastodon_api/views/notification_view.ex +++ b/lib/pleroma/web/mastodon_api/views/notification_view.ex @@ -128,7 +128,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do "pleroma:report" -> put_report(response, activity) - type when type in ["follow", "follow_request"] -> + type when type in ["follow", "follow_request", "bite"] -> response end end diff --git a/priv/repo/migrations/20240302224115_add_bite_to_notifications_enum.exs b/priv/repo/migrations/20240302224115_add_bite_to_notifications_enum.exs new file mode 100644 index 000000000..8adf51aa2 --- /dev/null +++ b/priv/repo/migrations/20240302224115_add_bite_to_notifications_enum.exs @@ -0,0 +1,16 @@ +defmodule Pleroma.Repo.Migrations.AddBiteToNotificationsEnum do + use Ecto.Migration + + @disable_ddl_transaction true + + def up do + """ + alter type notification_type add value if not exists 'bite' + """ + |> execute() + end + + def down do + # Leave value in place + end +end