diff --git a/app/presenters/grouped_notifications_presenter.rb b/app/presenters/grouped_notifications_presenter.rb new file mode 100644 index 0000000000..f64d5df59b --- /dev/null +++ b/app/presenters/grouped_notifications_presenter.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +class GroupedNotificationsPresenter < ActiveModelSerializers::Model + def initialize(grouped_notifications) + super() + + @grouped_notifications = grouped_notifications + end + + def notification_groups + @grouped_notifications + end + + def statuses + @grouped_notifications.filter_map(&:target_status) + end + + def accounts + @grouped_notifications.flat_map do |group| + accounts = group.sample_accounts.dup + + case group.type + when :favourite, :reblog, :status, :mention, :poll, :update + accounts << group.target_status&.account + when :'admin.report' + accounts << group.report&.target_account + when :moderation_warning + accounts << group.account_warning&.target_account + end + + accounts.compact + end.uniq(&:id) + end +end diff --git a/app/serializers/rest/dedup_notification_group_serializer.rb b/app/serializers/rest/dedup_notification_group_serializer.rb new file mode 100644 index 0000000000..5491950c25 --- /dev/null +++ b/app/serializers/rest/dedup_notification_group_serializer.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class REST::DedupNotificationGroupSerializer < ActiveModel::Serializer + has_many :accounts, serializer: REST::Shallow::AccountSerializer + has_many :statuses, serializer: REST::Shallow::StatusSerializer + has_many :notification_groups, serializer: REST::Shallow::NotificationGroupSerializer +end