Add `group_key` attribute to `NotificationSerializer` (#30776)

Co-authored-by: Renaud Chaput <renchap@gmail.com>
This commit is contained in:
Claire 2024-06-20 13:05:25 +02:00 committed by GitHub
parent a0910cd49c
commit 7889e983fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 1 deletions

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class REST::NotificationSerializer < ActiveModel::Serializer class REST::NotificationSerializer < ActiveModel::Serializer
attributes :id, :type, :created_at attributes :id, :type, :created_at, :group_key
belongs_to :from_account, key: :account, serializer: REST::AccountSerializer belongs_to :from_account, key: :account, serializer: REST::AccountSerializer
belongs_to :target_status, key: :status, if: :status_type?, serializer: REST::StatusSerializer belongs_to :target_status, key: :status, if: :status_type?, serializer: REST::StatusSerializer
@ -13,6 +13,10 @@ class REST::NotificationSerializer < ActiveModel::Serializer
object.id.to_s object.id.to_s
end end
def group_key
object.group_key || "ungrouped-#{object.id}"
end
def status_type? def status_type?
[:favourite, :reblog, :status, :mention, :poll, :update].include?(object.type) [:favourite, :reblog, :status, :mention, :poll, :update].include?(object.type)
end end