Refactoring marking feeds as read to better handle direction.

This commit is contained in:
Samuel Clay 2017-01-09 14:19:19 -08:00
parent c9ba9d9b22
commit 183176a494
4 changed files with 56 additions and 43 deletions

View file

@ -284,7 +284,7 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
this.make_request('/reader/starred_counts', {}, pre_callback, pre_callback, {request_type: 'GET'});
},
mark_feed_as_read: function(feed_id, cutoff_timestamp, direction, mark_active, callback) {
mark_feed_as_read: function(feed_id, cutoff_timestamp, direction, callback) {
var self = this;
var feed_ids = _.isArray(feed_id)
? _.select(feed_id, function(f) { return f; })
@ -296,32 +296,32 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
direction: direction
}, callback);
if (mark_active) {
this.stories.each(function(story) {
if ((!direction || direction == "older") &&
cutoff_timestamp &&
parseInt(story.get('story_timestamp'), 10) > cutoff_timestamp) {
return;
} else if (direction == "newer" &&
cutoff_timestamp &&
parseInt(story.get('story_timestamp'), 10) < cutoff_timestamp) {
return;
this.stories.each(function(story) {
if (direction == "older" &&
cutoff_timestamp &&
story.get('story_timestamp') > cutoff_timestamp) {
return;
} else if (direction == "newer" &&
cutoff_timestamp &&
story.get('story_timestamp') < cutoff_timestamp) {
return;
}
if (!story.get('read_status')) {
story.set('read_status', true);
var score = story.score();
var feed = self.get_feed(story.get('story_feed_id'));
if (!feed) return;
if (score > 0) {
feed.set('ps', feed.get('ps') - 1);
} else if (score == 0) {
feed.set('nt', feed.get('nt') - 1);
} else if (score < 0) {
feed.set('ng', feed.get('ng') - 1);
}
if (!story.get('read_status')) {
story.set('read_status', true);
var score = story.score();
var feed = self.get_feed(story.get('story_feed_id'));
if (!feed) return;
if (score > 0) {
feed.set('ps', feed.get('ps') - 1);
} else if (score == 0) {
feed.set('nt', feed.get('nt') - 1);
} else if (score < 0) {
feed.set('ng', feed.get('ng') - 1);
}
}
});
} else {
}
});
if (!cutoff_timestamp) {
_.each(feed_ids, function(feed_id) {
var feed = self.get_feed(feed_id);
if (!feed) return;

View file

@ -52,11 +52,23 @@ NEWSBLUR.Models.FeedOrFolder = Backbone.Model.extend({
return view;
},
feed_ids_in_folder: function(include_inactive) {
if (this.is_feed() && (include_inactive || (!include_inactive && this.feed.get('active')))) {
return this.feed.id;
feed_ids_in_folder: function(options) {
options = options || {};
if (this.is_feed()) {
if (options.include_inactive) {
return this.feed.id;
}
if (options.unread_only) {
var counts = this.feed.unread_counts();
if (counts.ps + counts.nt + counts.ng > 0) {
return this.feed.id;
}
}
if (this.feed.get('active')) {
return this.feed.id;
}
} else if (this.is_folder()) {
return this.folders.feed_ids_in_folder(include_inactive);
return this.folders.feed_ids_in_folder(options);
}
},
@ -219,9 +231,10 @@ NEWSBLUR.Collections.Folders = Backbone.Collection.extend({
return names;
},
feed_ids_in_folder: function(include_inactive) {
feed_ids_in_folder: function(options) {
options = options || {};
return _.compact(_.flatten(this.map(function(item) {
return item.feed_ids_in_folder(include_inactive);
return item.feed_ids_in_folder(options);
})));
},

View file

@ -2330,7 +2330,7 @@
mark_folder_as_read: function(folder, days_back, direction) {
var folder = folder || this.active_folder;
var feeds = folder.feed_ids_in_folder();
var feeds = folder.feed_ids_in_folder({unreads_only: true});
this.mark_feeds_as_read(feeds, days_back, direction);
@ -2349,15 +2349,15 @@
order == 'newest') {
cutoff_timestamp = this.model.stories.first().get('story_timestamp');
}
var mark_active = false;
if ((order == 'newest' && direction == 'newer') || (order == 'oldest' && direction == 'older')) {
mark_active = true;
}
this.model.mark_feed_as_read(feeds, cutoff_timestamp, direction,
mark_active, _.bind(function() {
if (!this.socket || !this.socket || !this.socket.connected) {
this.force_feeds_refresh(null, false, feeds);
_.bind(function() {
if (feeds.length == 1) {
this.feed_unread_count(feeds[0]);
} else {
if (!this.socket || !this.socket || !this.socket.connected) {
this.force_feeds_refresh(null, false, feeds);
}
}
}, this));
},
@ -6696,9 +6696,9 @@
if (order == 'oldest') direction = 'newer';
if (self.flags.river_view && !self.flags.social_view) {
self.mark_folder_as_read(self.active_folder, timestamp, order);
self.mark_folder_as_read(self.active_folder, timestamp, direction);
} else {
self.mark_feed_as_read(self.active_feed, timestamp, order);
self.mark_feed_as_read(self.active_feed, timestamp, direction);
}
});
$document.bind('keydown', 'm', function(e) {

View file

@ -242,7 +242,7 @@ _.extend(NEWSBLUR.ReaderFeedchooser.prototype, {
make_feeds: function() {
var feeds = this.model.feeds;
this.feed_count = _.unique(NEWSBLUR.assets.folders.feed_ids_in_folder(true)).length;
this.feed_count = _.unique(NEWSBLUR.assets.folders.feed_ids_in_folder({include_inactive: true})).length;
this.feedlist = new NEWSBLUR.Views.FeedList({
feed_chooser: true,