Fixing send story by email. Also adding update_counts field to feeds/flat.

This commit is contained in:
Samuel Clay 2012-08-01 18:52:54 -07:00
parent c3460bf109
commit f40c96b226
6 changed files with 23 additions and 23 deletions

View file

@ -259,8 +259,8 @@ def load_feed_favicons(request):
def load_feeds_flat(request):
user = request.user
include_favicons = request.REQUEST.get('include_favicons', False)
update_counts = request.REQUEST.get('update_counts', False)
include_favicons = is_true(request.REQUEST.get('include_favicons', False))
update_counts = is_true(request.REQUEST.get('update_counts', True))
feeds = {}
iphone_version = "1.2"
@ -280,7 +280,7 @@ def load_feeds_flat(request):
user_subs = UserSubscription.objects.select_related('feed').filter(user=user, active=True)
for sub in user_subs:
if sub.needs_unread_recalc:
if update_counts and sub.needs_unread_recalc:
sub.calculate_feed_scores(silent=True)
feeds[sub.feed_id] = sub.canonical(include_favicon=include_favicons)

View file

@ -612,19 +612,19 @@ class MSocialSubscription(mongo.Document):
return "%s:%s" % (self.user_id, self.subscription_user_id)
@classmethod
def feeds(cls, *args, **kwargs):
user_id = kwargs['user_id']
def feeds(cls, user_id=None, subscription_user_id=None, calculate_all_scores=False,
update_counts=False, *args, **kwargs):
print locals()
params = {
'user_id': user_id,
}
if 'subscription_user_id' in kwargs:
params["subscription_user_id"] = kwargs["subscription_user_id"]
if subscription_user_id:
params["subscription_user_id"] = subscription_user_id
social_subs = cls.objects.filter(**params)
# for sub in social_subs:
# sub.calculate_feed_scores()
social_feeds = []
if social_subs:
if kwargs.get('calculate_scores'):
if calculate_all_scores:
for s in social_subs: s.calculate_feed_scores()
social_subs = dict((s.subscription_user_id, s.to_json()) for s in social_subs)
social_user_ids = social_subs.keys()
@ -634,6 +634,8 @@ class MSocialSubscription(mongo.Document):
for user_id, social_sub in social_subs.items():
if social_profiles[user_id]['shared_stories_count'] <= 0:
continue
if update_counts and social_sub.needs_unread_recalc:
social_sub.calculate_feed_scores()
# Combine subscription read counts with feed/user info
feed = dict(social_sub.items() + social_profiles[user_id].items())

View file

@ -731,7 +731,7 @@ def follow(request):
'include_favicon': True,
'update_counts': True,
}
follow_subscription = MSocialSubscription.feeds(calculate_scores=True, **social_params)
follow_subscription = MSocialSubscription.feeds(calculate_all_scores=True, **social_params)
logging.user(request, "~BB~FRFollowing: %s" % follow_profile.username)

View file

@ -173,7 +173,7 @@ NEWSBLUR.Collections.Folders = Backbone.Collection.extend({
comparator: function(modelA, modelB) {
var sort_order = NEWSBLUR.assets.preference('feed_order');
if (modelA.is_feed() != modelB.is_feed()) {
// Feeds above folders
return modelA.is_feed() ? -1 : 1;

View file

@ -1756,9 +1756,8 @@
NEWSBLUR.assets.stories.mark_read(story, {skip_delay: true});
},
send_story_to_email: function(story_id) {
NEWSBLUR.reader_send_email = new NEWSBLUR.ReaderSendEmail(story_id);
var story = this.model.get_story(story_id);
send_story_to_email: function(story) {
NEWSBLUR.reader_send_email = new NEWSBLUR.ReaderSendEmail(story);
NEWSBLUR.assets.stories.mark_read(story, {skip_delay: true});
},
@ -2651,7 +2650,7 @@
} else if ($target.hasClass('NB-menu-manage-thirdparty-instapaper')) {
this.send_story_to_instapaper(story.id);
} else {
this.send_story_to_email(story.id);
this.send_story_to_email(story);
}
}, this)),
$.make('li', { className: 'NB-menu-item NB-menu-manage-story NB-menu-manage-story-share' }, [
@ -5173,9 +5172,9 @@
});
$document.bind('keypress', 'e', function(e) {
e.preventDefault();
var story_id = self.active_story;
if (!story_id) return;
self.send_story_to_email(story_id);
var story = self.active_story;
if (!story) return;
self.send_story_to_email(story);
});
$document.bind('keydown', 'shift+a', function(e) {
e.preventDefault();

View file

@ -1,12 +1,11 @@
NEWSBLUR.ReaderSendEmail = function(story_id, options) {
NEWSBLUR.ReaderSendEmail = function(story, options) {
var defaults = {};
_.bindAll(this, 'close', 'save_callback', 'error');
this.options = $.extend({}, defaults, options);
this.model = NEWSBLUR.assets;
this.story_id = story_id;
this.story = this.model.get_story(story_id);
this.story = story;
this.feed_id = this.story.get('story_feed_id');
this.feed = this.model.get_feed(this.feed_id);
@ -106,7 +105,7 @@ _.extend(NEWSBLUR.ReaderSendEmail.prototype, {
$('.NB-error', this.$modal).fadeOut(500);
this.model.send_story_email({
story_id : this.story_id,
story_id : this.story.id,
feed_id : this.feed_id,
from_name : from_name,
from_email : from_email,