Filling out dashboard stories to handle hidden stories. Needs focus stories handling and marking read elsewhere.

This commit is contained in:
Samuel Clay 2016-12-01 14:27:18 -08:00
parent 587e7fb2a6
commit 11b3a1edff
6 changed files with 50 additions and 19 deletions

View file

@ -277,7 +277,7 @@ class UserSubscription(models.Model):
feed_ids = []
if not all_feed_ids:
all_feed_ids = [f for f in feed_ids]
# feeds_string = ""
feeds_string = ','.join(str(f) for f in sorted(all_feed_ids))[:30]
ranked_stories_keys = '%szU:%s:feeds:%s' % (cache_prefix, user_id, feeds_string)
@ -285,7 +285,7 @@ class UserSubscription(models.Model):
stories_cached = rt.exists(ranked_stories_keys)
unreads_cached = True if read_filter == "unread" else rt.exists(unread_ranked_stories_keys)
if offset and stories_cached and unreads_cached:
story_hashes = range_func(ranked_stories_keys, offset, limit)
story_hashes = range_func(ranked_stories_keys, offset, offset+limit)
if read_filter == "unread":
unread_story_hashes = story_hashes
else:

View file

@ -1212,7 +1212,7 @@ def load_read_stories(request):
@json.json_view
def load_river_stories__redis(request):
limit = request.REQUEST.get('limit', 12)
limit = int(request.REQUEST.get('limit', 12))
start = time.time()
user = get_user(request)
message = None
@ -1231,9 +1231,8 @@ def load_river_stories__redis(request):
usersubs = []
code = 1
user_search = None
offset = (page-1) * limit
limit = page * limit
story_date_order = "%sstory_date" % ('' if order == 'oldest' else '-')
offset = (page-1) * limit
story_date_order = "%sstory_date" % ('' if order == 'oldest' else '-')
if story_hashes:
unread_feed_story_hashes = None

View file

@ -692,21 +692,27 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
},
fetch_dashboard_stories: function(feed_id, feeds, callback, error_callback) {
fetch_dashboard_stories: function(feed_id, feeds, page, callback, error_callback) {
var self = this;
var pre_callback = function(data) {
if (!NEWSBLUR.Globals.is_premium && NEWSBLUR.Globals.is_authenticated) {
data.stories = data.stories.splice(0, 3);
}
self.dashboard_stories.reset(data.stories, {added: data.stories.length});
// console.log(['dashboard stories fetch', self.dashboard_stories.length, self.stories.length]);
if (page > 1) {
self.dashboard_stories.add(data.stories, {silent: true});
self.dashboard_stories.trigger('add', {added: data.stories.length});
} else {
self.dashboard_stories.reset(data.stories, {added: data.stories.length});
}
callback();
};
this.make_request('/reader/river_stories', {
feeds: feeds,
limit: 4,
page: page,
order: this.view_setting(feed_id, 'order'),
read_filter: this.view_setting(feed_id, 'read_filter'),
include_hidden: false

View file

@ -17,18 +17,14 @@ NEWSBLUR.Views.DashboardRiver = Backbone.View.extend({
override_layout: 'split',
on_dashboard: true
});
this.page = 1;
NEWSBLUR.assets.feeds.bind('reset', _.bind(this.load_stories, this));
},
// ==========
// = Events =
// ==========
load_stories: function() {
// var feeds = NEWSBLUR.assets.folders.feed_ids_in_folder();
var visible_only = NEWSBLUR.assets.view_setting(this.active_feed, 'read_filter') == 'unread';
feeds: function() {
var feeds;
var visible_only = NEWSBLUR.assets.view_setting(this.active_feed, 'read_filter') == 'unread';
if (visible_only) {
feeds = _.pluck(this.active_folder.feeds_with_unreads(), 'id');
if (!feeds.length) {
@ -38,13 +34,36 @@ NEWSBLUR.Views.DashboardRiver = Backbone.View.extend({
feeds = this.active_folder.feed_ids_in_folder();
}
return feeds;
},
// ==========
// = Events =
// ==========
load_stories: function() {
// var feeds = NEWSBLUR.assets.folders.feed_ids_in_folder();
var feeds = this.feeds();
this.page = 1;
this.story_titles.show_loading();
NEWSBLUR.assets.fetch_dashboard_stories("river:", feeds,
NEWSBLUR.assets.fetch_dashboard_stories("river:", feeds, this.page,
_.bind(this.post_load_stories, this), NEWSBLUR.app.taskbar_info.show_stories_error);
},
post_load_stories: function() {
this.fill_out();
},
fill_out: function() {
var visible = NEWSBLUR.assets.dashboard_stories.visible().length;
if (visible >= 5 || this.page > 10) return;
var feeds = this.feeds();
this.page += 1;
this.story_titles.show_loading();
NEWSBLUR.assets.fetch_dashboard_stories("river:", feeds, this.page,
_.bind(this.post_load_stories, this), NEWSBLUR.app.taskbar_info.show_stories_error);
}
});

View file

@ -462,7 +462,7 @@ NEWSBLUR.Views.StoryTitleView = Backbone.View.extend({
if (e.which == 1 && $('.NB-menu-manage-container:visible').length) return;
if (this.options.on_dashboard) {
console.log(['clicked story', this.model]);
// console.log(['clicked story', this.model]);
NEWSBLUR.reader.open_river_stories(null, null, {story_id: this.model.id});
return;
}

View file

@ -58,6 +58,7 @@ NEWSBLUR.Views.StoryTitlesView = Backbone.View.extend({
// console.log(['add story_titles', options]);
var collection = this.collection;
if (options.added) {
var on_dashboard = this.options.on_dashboard;
var story_layout = this.options.override_layout ||
NEWSBLUR.assets.view_setting(NEWSBLUR.reader.active_feed, 'layout');
var stories = _.compact(_.map(this.collection.models.slice(-1 * options.added), function(story) {
@ -65,7 +66,9 @@ NEWSBLUR.Views.StoryTitlesView = Backbone.View.extend({
return new NEWSBLUR.Views.StoryTitleView({
model: story,
collection: collection,
is_grid: story_layout == 'grid'
is_grid: story_layout == 'grid',
override_layout: story_layout,
on_dashboard: on_dashboard
}).render();
}));
this.stories = this.stories.concat(stories);
@ -73,6 +76,10 @@ NEWSBLUR.Views.StoryTitlesView = Backbone.View.extend({
return story.el;
});
this.$el.append($stories);
if (this.options.on_dashboard) {
var $extras = this.$el.find('.NB-story-title-container').slice(5);
$extras.addClass('NB-hidden');
}
}
this.end_loading();
this.fill_out();