FIX: Always ensure notifications are treated as read once clicked

UX: improve messaging so notifications list is far more stable
PERF: improve performance of notifcation lookup queries

- Add feature "SetTransientHeader" that allows shipping info to server
   in the next Ajax request
- remove local storage hack used for notifications
- amend lookupStale to return hydrated objects, move logic into store
- stop magically clearing various notifications (likes, invitee accepted, group_summary, granted badge)
This commit is contained in:
Sam
2016-02-15 19:29:35 +11:00
parent 1f062ae2fd
commit dd6ebde824
15 changed files with 203 additions and 86 deletions

View File

@ -33,6 +33,7 @@ class ApplicationController < ActionController::Base
end
before_filter :set_current_user_for_logs
before_filter :clear_notifications
before_filter :set_locale
before_filter :set_mobile_view
before_filter :inject_preview_style
@ -137,6 +138,28 @@ class ApplicationController < ActionController::Base
response.headers["X-Discourse-Route"] = "#{controller_name}/#{action_name}"
end
def clear_notifications
if current_user && !Discourse.readonly_mode?
cookie_notifications = cookies['cn'.freeze]
notifications = request.headers['Discourse-Clear-Notifications'.freeze]
if cookie_notifications
if notifications.present?
notifications += "," << cookie_notifications
else
notifications = cookie_notifications
end
end
if notifications.present?
notification_ids = notifications.split(",").map(&:to_i)
Notification.where(user_id: current_user.id, id: notification_ids).update_all(read: true)
cookies.delete('cn')
end
end
end
def set_locale
I18n.locale = current_user.try(:effective_locale) || SiteSetting.default_locale
I18n.ensure_all_loaded!