mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 16:51:25 +08:00
Try to estimate the amount of notifications to return based on height
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
import { url } from 'discourse/lib/computed';
|
import { url } from 'discourse/lib/computed';
|
||||||
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
|
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
|
||||||
|
import { headerHeight } from 'discourse/views/header';
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
classNames: ['user-menu'],
|
classNames: ['user-menu'],
|
||||||
@ -43,10 +44,13 @@ export default Ember.Component.extend({
|
|||||||
refreshNotifications() {
|
refreshNotifications() {
|
||||||
if (this.get('loadingNotifications')) { return; }
|
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
|
// TODO: It's a bit odd to use the store in a component, but this one really
|
||||||
// wants to reach out and grab notifications
|
// wants to reach out and grab notifications
|
||||||
const store = this.container.lookup('store:main');
|
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) {
|
if (stale.hasResults) {
|
||||||
this.set('notifications', stale.results);
|
this.set('notifications', stale.results);
|
||||||
|
@ -7,7 +7,11 @@ class NotificationsController < ApplicationController
|
|||||||
def index
|
def index
|
||||||
user = current_user
|
user = current_user
|
||||||
if params[:recent].present?
|
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?
|
if notifications.present?
|
||||||
# ordering can be off due to PMs
|
# ordering can be off due to PMs
|
||||||
|
Reference in New Issue
Block a user