Real-time interaction count.

This commit is contained in:
Samuel Clay 2013-02-04 16:16:03 -08:00
parent 630314a5f2
commit 3b10ff8594
9 changed files with 62 additions and 8 deletions

View file

@ -15,6 +15,7 @@ urlpatterns = patterns('',
url(r'^favicons', views.load_feed_favicons, name='load-feed-favicons'),
url(r'^river_stories', views.load_river_stories__redis, name='load-river-stories'),
url(r'^refresh_feeds', views.refresh_feeds, name='refresh-feeds'),
url(r'^interactions_count', views.interactions_count, name='interactions-count'),
url(r'^feed_unread_count', views.feed_unread_count, name='feed-unread-count'),
url(r'^starred_stories', views.load_starred_stories, name='load-starred-stories'),
url(r'^mark_all_as_read', views.mark_all_as_read, name='mark-all-as-read'),

View file

@ -419,6 +419,16 @@ def refresh_feeds(request):
'interactions_count': interactions_count,
}
@json.json_view
def interactions_count(request):
user = get_user(request)
interactions_count = MInteraction.user_unread_count(user.pk)
return {
'interactions_count': interactions_count,
}
@never_cache
@json.json_view
def feed_unread_count(request):

View file

@ -2311,7 +2311,18 @@ class MInteraction(mongo.Document):
'story_feed_id': self.story_feed_id,
'content_id': self.content_id,
}
@classmethod
def publish_update_to_subscribers(self, user_id):
user = User.objects.get(pk=user_id)
try:
r = redis.Redis(connection_pool=settings.REDIS_POOL)
listeners_count = r.publish(user.username, 'interaction:new')
if listeners_count:
logging.debug(" ---> ~FMPublished to %s subscribers" % (listeners_count))
except redis.ConnectionError:
logging.debug(" ***> ~BMRedis is unavailable for real-time.")
@classmethod
def user(cls, user_id, page=1, limit=None, categories=None):
user_profile = Profile.objects.get(user=user_id)
@ -2367,6 +2378,8 @@ class MInteraction(mongo.Document):
logging.debug(" ---> ~FRDeleting dupe follow interactions. %s found." % dupes.count())
for dupe in dupes[1:]:
dupe.delete()
cls.publish_update_to_subscribers(followee_user_id)
@classmethod
def new_comment_reply(cls, user_id, reply_user_id, reply_content, story_id, story_feed_id, story_title=None, original_message=None):
@ -2392,6 +2405,8 @@ class MInteraction(mongo.Document):
if not original_message:
cls.objects.create(**params)
cls.publish_update_to_subscribers(user_id)
@classmethod
def remove_comment_reply(cls, user_id, reply_user_id, reply_content, story_id, story_feed_id):
@ -2406,6 +2421,8 @@ class MInteraction(mongo.Document):
}
original = cls.objects.filter(**params)
original.delete()
cls.publish_update_to_subscribers(user_id)
@classmethod
def new_comment_like(cls, liking_user_id, comment_user_id, story_id, story_title, comments):
@ -2418,6 +2435,8 @@ class MInteraction(mongo.Document):
"title": story_title,
"content": comments,
})
cls.publish_update_to_subscribers(comment_user_id)
@classmethod
def new_reply_reply(cls, user_id, comment_user_id, reply_user_id, reply_content, story_id, story_feed_id, story_title=None, original_message=None):
@ -2443,6 +2462,8 @@ class MInteraction(mongo.Document):
if not original_message:
cls.objects.create(**params)
cls.publish_update_to_subscribers(user_id)
@classmethod
def remove_reply_reply(cls, user_id, comment_user_id, reply_user_id, reply_content, story_id, story_feed_id):
@ -2458,6 +2479,8 @@ class MInteraction(mongo.Document):
original = cls.objects.filter(**params)
original.delete()
cls.publish_update_to_subscribers(user_id)
@classmethod
def new_reshared_story(cls, user_id, reshare_user_id, comments, story_title, story_feed_id, story_id, original_comments=None):
params = {
@ -2474,14 +2497,16 @@ class MInteraction(mongo.Document):
params['content'] = original_comments
original = cls.objects.filter(**params).limit(1)
if original:
original = original[0]
original.content = comments
original.save()
interaction = original[0]
interaction.content = comments
interaction.save()
else:
original_comments = None
if not original_comments:
cls.objects.create(**params)
cls.publish_update_to_subscribers(user_id)
class MActivity(mongo.Document):
user_id = mongo.IntField()

View file

@ -868,6 +868,7 @@ body {
.unread_count_negative {
background-color: #CC2A2E;
text-shadow: none;
/* text-shadow: 0 1px 0 rgba(0, 0, 0, .3);*/
}
@ -2565,7 +2566,7 @@ background: transparent;
}
#story_pane .NB-story-comment-reply-form .NB-story-comment-reply-comments {
margin: 0 8px 4px 0;
width: 62%;
width: 50%;
display: block;
float: left;
font-size: 12px;
@ -3469,6 +3470,7 @@ background: transparent;
}
#story_taskbar .feed_counts_floater .unread_count {
margin-top: 1px;
text-shadow: none;
}
#story_taskbar .NB-taskbar {
margin: 5px 0 0 0;

