Remove unnecessary mastodon_type hack
This commit is contained in:
parent
db88bf30d5
commit
86fa0889bc
@ -29,7 +29,6 @@ defmodule Pleroma.Web.Push.Impl do
|
|||||||
when activity_type in @types do
|
when activity_type in @types do
|
||||||
actor = User.get_cached_by_ap_id(notification.activity.data["actor"])
|
actor = User.get_cached_by_ap_id(notification.activity.data["actor"])
|
||||||
|
|
||||||
mastodon_type = notification.type
|
|
||||||
gcm_api_key = Application.get_env(:web_push_encryption, :gcm_api_key)
|
gcm_api_key = Application.get_env(:web_push_encryption, :gcm_api_key)
|
||||||
avatar_url = User.avatar_url(actor)
|
avatar_url = User.avatar_url(actor)
|
||||||
object = Object.normalize(activity, fetch: false)
|
object = Object.normalize(activity, fetch: false)
|
||||||
@ -37,11 +36,11 @@ defmodule Pleroma.Web.Push.Impl do
|
|||||||
direct_conversation_id = Activity.direct_conversation_id(activity, user)
|
direct_conversation_id = Activity.direct_conversation_id(activity, user)
|
||||||
|
|
||||||
for subscription <- fetch_subscriptions(user_id),
|
for subscription <- fetch_subscriptions(user_id),
|
||||||
Subscription.enabled?(subscription, mastodon_type) do
|
Subscription.enabled?(subscription, notification.type) do
|
||||||
%{
|
%{
|
||||||
access_token: subscription.token.token,
|
access_token: subscription.token.token,
|
||||||
notification_id: notification.id,
|
notification_id: notification.id,
|
||||||
notification_type: mastodon_type,
|
notification_type: notification.type,
|
||||||
icon: avatar_url,
|
icon: avatar_url,
|
||||||
preferred_locale: "en",
|
preferred_locale: "en",
|
||||||
pleroma: %{
|
pleroma: %{
|
||||||
@ -49,7 +48,7 @@ defmodule Pleroma.Web.Push.Impl do
|
|||||||
direct_conversation_id: direct_conversation_id
|
direct_conversation_id: direct_conversation_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|> Map.merge(build_content(notification, actor, object, mastodon_type))
|
|> Map.merge(build_content(notification, actor, object))
|
||||||
|> Jason.encode!()
|
|> Jason.encode!()
|
||||||
|> push_message(build_sub(subscription), gcm_api_key, subscription)
|
|> push_message(build_sub(subscription), gcm_api_key, subscription)
|
||||||
end
|
end
|
||||||
@ -106,31 +105,24 @@ defmodule Pleroma.Web.Push.Impl do
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_content(notification, actor, object, mastodon_type \\ nil)
|
|
||||||
|
|
||||||
def build_content(
|
def build_content(
|
||||||
%{
|
%{
|
||||||
user: %{notification_settings: %{hide_notification_contents: true}}
|
user: %{notification_settings: %{hide_notification_contents: true}}
|
||||||
} = notification,
|
} = notification,
|
||||||
_actor,
|
_actor,
|
||||||
_object,
|
_object
|
||||||
mastodon_type
|
|
||||||
) do
|
) do
|
||||||
%{body: format_title(notification, mastodon_type)}
|
%{body: format_title(notification)}
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_content(notification, actor, object, mastodon_type) do
|
def build_content(notification, actor, object) do
|
||||||
mastodon_type = mastodon_type || notification.type
|
|
||||||
|
|
||||||
%{
|
%{
|
||||||
title: format_title(notification, mastodon_type),
|
title: format_title(notification),
|
||||||
body: format_body(notification, actor, object, mastodon_type)
|
body: format_body(notification, actor, object)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_body(activity, actor, object, mastodon_type \\ nil)
|
def format_body(_activity, actor, %{data: %{"type" => "ChatMessage"} = data}) do
|
||||||
|
|
||||||
def format_body(_activity, actor, %{data: %{"type" => "ChatMessage"} = data}, _) do
|
|
||||||
case data["content"] do
|
case data["content"] do
|
||||||
nil -> "@#{actor.nickname}: (Attachment)"
|
nil -> "@#{actor.nickname}: (Attachment)"
|
||||||
content -> "@#{actor.nickname}: #{Utils.scrub_html_and_truncate(content, 80)}"
|
content -> "@#{actor.nickname}: #{Utils.scrub_html_and_truncate(content, 80)}"
|
||||||
@ -140,8 +132,7 @@ defmodule Pleroma.Web.Push.Impl do
|
|||||||
def format_body(
|
def format_body(
|
||||||
%{activity: %{data: %{"type" => "Create"}}},
|
%{activity: %{data: %{"type" => "Create"}}},
|
||||||
actor,
|
actor,
|
||||||
%{data: %{"content" => content}},
|
%{data: %{"content" => content}}
|
||||||
_mastodon_type
|
|
||||||
) do
|
) do
|
||||||
"@#{actor.nickname}: #{Utils.scrub_html_and_truncate(content, 80)}"
|
"@#{actor.nickname}: #{Utils.scrub_html_and_truncate(content, 80)}"
|
||||||
end
|
end
|
||||||
@ -149,8 +140,7 @@ defmodule Pleroma.Web.Push.Impl do
|
|||||||
def format_body(
|
def format_body(
|
||||||
%{activity: %{data: %{"type" => "Announce"}}},
|
%{activity: %{data: %{"type" => "Announce"}}},
|
||||||
actor,
|
actor,
|
||||||
%{data: %{"content" => content}},
|
%{data: %{"content" => content}}
|
||||||
_mastodon_type
|
|
||||||
) do
|
) do
|
||||||
"@#{actor.nickname} repeated: #{Utils.scrub_html_and_truncate(content, 80)}"
|
"@#{actor.nickname} repeated: #{Utils.scrub_html_and_truncate(content, 80)}"
|
||||||
end
|
end
|
||||||
@ -158,8 +148,7 @@ defmodule Pleroma.Web.Push.Impl do
|
|||||||
def format_body(
|
def format_body(
|
||||||
%{activity: %{data: %{"type" => "EmojiReact", "content" => content}}},
|
%{activity: %{data: %{"type" => "EmojiReact", "content" => content}}},
|
||||||
actor,
|
actor,
|
||||||
_object,
|
_object
|
||||||
_mastodon_type
|
|
||||||
) do
|
) do
|
||||||
"@#{actor.nickname} reacted with #{content}"
|
"@#{actor.nickname} reacted with #{content}"
|
||||||
end
|
end
|
||||||
@ -167,13 +156,10 @@ defmodule Pleroma.Web.Push.Impl do
|
|||||||
def format_body(
|
def format_body(
|
||||||
%{activity: %{data: %{"type" => type}}} = notification,
|
%{activity: %{data: %{"type" => type}}} = notification,
|
||||||
actor,
|
actor,
|
||||||
_object,
|
_object
|
||||||
mastodon_type
|
|
||||||
)
|
)
|
||||||
when type in ["Follow", "Like"] do
|
when type in ["Follow", "Like"] do
|
||||||
mastodon_type = mastodon_type || notification.type
|
case notification.type do
|
||||||
|
|
||||||
case mastodon_type do
|
|
||||||
"follow" -> "@#{actor.nickname} has followed you"
|
"follow" -> "@#{actor.nickname} has followed you"
|
||||||
"follow_request" -> "@#{actor.nickname} has requested to follow you"
|
"follow_request" -> "@#{actor.nickname} has requested to follow you"
|
||||||
"favourite" -> "@#{actor.nickname} has favorited your post"
|
"favourite" -> "@#{actor.nickname} has favorited your post"
|
||||||
@ -183,20 +169,17 @@ defmodule Pleroma.Web.Push.Impl do
|
|||||||
def format_body(
|
def format_body(
|
||||||
%{activity: %{data: %{"type" => "Update"}}},
|
%{activity: %{data: %{"type" => "Update"}}},
|
||||||
actor,
|
actor,
|
||||||
_object,
|
_object
|
||||||
_mastodon_type
|
|
||||||
) do
|
) do
|
||||||
"@#{actor.nickname} edited a status"
|
"@#{actor.nickname} edited a status"
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_title(activity, mastodon_type \\ nil)
|
def format_title(%{activity: %{data: %{"directMessage" => true}}}) do
|
||||||
|
|
||||||
def format_title(%{activity: %{data: %{"directMessage" => true}}}, _mastodon_type) do
|
|
||||||
"New Direct Message"
|
"New Direct Message"
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_title(%{type: type}, mastodon_type) do
|
def format_title(%{type: type}) do
|
||||||
case mastodon_type || type do
|
case type do
|
||||||
"mention" -> "New Mention"
|
"mention" -> "New Mention"
|
||||||
"status" -> "New Status"
|
"status" -> "New Status"
|
||||||
"follow" -> "New Follower"
|
"follow" -> "New Follower"
|
||||||
|
Loading…
Reference in New Issue
Block a user