1
0
mirror of https://github.com/mastodon/mastodon synced 2024-12-21 10:08:13 +09:00
mastodon/app/serializers/web/notification_serializer.rb
renovate[bot] 3ed9b55cb3
Update dependency rubocop-rails to v2.20.1 (#25493)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Renaud Chaput <renchap@gmail.com>
2023-07-13 11:44:02 +02:00

40 lines
1.1 KiB
Ruby

# frozen_string_literal: true
class Web::NotificationSerializer < ActiveModel::Serializer
include RoutingHelper
include ActionView::Helpers::TextHelper
include ActionView::Helpers::SanitizeHelper
attributes :access_token, :preferred_locale, :notification_id,
:notification_type, :icon, :title, :body
def access_token
current_push_subscription.associated_access_token
end
def preferred_locale
current_push_subscription.associated_user&.locale || I18n.default_locale
end
def notification_id
object.id
end
def notification_type
object.type
end
def icon
full_asset_url(object.from_account.avatar_static_url)
end
def title
I18n.t("notification_mailer.#{object.type}.subject", name: object.from_account.display_name.presence || object.from_account.username)
end
def body
str = strip_tags(object.target_status&.spoiler_text.presence || object.target_status&.text || object.from_account.note)
truncate(HTMLEntities.new.decode(str.to_str), length: 140, escape: false) # Do not encode entities, since this value will not be used in HTML
end
end