mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 00:43:24 +08:00
b7b61d4b56
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.
37 lines
753 B
Ruby
37 lines
753 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Notifications
|
|
class ConsolidationPlan
|
|
def set_precondition(precondition_blk: nil)
|
|
@precondition_blk = precondition_blk
|
|
|
|
self
|
|
end
|
|
|
|
def set_mutations(set_data_blk: nil)
|
|
@set_data_blk = set_data_blk
|
|
|
|
self
|
|
end
|
|
|
|
def can_consolidate_data?(_notification)
|
|
raise NotImplementedError
|
|
end
|
|
|
|
def consolidate_or_save!(_notification)
|
|
raise NotImplementedError
|
|
end
|
|
|
|
protected
|
|
|
|
def consolidated_data(notification)
|
|
return notification.data_hash if @set_data_blk.nil?
|
|
@set_data_blk.call(notification)
|
|
end
|
|
|
|
def user_notifications(notification, type)
|
|
notification.user.notifications.where(notification_type: type)
|
|
end
|
|
end
|
|
end
|