From ac672a9d6bfdd3cba7692f80a883bd38b0b09a57 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 9 Apr 2020 15:13:37 +0300 Subject: [PATCH] [#1559] Addressed code review requests. --- lib/pleroma/activity.ex | 8 +++--- .../mastodon_api/views/notification_view.ex | 9 +++---- lib/pleroma/web/push/impl.ex | 25 ++++++++++--------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 3803d8e50..6213d0eb7 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -300,6 +300,8 @@ def follow_accepted?( def follow_accepted?(_), do: false + @spec mastodon_notification_type(Activity.t()) :: String.t() | nil + for {ap_type, type} <- @mastodon_notification_types, not is_list(type) do def mastodon_notification_type(%Activity{data: %{"type" => unquote(ap_type)}}), do: unquote(type) @@ -315,11 +317,11 @@ def mastodon_notification_type(%Activity{data: %{"type" => "Follow"}} = activity def mastodon_notification_type(%Activity{}), do: nil + @spec from_mastodon_notification_type(String.t()) :: String.t() | nil + @doc "Converts Mastodon notification type to AR activity type" def from_mastodon_notification_type(type) do with {k, _v} <- - Enum.find(@mastodon_notification_types, fn {_k, v} -> - v == type or (is_list(v) and type in v) - end) do + Enum.find(@mastodon_notification_types, fn {_k, v} -> type in List.wrap(v) end) do k 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 feed47129..7001fd7b9 100644 --- a/lib/pleroma/web/mastodon_api/views/notification_view.ex +++ b/lib/pleroma/web/mastodon_api/views/notification_view.ex @@ -113,17 +113,14 @@ def render( "move" -> put_target(response, activity, reading_user, render_opts) - "follow" -> - response - - "follow_request" -> - response - "pleroma:emoji_reaction" -> response |> put_status(parent_activity_fn.(), reading_user, render_opts) |> put_emoji(activity) + type when type in ["follow", "follow_request"] -> + response + _ -> nil end diff --git a/lib/pleroma/web/push/impl.ex b/lib/pleroma/web/push/impl.ex index 89d45b2e1..f1740a6e0 100644 --- a/lib/pleroma/web/push/impl.ex +++ b/lib/pleroma/web/push/impl.ex @@ -153,10 +153,10 @@ def format_body( when type in ["Follow", "Like"] do mastodon_type = mastodon_type || mastodon_notification_type(notification.activity) - case {type, mastodon_type} do - {"Follow", "follow"} -> "@#{actor.nickname} has followed you" - {"Follow", "follow_request"} -> "@#{actor.nickname} has requested to follow you" - {"Like", _} -> "@#{actor.nickname} has favorited your post" + case mastodon_type do + "follow" -> "@#{actor.nickname} has followed you" + "follow_request" -> "@#{actor.nickname} has requested to follow you" + "favourite" -> "@#{actor.nickname} has favorited your post" end end @@ -166,15 +166,16 @@ def format_title(%{activity: %{data: %{"directMessage" => true}}}, _mastodon_typ "New Direct Message" end - def format_title(%{activity: %{data: %{"type" => type}}} = notification, mastodon_type) do - mastodon_type = mastodon_type || mastodon_notification_type(notification.activity) + def format_title(%{activity: activity}, mastodon_type) do + mastodon_type = mastodon_type || mastodon_notification_type(activity) - case {type, mastodon_type} do - {"Create", _} -> "New Mention" - {"Follow", "follow"} -> "New Follower" - {"Follow", "follow_request"} -> "New Follow Request" - {"Announce", _} -> "New Repeat" - {"Like", _} -> "New Favorite" + case mastodon_type do + "mention" -> "New Mention" + "follow" -> "New Follower" + "follow_request" -> "New Follow Request" + "reblog" -> "New Repeat" + "favourite" -> "New Favorite" + type -> "New #{String.capitalize(type || "event")}" end end end