Push: add missing notification_type field

This commit is contained in:
href 2018-12-08 17:34:13 +01:00
parent 7facbb2b8d
commit d8984b7bf8
No known key found for this signature in database
GPG key ID: EE8296C1A152C325

View file

@ -58,14 +58,15 @@ def handle_cast(
body = body =
Jason.encode!(%{ Jason.encode!(%{
title: format_title(notification), title: format_title(notification),
access_token: record.token.token,
body: format_body(notification, actor), body: format_body(notification, actor),
notification_id: notification.id, notification_id: notification.id,
notification_type: format_type(notification),
icon: User.avatar_url(actor), icon: User.avatar_url(actor),
preferred_locale: "en", preferred_locale: "en"
access_token: record.token.token
}) })
case WebPushEncryption.send_web_push(body, subscription, @gcm_api_key) do case WebPushEncryption.send_web_push(body, subscription) do
{:ok, %{status_code: code}} when 400 <= code and code < 500 -> {:ok, %{status_code: code}} when 400 <= code and code < 500 ->
Logger.debug("Removing subscription record") Logger.debug("Removing subscription record")
Repo.delete!(record) Repo.delete!(record)
@ -92,6 +93,16 @@ def handle_cast({:send, _}, state) do
{:noreply, state} {:noreply, state}
end end
# https://github.com/tootsuite/mastodon/blob/master/app/models/notification.rb#L19
defp format_type(%{activity: %{data: %{"type" => type}}}) do
case type do
"Create" -> "mention"
"Follow" -> "follow"
"Announce" -> "reblog"
"Favorite" -> "favourite"
end
end
defp format_title(%{activity: %{data: %{"type" => type}}}) do defp format_title(%{activity: %{data: %{"type" => type}}}) do
case type do case type do
"Create" -> "New Mention" "Create" -> "New Mention"