Hiding share comments by private profiles when not being followed.

This commit is contained in:
Samuel Clay 2012-10-24 17:01:22 -07:00
parent d05b308cf3
commit 41b69dd3b5
5 changed files with 38 additions and 14 deletions

View file

@ -1488,7 +1488,7 @@ class MSharedStory(mongo.Document):
return comment, profiles
@classmethod
def stories_with_comments_and_profiles(cls, stories, user_id, check_all=False, public=False):
def stories_with_comments_and_profiles(cls, stories, user_id, check_all=False):
r = redis.Redis(connection_pool=settings.REDIS_POOL)
friend_key = "F:%s:F" % (user_id)
profile_user_ids = set()
@ -1553,7 +1553,16 @@ class MSharedStory(mongo.Document):
profiles = MSocialProfile.objects.filter(user_id__in=list(profile_user_ids))
profiles = [profile.to_json(compact=True) for profile in profiles]
# Toss public comments by private profiles
profiles_dict = dict((profile['user_id'], profile) for profile in profiles)
for story in stories:
commented_by_public = story.get('commented_by_public') or [c['user_id'] for c in story['public_comments']]
for user_id in commented_by_public:
if profiles_dict[user_id]['private']:
story['public_comments'] = [c for c in story['public_comments'] if c['user_id'] != user_id]
story['comment_count_public'] -= 1
return stories, profiles
@staticmethod

View file

@ -440,8 +440,7 @@ def story_public_comments(request):
stories = MSharedStory.objects.filter(story_feed_id=feed_id, story_guid=story_id).limit(1)
stories = Feed.format_stories(stories)
stories, profiles = MSharedStory.stories_with_comments_and_profiles(stories, relative_user_id,
check_all=True,
public=True)
check_all=True)
if format == 'html':
stories = MSharedStory.attach_users_to_stories(stories, profiles)

View file

@ -2445,10 +2445,10 @@ background: transparent;
vertical-align: middle;
height: 22px;
width: 22px;
margin: 0 4px 0 0;
padding: 0 2px;
cursor: pointer;
}
#story_pane .NB-story-share-profile .NB-user-avatar img {
#story_pane .NB-story-share-profile .NB-user-avatar img.NB-user-avatar-image {
width: 22px;
height: 22px;
border-radius: 3px;
@ -2487,6 +2487,20 @@ background: transparent;
display: none;
}
/* =============== */
/* = User Avatar = */
/* =============== */
.NB-user-avatar {
position: relative;
}
.NB-user-avatar .NB-user-avatar-private {
position: absolute;
width: 12px;
height: 12px;
bottom: -2px;
left: -1px;
}
/* ============================= */
/* = Side Options in Feed view = */
/* ============================= */

View file

@ -14,7 +14,8 @@ NEWSBLUR.Views.ProfileThumb = Backbone.View.extend({
render: function() {
var $profile = $.make('div', { className: 'NB-user-avatar', title: this.model.get('username') }, [
$.make('img', { src: this.model.get('photo_url') })
(this.model.get('private') && $.make('img', { src: NEWSBLUR.Globals.MEDIA_URL + 'img/icons/silk/lock.png', className: 'NB-user-avatar-private' })),
$.make('img', { src: this.model.get('photo_url'), className: 'NB-user-avatar-image' })
]).tipsy({
delayIn: 50,
gravity: 's',

View file

@ -29,20 +29,21 @@ NEWSBLUR.Views.StoryCommentsView = Backbone.View.extend({
var $comments_friends = this.$('.NB-story-share-profiles-comments-friends');
var $comments_public = this.$('.NB-story-share-profiles-comments-public');
var comment_user_ids = [];
this.model.friend_comments.each(function(comment) {
var $thumb = NEWSBLUR.Views.ProfileThumb.create(comment.get('user_id')).render().el;
_.each(this.model.get('commented_by_friends'), function(user_id) {
var $thumb = NEWSBLUR.Views.ProfileThumb.create(user_id).render().el;
$comments_friends.append($thumb);
comment_user_ids.push(comment.get('user_id'));
});
this.model.public_comments.each(function(comment) {
var $thumb = NEWSBLUR.Views.ProfileThumb.create(comment.get('user_id')).render().el;
_.each(this.model.get('commented_by_public'), function(user_id) {
var $thumb = NEWSBLUR.Views.ProfileThumb.create(user_id).render().el;
$comments_public.append($thumb);
comment_user_ids.push(comment.get('user_id'));
});
if (!this.model.friend_comments.length && !this.model.public_comments.length) {
this.$el.hide();
}
var $shares_friends = this.$('.NB-story-share-profiles-shares-friends');
var $shares_public = this.$('.NB-story-share-profiles-shares-public');
var comment_user_ids = this.model.get('comment_user_ids');
_.each(this.model.get('shared_by_friends'), function(user_id) {
if (_.contains(comment_user_ids, user_id)) return;
var $thumb = NEWSBLUR.Views.ProfileThumb.create(user_id).render().el;