2017-09-01 04:35:23 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Web::NotificationSerializer < ActiveModel::Serializer
|
2017-09-01 18:03:21 -07:00
|
|
|
include RoutingHelper
|
2018-05-19 05:46:47 -07:00
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
include ActionView::Helpers::SanitizeHelper
|
2017-09-01 04:35:23 -07:00
|
|
|
|
2018-05-19 05:46:47 -07:00
|
|
|
attributes :access_token, :preferred_locale, :notification_id,
|
|
|
|
:notification_type, :icon, :title, :body
|
2017-09-01 04:35:23 -07:00
|
|
|
|
2018-05-19 05:46:47 -07:00
|
|
|
def access_token
|
|
|
|
current_push_subscription.associated_access_token
|
2017-09-01 04:35:23 -07:00
|
|
|
end
|
|
|
|
|
2018-05-19 05:46:47 -07:00
|
|
|
def preferred_locale
|
|
|
|
current_push_subscription.associated_user&.locale || I18n.default_locale
|
2017-09-01 04:35:23 -07:00
|
|
|
end
|
|
|
|
|
2018-05-19 05:46:47 -07:00
|
|
|
def notification_id
|
2017-09-01 04:35:23 -07:00
|
|
|
object.id
|
|
|
|
end
|
|
|
|
|
2018-05-19 05:46:47 -07:00
|
|
|
def notification_type
|
|
|
|
object.type
|
2017-09-01 04:35:23 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def icon
|
2018-05-19 05:46:47 -07:00
|
|
|
full_asset_url(object.from_account.avatar_static_url)
|
2017-09-01 04:35:23 -07:00
|
|
|
end
|
|
|
|
|
2018-05-19 05:46:47 -07:00
|
|
|
def title
|
|
|
|
I18n.t("notification_mailer.#{object.type}.subject", name: object.from_account.display_name.presence || object.from_account.username)
|
2017-09-01 04:35:23 -07:00
|
|
|
end
|
|
|
|
|
2018-05-19 05:46:47 -07:00
|
|
|
def body
|
|
|
|
truncate(strip_tags(object.target_status&.spoiler_text&.presence || object.target_status&.text || object.from_account.note), length: 140)
|
2017-09-01 04:35:23 -07:00
|
|
|
end
|
|
|
|
end
|