View file

@ -741,6 +741,12 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
}
},
interactions_count: function(callback, error_callback) {
this.make_request('/reader/interactions_count', {}, callback, error_callback, {
'request_type': 'GET'
});
},
count_unfetched_feeds: function() {
var counts = this.feeds.reduce(function(counts, feed) {
if (feed.get('active')) {

View file

@ -3787,6 +3787,8 @@
NEWSBLUR.log(['Real-time user update', username, feed_id]);
this.feed_unread_count(feed_id);
}
} else if (feed_id == "interaction:new") {
this.update_interactions_count();
}
}, this));
@ -3922,6 +3924,12 @@
this.model.feed_unread_count(feed_id);
},
update_interactions_count: function() {
this.model.interactions_count(function(data) {
NEWSBLUR.app.sidebar_header.update_interactions_count(data.interactions_count);
}, $.noop);
},
// ===================
// = Mouse Indicator =
// ===================

View file

@ -470,7 +470,7 @@ NEWSBLUR.Views.OriginalTabView = Backbone.View.extend({
if (this.iframe_scroll
&& this.flags.iframe_scroll_snap_back_prepared
&& this.$el.contents().scrollTop() == 0) {
// NEWSBLUR.log(['Snap back, loaded, scroll', this.iframe_scroll]);
NEWSBLUR.log(['Snap back, loaded, scroll', this.iframe_scroll]);
this.$el.contents().scrollTop(this.iframe_scroll);
if (iframe_loaded) {
this.flags.iframe_scroll_snap_back_prepared = false;

View file

@ -102,6 +102,7 @@ NEWSBLUR.Views.StoryComment = Backbone.View.extend({
});
var tipsy = $like.data('tipsy');
_.defer(function() {
if (!tipsy) return;
tipsy.enable();
tipsy.show();
});
@ -112,7 +113,7 @@ NEWSBLUR.Views.StoryComment = Backbone.View.extend({
'duration': 850,
'queue': false,
'complete': function() {
if (tipsy.enabled) {
if (tipsy && tipsy.enabled) {
tipsy.hide();
tipsy.disable();
}

View file

@ -224,7 +224,8 @@ NEWSBLUR.Views.StoryShareView = Backbone.View.extend({
},
post_share_story: function(shared, data) {
this.model.set("shared", shared);
this.model.set("shared", shared, {silent: true});
this.model.trigger('change:shared');
var $share_star = this.model.story_title_view && this.model.story_title_view.$('.NB-storytitles-share');
var $share_button = this.$('.NB-sideoption-share-save');