2017-09-01 21:35:23 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Web::NotificationSerializer < ActiveModel::Serializer
|
2017-09-02 11:03:21 +10:00
|
|
|
include RoutingHelper
|
2018-05-19 22:46:47 +10:00
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
include ActionView::Helpers::SanitizeHelper
|
2017-09-01 21:35:23 +10:00
|
|
|
|
2018-05-19 22:46:47 +10:00
|
|
|
attributes :access_token, :preferred_locale, :notification_id,
|
|
|
|
:notification_type, :icon, :title, :body
|
2017-09-01 21:35:23 +10:00
|
|
|
|
2018-05-19 22:46:47 +10:00
|
|
|
def access_token
|
|
|
|
current_push_subscription.associated_access_token
|
2017-09-01 21:35:23 +10:00
|
|
|
end
|
|
|
|
|
2018-05-19 22:46:47 +10:00
|
|
|
def preferred_locale
|
|
|
|
current_push_subscription.associated_user&.locale || I18n.default_locale
|
2017-09-01 21:35:23 +10:00
|
|
|
end
|
|
|
|
|
2018-05-19 22:46:47 +10:00
|
|
|
def notification_id
|
2017-09-01 21:35:23 +10:00
|
|
|
object.id
|
|
|
|
end
|
|
|
|
|
2018-05-19 22:46:47 +10:00
|
|
|
def notification_type
|
|
|
|
object.type
|
2017-09-01 21:35:23 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
def icon
|
2018-05-19 22:46:47 +10:00
|
|
|
full_asset_url(object.from_account.avatar_static_url)
|
2017-09-01 21:35:23 +10:00
|
|
|
end
|
|
|
|
|
2018-05-19 22:46:47 +10:00
|
|
|
def title
|
|
|
|
I18n.t("notification_mailer.#{object.type}.subject", name: object.from_account.display_name.presence || object.from_account.username)
|
2017-09-01 21:35:23 +10:00
|
|
|
end
|
|
|
|
|
2018-05-19 22:46:47 +10:00
|
|
|
def body
|
2018-08-24 05:44:27 +10:00
|
|
|
str = strip_tags(object.target_status&.spoiler_text&.presence || object.target_status&.text || object.from_account.note)
|
2022-04-24 05:47:43 +10: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 21:35:23 +10:00
|
|
|
end
|
|
|
|
end
|