mirror of
https://github.com/mastodon/mastodon.git
synced 2025-02-08 16:05:05 +00:00
![Claire](/assets/img/avatar_default.png)
Some checks are pending
Check i18n / check-i18n (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
Haml Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
Historical data migration test / pre_job (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Blocked by required conditions
Historical data migration test / test (15-alpine) (push) Blocked by required conditions
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.1) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / Libvips tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.1) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.1) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.1, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
38 lines
1.3 KiB
Ruby
38 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class NotificationGroup < ActiveModelSerializers::Model
|
|
attributes :group_key, :sample_accounts, :notifications_count, :notification, :most_recent_notification_id
|
|
|
|
def self.from_notification(notification, max_id: nil)
|
|
if notification.group_key.present?
|
|
# TODO: caching and preloading
|
|
scope = notification.account.notifications.where(group_key: notification.group_key)
|
|
scope = scope.where(id: ..max_id) if max_id.present?
|
|
|
|
most_recent_notifications = scope.order(id: :desc).take(3)
|
|
most_recent_id = most_recent_notifications.first.id
|
|
sample_accounts = most_recent_notifications.map(&:from_account)
|
|
notifications_count = scope.count
|
|
else
|
|
most_recent_id = notification.id
|
|
sample_accounts = [notification.from_account]
|
|
notifications_count = 1
|
|
end
|
|
|
|
NotificationGroup.new(
|
|
notification: notification,
|
|
group_key: notification.group_key || "ungrouped-#{notification.id}",
|
|
sample_accounts: sample_accounts,
|
|
notifications_count: notifications_count,
|
|
most_recent_notification_id: most_recent_id
|
|
)
|
|
end
|
|
|
|
delegate :type,
|
|
:target_status,
|
|
:report,
|
|
:account_relationship_severance_event,
|
|
:account_warning,
|
|
to: :notification, prefix: false
|
|
end
|