FEATURE: A notification consolidation plan for keeping the latest one. (#15249)

We previously used ConsolidateNotifications with a threshold of 1 to re-use an existing notification and bump it to the top instead of creating a new one. It produces some jumpiness in the user notification list, and it relies on updating the `created_at` attribute, which is a bit hacky.

As a better alternative, we're introducing a new plan that deletes all the previous versions of the notification, then creates a new one.
This commit is contained in:
Roman Rizzi
2021-12-10 10:32:15 -03:00
committed by GitHub
parent 3602f83cf4
commit b7b61d4b56
7 changed files with 106 additions and 83 deletions

View File

@ -986,10 +986,11 @@ class Plugin::Instance
#
# The rule object is quite complex. We strongly recommend you write tests to ensure your plugin consolidates notifications correctly.
#
# - Plan's documentation: https://github.com/discourse/discourse/blob/main/app/services/notifications/consolidate_notifications.rb
# - Threshold and time window consolidation plan: https://github.com/discourse/discourse/blob/main/app/services/notifications/consolidate_notifications.rb
# - Create a new notification and delete previous versions plan: https://github.com/discourse/discourse/blob/main/app/services/notifications/delete_previous_notifications.rb
# - Base plans: https://github.com/discourse/discourse/blob/main/app/services/notifications/consolidation_planner.rb
def register_notification_consolidation_plan(plan)
raise ArgumentError.new("Not a consolidation plan") if plan.class != Notifications::ConsolidateNotifications
raise ArgumentError.new("Not a consolidation plan") if !plan.class.ancestors.include?(Notifications::ConsolidationPlan)
DiscoursePluginRegistry.register_notification_consolidation_plan(plan, self)
end