[#1559] Addressed code review requests.

This commit is contained in:
Ivan Tashkinov 2020-04-09 15:13:37 +03:00
parent 3965772b26
commit ac672a9d6b
3 changed files with 21 additions and 21 deletions

View File

@ -300,6 +300,8 @@ defmodule Pleroma.Activity do
def follow_accepted?(_), do: false 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 for {ap_type, type} <- @mastodon_notification_types, not is_list(type) do
def mastodon_notification_type(%Activity{data: %{"type" => unquote(ap_type)}}), def mastodon_notification_type(%Activity{data: %{"type" => unquote(ap_type)}}),
do: unquote(type) do: unquote(type)
@ -315,11 +317,11 @@ defmodule Pleroma.Activity do
def mastodon_notification_type(%Activity{}), do: nil 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 def from_mastodon_notification_type(type) do
with {k, _v} <- with {k, _v} <-
Enum.find(@mastodon_notification_types, fn {_k, v} -> Enum.find(@mastodon_notification_types, fn {_k, v} -> type in List.wrap(v) end) do
v == type or (is_list(v) and type in v)
end) do
k k
end end
end end

View File

@ -113,17 +113,14 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
"move" -> "move" ->
put_target(response, activity, reading_user, render_opts) put_target(response, activity, reading_user, render_opts)
"follow" ->
response
"follow_request" ->
response
"pleroma:emoji_reaction" -> "pleroma:emoji_reaction" ->
response response
|> put_status(parent_activity_fn.(), reading_user, render_opts) |> put_status(parent_activity_fn.(), reading_user, render_opts)
|> put_emoji(activity) |> put_emoji(activity)
type when type in ["follow", "follow_request"] ->
response
_ -> _ ->
nil nil
end end

View File

@ -153,10 +153,10 @@ defmodule Pleroma.Web.Push.Impl do
when type in ["Follow", "Like"] do when type in ["Follow", "Like"] do
mastodon_type = mastodon_type || mastodon_notification_type(notification.activity) mastodon_type = mastodon_type || mastodon_notification_type(notification.activity)
case {type, mastodon_type} do case mastodon_type do
{"Follow", "follow"} -> "@#{actor.nickname} has followed you" "follow" -> "@#{actor.nickname} has followed you"
{"Follow", "follow_request"} -> "@#{actor.nickname} has requested to follow you" "follow_request" -> "@#{actor.nickname} has requested to follow you"
{"Like", _} -> "@#{actor.nickname} has favorited your post" "favourite" -> "@#{actor.nickname} has favorited your post"
end end
end end
@ -166,15 +166,16 @@ defmodule Pleroma.Web.Push.Impl do
"New Direct Message" "New Direct Message"
end end
def format_title(%{activity: %{data: %{"type" => type}}} = notification, mastodon_type) do def format_title(%{activity: activity}, mastodon_type) do
mastodon_type = mastodon_type || mastodon_notification_type(notification.activity) mastodon_type = mastodon_type || mastodon_notification_type(activity)
case {type, mastodon_type} do case mastodon_type do
{"Create", _} -> "New Mention" "mention" -> "New Mention"
{"Follow", "follow"} -> "New Follower" "follow" -> "New Follower"
{"Follow", "follow_request"} -> "New Follow Request" "follow_request" -> "New Follow Request"
{"Announce", _} -> "New Repeat" "reblog" -> "New Repeat"
{"Like", _} -> "New Favorite" "favourite" -> "New Favorite"
type -> "New #{String.capitalize(type || "event")}"
end end
end end
end end