From e624b7198dbff56cae33ada62bf5b51cff8138fa Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 2 Sep 2015 14:29:53 -0400 Subject: [PATCH] Try to estimate the amount of notifications to return based on height --- .../javascripts/discourse/components/user-menu.js.es6 | 6 +++++- app/controllers/notifications_controller.rb | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/components/user-menu.js.es6 b/app/assets/javascripts/discourse/components/user-menu.js.es6 index a6a7e46be88..b60a0eb8282 100644 --- a/app/assets/javascripts/discourse/components/user-menu.js.es6 +++ b/app/assets/javascripts/discourse/components/user-menu.js.es6 @@ -1,5 +1,6 @@ import { url } from 'discourse/lib/computed'; import { default as computed, observes } from 'ember-addons/ember-computed-decorators'; +import { headerHeight } from 'discourse/views/header'; export default Ember.Component.extend({ classNames: ['user-menu'], @@ -43,10 +44,13 @@ export default Ember.Component.extend({ refreshNotifications() { if (this.get('loadingNotifications')) { return; } + // estimate (poorly) the amount of notifications to return + const limit = Math.round(($(window).height() - headerHeight()) / 50); + // TODO: It's a bit odd to use the store in a component, but this one really // wants to reach out and grab notifications const store = this.container.lookup('store:main'); - const stale = store.findStale('notification', {recent: true}); + const stale = store.findStale('notification', {recent: true, limit }); if (stale.hasResults) { this.set('notifications', stale.results); diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 407d63ce2d2..53e26afda2d 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -7,7 +7,11 @@ class NotificationsController < ApplicationController def index user = current_user if params[:recent].present? - notifications = Notification.recent_report(current_user, 15) + + limit = params[:limit].to_i || 15 + limit = 50 if limit > 50 + + notifications = Notification.recent_report(current_user, limit) if notifications.present? # ordering can be off due to PMs