mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Posting replies (and handling error cases) on blurblogs.
This commit is contained in:
parent
a82492f928
commit
feadee3c5f
6 changed files with 63 additions and 19 deletions
|
@ -1216,8 +1216,20 @@ class MSharedStory(mongo.Document):
|
|||
stories[s][comment_set][c]['source_user'] = profiles[comment['source_user_id']]
|
||||
for r, reply in enumerate(comment['replies']):
|
||||
stories[s][comment_set][c]['replies'][r]['user'] = profiles[reply['user_id']]
|
||||
|
||||
|
||||
return stories
|
||||
|
||||
@staticmethod
|
||||
def attach_users_to_comment(comment, profiles):
|
||||
profiles = dict([(p['user_id'], p) for p in profiles])
|
||||
comment['user'] = profiles[comment['user_id']]
|
||||
if comment['source_user_id']:
|
||||
comment['source_user'] = profiles[comment['source_user_id']]
|
||||
for r, reply in enumerate(comment['replies']):
|
||||
comment['replies'][r]['user'] = profiles[reply['user_id']]
|
||||
|
||||
return comment
|
||||
|
||||
|
||||
def blurblog_permalink(self):
|
||||
profile = MSocialProfile.objects.get(user_id=self.user_id)
|
||||
|
|
|
@ -374,7 +374,6 @@ def mark_story_as_unshared(request):
|
|||
})
|
||||
|
||||
@ajax_login_required
|
||||
@json.json_view
|
||||
def save_comment_reply(request):
|
||||
code = 1
|
||||
feed_id = int(request.POST['story_feed_id'])
|
||||
|
@ -382,9 +381,10 @@ def save_comment_reply(request):
|
|||
comment_user_id = request.POST['comment_user_id']
|
||||
reply_comments = request.POST.get('reply_comments')
|
||||
original_message = request.POST.get('original_message')
|
||||
format = request.REQUEST.get('format', 'json')
|
||||
|
||||
if not reply_comments:
|
||||
return {'code': -1, 'message': 'Reply comments cannot be empty.'}
|
||||
return json.json_response(request, {'code': -1, 'message': 'Reply comments cannot be empty.'})
|
||||
|
||||
shared_story = MSharedStory.objects.get(user_id=comment_user_id,
|
||||
story_feed_id=feed_id,
|
||||
|
@ -444,7 +444,17 @@ def save_comment_reply(request):
|
|||
social_feed_id=comment_user_id,
|
||||
story_id=story_id)
|
||||
|
||||
return {'code': code, 'comment': comment, 'user_profiles': profiles}
|
||||
if format == 'html':
|
||||
comment = MSharedStory.attach_users_to_comment(comment, profiles)
|
||||
return render_to_response('social/story_comment.xhtml', {
|
||||
'comment': comment,
|
||||
}, context_instance=RequestContext(request))
|
||||
else:
|
||||
return json.json_response(request, {
|
||||
'code': code,
|
||||
'comment': comment,
|
||||
'user_profiles': profiles
|
||||
})
|
||||
|
||||
def shared_stories_public(request, username):
|
||||
try:
|
||||
|
|
|
@ -96,20 +96,16 @@ NEWSBLUR.SocialPageAssets = Backbone.Router.extend({
|
|||
},
|
||||
|
||||
save_comment_reply: function(story_id, story_feed_id, comment_user_id, reply_comments, original_message, callback, error_callback) {
|
||||
var pre_callback = _.bind(function(data) {
|
||||
if (data.user_profiles) {
|
||||
this.add_user_profiles(data.user_profiles);
|
||||
}
|
||||
callback(data);
|
||||
}, this);
|
||||
|
||||
this.make_request('/social/save_comment_reply', {
|
||||
story_id: story_id,
|
||||
story_feed_id: story_feed_id,
|
||||
comment_user_id: comment_user_id,
|
||||
reply_comments: reply_comments,
|
||||
original_message: original_message
|
||||
}, pre_callback, error_callback);
|
||||
original_message: original_message,
|
||||
format: 'html'
|
||||
}, callback, error_callback, {
|
||||
request_type: 'POST'
|
||||
});
|
||||
}
|
||||
|
||||
});
|
|
@ -11,10 +11,15 @@ NEWSBLUR.Views.SocialPageComments = Backbone.View.extend({
|
|||
|
||||
this.$('.NB-story-comment').each(function() {
|
||||
var $comment = $(this);
|
||||
var comment = new Backbone.Model({
|
||||
user_id: $comment.data('userId')
|
||||
});
|
||||
var comment_view = new NEWSBLUR.Views.StoryComment({
|
||||
el: $comment,
|
||||
on_social_page: true,
|
||||
story: self.model
|
||||
story: self.model,
|
||||
story_comments_view: self,
|
||||
model: comment
|
||||
});
|
||||
self.comment_views.push(comment_view);
|
||||
});
|
||||
|
@ -45,6 +50,17 @@ NEWSBLUR.Views.SocialPageComments = Backbone.View.extend({
|
|||
this.setElement($new_comments);
|
||||
this.story_view.attach_tooltips();
|
||||
this.initialize();
|
||||
},
|
||||
|
||||
replace_comment: function(comment_user_id, html) {
|
||||
var comment_view = _.detect(this.comment_views, function(view) {
|
||||
return view.model.get('user_id') == comment_user_id;
|
||||
});
|
||||
var $new_comment = $(html);
|
||||
comment_view.$el.replaceWith($new_comment);
|
||||
comment_view.setElement($new_comment);
|
||||
this.story_view.attach_tooltips();
|
||||
this.initialize();
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -123,7 +123,9 @@ NEWSBLUR.Views.StoryComment = Backbone.View.extend({
|
|||
|
||||
if (!comment_reply || comment_reply.length <= 1) {
|
||||
this.remove_social_comment_reply_form();
|
||||
NEWSBLUR.app.story_list.fetch_story_locations_in_feed_view();
|
||||
if (NEWSBLUR.app.story_list) {
|
||||
NEWSBLUR.app.story_list.fetch_story_locations_in_feed_view();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -136,9 +138,13 @@ NEWSBLUR.Views.StoryComment = Backbone.View.extend({
|
|||
comment_user_id, comment_reply,
|
||||
original_message,
|
||||
_.bind(function(data) {
|
||||
this.model.set(data.comment);
|
||||
this.render();
|
||||
NEWSBLUR.app.story_list.fetch_story_locations_in_feed_view();
|
||||
if (this.options.on_social_page) {
|
||||
this.options.story_comments_view.replace_comment(this.model.get('user_id'), data);
|
||||
} else {
|
||||
this.model.set(data.comment);
|
||||
this.render();
|
||||
NEWSBLUR.app.story_list.fetch_story_locations_in_feed_view();
|
||||
}
|
||||
}, this), _.bind(function(data) {
|
||||
var message = data && data.message || "Sorry, this reply could not be posted. Probably a bug.";
|
||||
if (!NEWSBLUR.Globals.is_authenticated) {
|
||||
|
@ -148,7 +154,9 @@ NEWSBLUR.Views.StoryComment = Backbone.View.extend({
|
|||
$submit.removeClass('NB-disabled').text('Post');
|
||||
$form.find('.NB-error').remove();
|
||||
$form.append($error);
|
||||
NEWSBLUR.app.story_list.fetch_story_locations_in_feed_view();
|
||||
if (NEWSBLUR.app.story_list) {
|
||||
NEWSBLUR.app.story_list.fetch_story_locations_in_feed_view();
|
||||
}
|
||||
}, this));
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ def user(u, msg):
|
|||
platform = 'iPhone'
|
||||
elif 'Blar' in user_agent:
|
||||
platform = 'Blar'
|
||||
elif 'Android' in user_agent:
|
||||
platform = 'Androd'
|
||||
elif 'MSIE' in user_agent:
|
||||
platform = 'IE'
|
||||
elif 'Chrome' in user_agent:
|
||||
|
|
Loading…
Add table
Reference in a new issue