mirror of https://github.com/mastodon/mastodon
Add `most_recent_notification_id` to `NotificationGroup` (#30707)
This commit is contained in:
parent
b5d1d48266
commit
8eb27c60e1
|
@ -1,14 +1,17 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class NotificationGroup < ActiveModelSerializers::Model
|
class NotificationGroup < ActiveModelSerializers::Model
|
||||||
attributes :group_key, :sample_accounts, :notifications_count, :notification
|
attributes :group_key, :sample_accounts, :notifications_count, :notification, :most_recent_notification_id
|
||||||
|
|
||||||
def self.from_notification(notification)
|
def self.from_notification(notification)
|
||||||
if notification.group_key.present?
|
if notification.group_key.present?
|
||||||
# TODO: caching and preloading
|
# TODO: caching and preloading
|
||||||
sample_accounts = notification.account.notifications.where(group_key: notification.group_key).order(id: :desc).limit(3).map(&:from_account)
|
most_recent_notifications = notification.account.notifications.where(group_key: notification.group_key).order(id: :desc).take(3)
|
||||||
|
most_recent_id = most_recent_notifications.first.id
|
||||||
|
sample_accounts = most_recent_notifications.map(&:from_account)
|
||||||
notifications_count = notification.account.notifications.where(group_key: notification.group_key).count
|
notifications_count = notification.account.notifications.where(group_key: notification.group_key).count
|
||||||
else
|
else
|
||||||
|
most_recent_id = notification.id
|
||||||
sample_accounts = [notification.from_account]
|
sample_accounts = [notification.from_account]
|
||||||
notifications_count = 1
|
notifications_count = 1
|
||||||
end
|
end
|
||||||
|
@ -17,7 +20,8 @@ class NotificationGroup < ActiveModelSerializers::Model
|
||||||
notification: notification,
|
notification: notification,
|
||||||
group_key: notification.group_key || "ungrouped-#{notification.id}",
|
group_key: notification.group_key || "ungrouped-#{notification.id}",
|
||||||
sample_accounts: sample_accounts,
|
sample_accounts: sample_accounts,
|
||||||
notifications_count: notifications_count
|
notifications_count: notifications_count,
|
||||||
|
most_recent_notification_id: most_recent_id
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class REST::NotificationGroupSerializer < ActiveModel::Serializer
|
class REST::NotificationGroupSerializer < ActiveModel::Serializer
|
||||||
attributes :group_key, :notifications_count, :type
|
attributes :group_key, :notifications_count, :type, :most_recent_notification_id
|
||||||
|
|
||||||
attribute :page_min_id, if: :paginated?
|
attribute :page_min_id, if: :paginated?
|
||||||
attribute :page_max_id, if: :paginated?
|
attribute :page_max_id, if: :paginated?
|
||||||
|
|
Loading…
Reference in New Issue