DEV: Prioritize unread notifications in the experimental user menu (#18216)

Right now the experimental user menu sorts notifications the same way that the old menu does: unread high-priority notifications are shown first in reverse-chronological order followed by everything else also in reverse-chronological order. However, since the experimental user menu has dedicated tabs for some notification types and each tab displays a badge with the count of unread notifications in the tab, we feel like it makes sense to change how notifications are sorted in the experimental user menu to this:

1. unread high-priority notifications
2. unread regular notifications
3. all read notifications (both high-priority and regular)
4. within each group, notifications are sorted in reverse-chronological order (i.e. newest is shown first).

This new sorting logic applies to all tabs in the experimental user menu, however it doesn't change anything in the old menu. With this change, if a tab in the experimental user menu shows an unread notification badge for a really old notification, it will be surfaced to the top and prevents confusing scenarios where a user sees an unread notification badge on a tab, but the tab doesn't show the unread notification because it's too old to make it to the list.

Internal topic: t72199.
This commit is contained in:
Osama Sayegh
2022-09-12 21:19:25 +03:00
committed by GitHub
parent 321aa4b4b4
commit 1fa21ed415
6 changed files with 256 additions and 13 deletions

View File

@ -30,18 +30,17 @@ class NotificationsController < ApplicationController
limit = (params[:limit] || 15).to_i
limit = 50 if limit > 50
notifications = Notification.recent_report(current_user, limit, notification_types)
changed = false
if notifications.present? && !(params.has_key?(:silent) || @readonly_mode)
# ordering can be off due to PMs
max_id = notifications.map(&:id).max
changed = current_user.saw_notification_id(max_id)
if SiteSetting.enable_experimental_sidebar_hamburger
notifications = Notification.prioritized_list(current_user, count: limit, types: notification_types)
else
notifications = Notification.recent_report(current_user, limit, notification_types)
end
if changed
current_user.reload
current_user.publish_notifications_state
if notifications.present? && !(params.has_key?(:silent) || @readonly_mode)
if changed = current_user.bump_last_seen_notification!
current_user.reload
current_user.publish_notifications_state
end
end
if !params.has_key?(:silent) && params[:bump_last_seen_reviewable] && !@readonly_mode
@ -103,7 +102,7 @@ class NotificationsController < ApplicationController
end
Notification.read_types(current_user, types)
current_user.saw_notification_id(Notification.recent_report(current_user, 1).max.try(:id))
current_user.bump_last_seen_notification!
end
current_user.reload