2017-09-01 13:35:23 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Web::NotificationSerializer < ActiveModel::Serializer
|
2017-09-02 03:03:21 +02:00
|
|
|
include RoutingHelper
|
2018-05-19 14:46:47 +02:00
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
include ActionView::Helpers::SanitizeHelper
|
2017-09-01 13:35:23 +02:00
|
|
|
|
2018-05-19 14:46:47 +02:00
|
|
|
attributes :access_token, :preferred_locale, :notification_id,
|
|
|
|
:notification_type, :icon, :title, :body
|
2017-09-01 13:35:23 +02:00
|
|
|
|
2018-05-19 14:46:47 +02:00
|
|
|
def access_token
|
|
|
|
current_push_subscription.associated_access_token
|
2017-09-01 13:35:23 +02:00
|
|
|
end
|
|
|
|
|
2018-05-19 14:46:47 +02:00
|
|
|
def preferred_locale
|
|
|
|
current_push_subscription.associated_user&.locale || I18n.default_locale
|
2017-09-01 13:35:23 +02:00
|
|
|
end
|
|
|
|
|
2018-05-19 14:46:47 +02:00
|
|
|
def notification_id
|
2017-09-01 13:35:23 +02:00
|
|
|
object.id
|
|
|
|
end
|
|
|
|
|
2018-05-19 14:46:47 +02:00
|
|
|
def notification_type
|
|
|
|
object.type
|
2017-09-01 13:35:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def icon
|
2018-05-19 14:46:47 +02:00
|
|
|
full_asset_url(object.from_account.avatar_static_url)
|
2017-09-01 13:35:23 +02:00
|
|
|
end
|
|
|
|
|
2018-05-19 14:46:47 +02:00
|
|
|
def title
|
|
|
|
I18n.t("notification_mailer.#{object.type}.subject", name: object.from_account.display_name.presence || object.from_account.username)
|
2017-09-01 13:35:23 +02:00
|
|
|
end
|
|
|
|
|
2018-05-19 14:46:47 +02:00
|
|
|
def body
|
2023-07-13 11:44:02 +02:00
|
|
|
str = strip_tags(object.target_status&.spoiler_text.presence || object.target_status&.text || object.from_account.note)
|
2022-04-23 21:47:43 +02:00
|
|
|
truncate(HTMLEntities.new.decode(str.to_str), length: 140, escape: false) # Do not encode entities, since this value will not be used in HTML
|
2017-09-01 13:35:23 +02:00
|
|
|
end
|
|
|
|
end
|