REFACTOR: Improve support for consolidating notifications. (PR #14904)

Before this commit, we didn’t have a single way of consolidating notifications. For notifications like group summaries, we manually removed old ones before creating a new one. On the other hand, we used an after_create callback for likes and group membership requests, which caused unnecessary work, as we need to delete the record we created to replace it with a consolidated one.

We now have all the consolidation rules centralized in a single place: the consolidation planner class. Other parts of the app looking to create a consolidable notification can do so by calling Notification#consolidate_or_save!, instead of the default Notification#create! method.

Finally, we added two more rules: one for re-using existing group summaries and another for deleting duplicated dashboard problems PMs notifications when the user is tracking the moderator’s inbox. Setting the threshold to one forces the planner to apply this rule every time.

I plan to add plugin support for adding custom rules in another PR to keep this one relatively small.

GitHub

I would recommend using keyword arguments here, since there are quite a few parameters and it should make it easier to reason about what is passed in at the call sites.

Looks very nice. A big improvement.

Incredibly minor but this seems too indented to me?

Does it make sense to add a test for custom plans, as a means of demonstrating the API and keeping it stable?

I support merging this, I like a lot that the logic of consolidating is no longer a hijack for notification creation, also like that there is a new consolidator class. Anything holding us back from merging (my comment can wait for another followup PR)

Yes, definitely. I just added the test.

I support merging this, I like a lot that the logic of consolidating is no longer a hijack for notification creation, also like that there is a new consolidator class. Anything holding us back from merging (my comment can wait for another followup PR)

I wanted to open PRs both for discourse-code-review and discourse-reactions before merging this one. Will merge soon!