2016-11-29 17:26:17 -08:00
|
|
|
NEWSBLUR.Views.DashboardRiver = Backbone.View.extend({
|
|
|
|
|
|
|
|
el: ".NB-module-river",
|
|
|
|
|
|
|
|
events: {
|
|
|
|
"click .NB-module-search-add-url" : "add_url"
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function() {
|
2016-11-30 20:06:24 -08:00
|
|
|
this.$stories = this.$(".NB-module-item .NB-story-titles");
|
2020-07-14 16:41:07 -04:00
|
|
|
console.log('dashboard stories', this.options.el, this.$stories, this.options);
|
2016-11-29 17:26:17 -08:00
|
|
|
this.story_titles = new NEWSBLUR.Views.StoryTitlesView({
|
2016-11-30 18:53:32 -08:00
|
|
|
el: this.$stories,
|
2020-07-14 16:41:07 -04:00
|
|
|
collection: this.options.dashboard_stories,
|
2016-11-30 17:55:25 -08:00
|
|
|
$story_titles: this.$stories,
|
2016-11-30 18:53:32 -08:00
|
|
|
override_layout: 'split',
|
2020-07-15 11:51:03 -04:00
|
|
|
on_dashboard: this
|
2016-11-29 17:26:17 -08:00
|
|
|
});
|
2016-12-01 14:27:18 -08:00
|
|
|
this.page = 1;
|
2016-12-01 15:06:19 -08:00
|
|
|
this.cache = {
|
|
|
|
story_hashes: []
|
|
|
|
};
|
2016-11-29 17:26:17 -08:00
|
|
|
|
2020-07-14 16:41:07 -04:00
|
|
|
if (this.options.active_feed == "river:infrequent") {
|
|
|
|
this.options.infrequent = NEWSBLUR.assets.preference('infrequent_stories_per_month');
|
|
|
|
} else if (this.options.active_feed == "river:global") {
|
|
|
|
this.options.global_feed = true;
|
|
|
|
}
|
|
|
|
|
2016-11-29 17:26:17 -08:00
|
|
|
NEWSBLUR.assets.feeds.bind('reset', _.bind(this.load_stories, this));
|
2016-12-01 15:06:19 -08:00
|
|
|
NEWSBLUR.assets.stories.bind('change:read_status', this.check_read_stories, this);
|
2016-12-01 16:22:51 -08:00
|
|
|
// NEWSBLUR.assets.stories.bind('change:selected', this.check_read_stories, this);
|
2017-01-03 18:14:54 -08:00
|
|
|
|
|
|
|
this.setup_dashboard_refresh();
|
2016-11-29 17:26:17 -08:00
|
|
|
},
|
2020-12-09 18:20:55 -05:00
|
|
|
|
|
|
|
options_template: function () {
|
|
|
|
var $options = $(_.template('<div class="NB-feedbar-options-container">\
|
|
|
|
<span class="NB-feedbar-options">\
|
|
|
|
<div class="NB-icon"></div>\
|
|
|
|
<%= NEWSBLUR.assets.view_setting(feed_id, "read_filter") %>\
|
|
|
|
·\
|
|
|
|
<%= NEWSBLUR.assets.view_setting(feed_id, "order") %>\
|
|
|
|
</span>\
|
|
|
|
</div>'), {
|
|
|
|
feed_id: this.options.active_feed
|
|
|
|
});
|
|
|
|
|
2020-12-10 12:32:20 -05:00
|
|
|
this.$(".NB-module-river-settings").html($options);
|
2020-12-09 18:20:55 -05:00
|
|
|
},
|
2016-11-29 17:26:17 -08:00
|
|
|
|
2016-12-01 14:27:18 -08:00
|
|
|
feeds: function() {
|
2016-12-01 12:47:01 -08:00
|
|
|
var feeds;
|
2020-07-14 16:41:07 -04:00
|
|
|
var visible_only = NEWSBLUR.assets.view_setting(this.options.active_feed, 'read_filter') == 'unread';
|
2016-12-01 12:47:01 -08:00
|
|
|
if (visible_only) {
|
2020-07-14 16:41:07 -04:00
|
|
|
feeds = _.pluck(this.options.active_folder.feeds_with_unreads(), 'id');
|
2016-12-01 12:47:01 -08:00
|
|
|
if (!feeds.length) {
|
2020-07-14 16:41:07 -04:00
|
|
|
feeds = this.options.active_folder.feed_ids_in_folder();
|
2016-12-01 12:47:01 -08:00
|
|
|
}
|
|
|
|
} else {
|
2020-07-14 16:41:07 -04:00
|
|
|
feeds = this.options.active_folder.feed_ids_in_folder();
|
2016-12-01 12:47:01 -08:00
|
|
|
}
|
|
|
|
|
2016-12-01 14:27:18 -08:00
|
|
|
return feeds;
|
|
|
|
},
|
|
|
|
|
2017-01-03 18:14:54 -08:00
|
|
|
// ===========
|
|
|
|
// = Refresh =
|
|
|
|
// ===========
|
|
|
|
|
|
|
|
setup_dashboard_refresh: function() {
|
2017-01-11 12:33:52 -08:00
|
|
|
// if (NEWSBLUR.Globals.debug) return;
|
2017-01-03 18:14:54 -08:00
|
|
|
|
2017-01-11 12:33:52 -08:00
|
|
|
// Reload dashboard graphs every N minutes.
|
2017-01-05 10:14:44 -08:00
|
|
|
// var reload_interval = NEWSBLUR.Globals.is_staff ? 60*1000 : 10*60*1000;
|
2017-01-11 12:33:52 -08:00
|
|
|
var reload_interval = 60*60*1000;
|
|
|
|
// console.log(['setup_dashboard_refresh', this.refresh_interval]);
|
|
|
|
|
|
|
|
clearTimeout(this.refresh_interval);
|
|
|
|
this.refresh_interval = setTimeout(_.bind(function() {
|
2020-07-14 16:41:07 -04:00
|
|
|
if (NEWSBLUR.reader.active_feed == this.options.active_feed) {
|
2017-01-22 15:55:52 -08:00
|
|
|
// Currently reading the river, so don't reload because it'll break the cache.
|
|
|
|
console.log(['Currently reading river, so not reloading dashboard river', NEWSBLUR.reader.active_feed]);
|
|
|
|
this.setup_dashboard_refresh();
|
|
|
|
} else {
|
|
|
|
this.load_stories();
|
|
|
|
}
|
2017-01-03 18:14:54 -08:00
|
|
|
}, this), reload_interval * (Math.random() * (1.25 - 0.75) + 0.75));
|
|
|
|
},
|
|
|
|
|
2016-12-01 14:27:18 -08:00
|
|
|
// ==========
|
|
|
|
// = Events =
|
|
|
|
// ==========
|
|
|
|
|
2016-12-13 17:41:56 -08:00
|
|
|
load_stories: function(options) {
|
2020-07-14 16:41:07 -04:00
|
|
|
options = _.extend({
|
|
|
|
global_feed: this.options.global_feed,
|
|
|
|
infrequent: this.options.infrequent,
|
|
|
|
query: this.options.query,
|
|
|
|
}, options || {});
|
2016-12-13 17:41:56 -08:00
|
|
|
if (options.feed_selector) return;
|
2016-12-01 14:27:18 -08:00
|
|
|
// var feeds = NEWSBLUR.assets.folders.feed_ids_in_folder();
|
|
|
|
var feeds = this.feeds();
|
2016-12-01 16:54:13 -08:00
|
|
|
if (!feeds.length) return;
|
2016-12-01 18:05:41 -08:00
|
|
|
if (!this.$stories.length) return;
|
2020-07-14 16:41:07 -04:00
|
|
|
console.log(['dashboard river load_stories', this.page, feeds.length, options]);
|
2016-12-01 14:27:18 -08:00
|
|
|
this.page = 1;
|
2016-11-29 17:26:17 -08:00
|
|
|
this.story_titles.show_loading();
|
2020-07-14 16:41:07 -04:00
|
|
|
NEWSBLUR.assets.fetch_dashboard_stories(this.options.active_feed, feeds, this.page, this.options.dashboard_stories, options,
|
2016-11-29 17:26:17 -08:00
|
|
|
_.bind(this.post_load_stories, this), NEWSBLUR.app.taskbar_info.show_stories_error);
|
2017-01-11 12:33:52 -08:00
|
|
|
|
|
|
|
this.setup_dashboard_refresh();
|
2016-11-29 17:26:17 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
post_load_stories: function() {
|
2016-12-01 14:27:18 -08:00
|
|
|
this.fill_out();
|
2020-07-14 16:41:07 -04:00
|
|
|
this.cache.story_hashes = this.options.dashboard_stories.pluck('story_hash');
|
2016-12-01 14:27:18 -08:00
|
|
|
},
|
|
|
|
|
2020-07-14 16:41:07 -04:00
|
|
|
fill_out: function(options) {
|
|
|
|
options = _.extend({
|
|
|
|
global_feed: this.options.global_feed,
|
|
|
|
infrequent: this.options.infrequent,
|
|
|
|
query: this.options.query
|
|
|
|
}, options || {});
|
|
|
|
|
|
|
|
if (this.options.dashboard_stories.length == 0) {
|
|
|
|
this.show_end_line();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var visible = this.options.dashboard_stories.visible().length;
|
|
|
|
console.log("Visible", visible, options)
|
2016-12-01 14:51:53 -08:00
|
|
|
if (visible >= 3 && !NEWSBLUR.Globals.is_premium) {
|
|
|
|
this.story_titles.check_premium_river();
|
2017-01-12 14:35:43 -08:00
|
|
|
this.complete_fill();
|
2016-12-01 14:51:53 -08:00
|
|
|
return;
|
|
|
|
}
|
2017-01-12 13:16:34 -08:00
|
|
|
if (visible >= 5) {
|
|
|
|
this.complete_fill();
|
|
|
|
return;
|
|
|
|
}
|
2016-12-01 16:54:13 -08:00
|
|
|
|
|
|
|
var counts = NEWSBLUR.assets.folders.unread_counts();
|
|
|
|
var unread_view = NEWSBLUR.assets.preference('unread_view');
|
|
|
|
if (unread_view >= 1) {
|
2016-12-13 16:29:42 -08:00
|
|
|
// console.log(['counts', counts['ps'], visible, this.page]);
|
2016-12-07 19:07:00 -08:00
|
|
|
if (counts['ps'] <= visible) {
|
|
|
|
this.show_end_line();
|
|
|
|
return;
|
|
|
|
}
|
2017-01-12 13:16:34 -08:00
|
|
|
if (this.page > 20) {
|
|
|
|
this.complete_fill();
|
|
|
|
return;
|
|
|
|
}
|
2016-12-01 16:54:13 -08:00
|
|
|
} else {
|
2016-12-07 19:07:00 -08:00
|
|
|
if (counts['nt'] <= visible) {
|
|
|
|
this.show_end_line();
|
|
|
|
return;
|
|
|
|
}
|
2017-01-12 13:16:34 -08:00
|
|
|
if (this.page > 20) {
|
|
|
|
this.complete_fill();
|
|
|
|
return;
|
|
|
|
}
|
2016-12-01 16:54:13 -08:00
|
|
|
}
|
2016-11-30 18:53:32 -08:00
|
|
|
|
2016-12-01 14:27:18 -08:00
|
|
|
var feeds = this.feeds();
|
|
|
|
this.page += 1;
|
|
|
|
this.story_titles.show_loading();
|
2020-07-14 16:41:07 -04:00
|
|
|
NEWSBLUR.assets.fetch_dashboard_stories(this.options.active_feed, feeds, this.page, this.options.dashboard_stories, options,
|
2016-12-01 14:27:18 -08:00
|
|
|
_.bind(this.post_load_stories, this), NEWSBLUR.app.taskbar_info.show_stories_error);
|
2016-12-01 15:06:19 -08:00
|
|
|
},
|
|
|
|
|
2016-12-01 16:22:51 -08:00
|
|
|
check_read_stories: function(story, attr) {
|
2017-01-11 12:33:52 -08:00
|
|
|
// console.log(['story read', story, story.get('story_hash'), story.get('read_status'), attr]);
|
2016-12-01 15:06:19 -08:00
|
|
|
if (!_.contains(this.cache.story_hashes, story.get('story_hash'))) return;
|
2020-07-14 16:41:07 -04:00
|
|
|
var dashboard_story = this.options.dashboard_stories.get_by_story_hash(story.get('story_hash'));
|
2016-12-01 15:06:19 -08:00
|
|
|
if (!dashboard_story) {
|
|
|
|
console.log(['Error: missing story on dashboard', story, this.cache.story_hashes]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dashboard_story.set('read_status', story.get('read_status'));
|
2016-12-01 16:22:51 -08:00
|
|
|
// dashboard_story.set('selected', false);
|
|
|
|
},
|
|
|
|
|
|
|
|
open_story: function(story) {
|
2020-07-15 11:51:03 -04:00
|
|
|
console.log('Opening dashboard story', story, this.options);
|
|
|
|
if (this.options.query) {
|
|
|
|
console.log('Saved search', NEWSBLUR.assets.searches_feeds.get(this.options.active_feed))
|
|
|
|
NEWSBLUR.reader.flags.searching = true;
|
|
|
|
NEWSBLUR.reader.flags.search = this.options.query;
|
|
|
|
NEWSBLUR.reader.open_saved_search({
|
|
|
|
search_model: NEWSBLUR.assets.searches_feeds.get(this.options.active_feed),
|
|
|
|
feed_id: this.options.active_feed,
|
|
|
|
dashboard_transfer: this.options.dashboard_stories,
|
|
|
|
story_id: story.id,
|
|
|
|
query: this.options.query
|
|
|
|
});
|
|
|
|
} else if (this.options.active_feed == "river:infrequent") {
|
|
|
|
NEWSBLUR.reader.open_river_stories(null, null, {
|
|
|
|
dashboard_transfer: this.options.dashboard_stories,
|
|
|
|
infrequent: this.options.infrequent,
|
|
|
|
story_id: story.id
|
|
|
|
});
|
|
|
|
} else if (this.options.active_feed == "river:global") {
|
|
|
|
NEWSBLUR.reader.open_river_blurblogs_stories({
|
|
|
|
global: true,
|
|
|
|
dashboard_transfer: this.options.dashboard_stories,
|
|
|
|
story_id: story.id
|
|
|
|
});
|
|
|
|
} else if (_.string.startsWith(this.options.active_feed, 'river:')) {
|
|
|
|
NEWSBLUR.reader.open_river_stories(null, null, {
|
|
|
|
dashboard_transfer: this.options.dashboard_stories,
|
|
|
|
story_id: story.id
|
|
|
|
});
|
|
|
|
}
|
2016-12-07 19:07:00 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
show_end_line: function() {
|
|
|
|
this.story_titles.show_no_more_stories();
|
|
|
|
this.$(".NB-end-line").addClass("NB-visible");
|
2016-12-13 16:29:42 -08:00
|
|
|
},
|
|
|
|
|
2017-01-12 13:16:34 -08:00
|
|
|
complete_fill: function() {
|
|
|
|
var feeds = this.feeds();
|
2020-07-14 16:41:07 -04:00
|
|
|
NEWSBLUR.assets.complete_river(this.options.active_feed, feeds, this.page);
|
2017-01-12 13:16:34 -08:00
|
|
|
},
|
|
|
|
|
2016-12-13 16:29:42 -08:00
|
|
|
new_story: function(story_hash, timestamp) {
|
2016-12-29 18:40:14 -08:00
|
|
|
var current_timestamp = Math.floor(Date.now() / 1000);
|
|
|
|
if (timestamp > (current_timestamp + 60*60)) {
|
|
|
|
console.log(['New story newer than current time + 1 hour',
|
|
|
|
(timestamp - current_timestamp)/60 + " minutes newer"]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-14 16:41:07 -04:00
|
|
|
var oldest_story = this.options.dashboard_stories.last();
|
2016-12-13 16:29:42 -08:00
|
|
|
if (oldest_story) {
|
|
|
|
var last_timestamp = parseInt(oldest_story.get('story_timestamp'), 10);
|
|
|
|
timestamp = parseInt(timestamp, 10);
|
|
|
|
|
2020-07-14 16:41:07 -04:00
|
|
|
if (NEWSBLUR.assets.view_setting(this.options.active_feed, 'order') == 'newest') {
|
2016-12-13 16:29:42 -08:00
|
|
|
if (timestamp < last_timestamp) {
|
|
|
|
// console.log(['New story older than last/oldest dashboard story', timestamp, '<', last_timestamp]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (timestamp > last_timestamp) {
|
|
|
|
// console.log(['New story older than last/newest dashboard story', timestamp, '<', last_timestamp]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-15 12:20:00 -08:00
|
|
|
var feed_id = story_hash.split(':')[0];
|
|
|
|
var feed = NEWSBLUR.assets.get_feed(feed_id);
|
2016-12-16 13:11:33 -08:00
|
|
|
if (!feed) {
|
|
|
|
console.log(["Can't fetch dashboard story, no feed", feed_id]);
|
|
|
|
return;
|
|
|
|
}
|
2016-12-15 12:20:00 -08:00
|
|
|
var subs = feed.get('num_subscribers');
|
|
|
|
var delay = subs * 2; // 1,000 subs = 2 seconds
|
|
|
|
console.log(['Fetching dashboard story', story_hash, delay + 'ms delay']);
|
|
|
|
|
2020-07-14 16:41:07 -04:00
|
|
|
_.delay(_.bind(function() {
|
|
|
|
NEWSBLUR.assets.add_dashboard_story(story_hash, this.options.dashboard_stories);
|
|
|
|
}, this), Math.random() * delay);
|
2016-12-13 16:29:42 -08:00
|
|
|
|
2016-11-29 17:26:17 -08:00
|
|
|
}
|
|
|
|
|
2020-12-09 18:20:55 -05:00
|
|
|
});
|