mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Loading public comments through ajax. Needs to remove friends.
This commit is contained in:
parent
d8f4005d3c
commit
3e0a184fc0
4 changed files with 94 additions and 48 deletions
|
@ -11,6 +11,7 @@ urlpatterns = patterns('',
|
|||
url(r'^profile/?$', views.profile, name='profile'),
|
||||
url(r'^follow/?$', views.follow, name='social-follow'),
|
||||
url(r'^unfollow/?$', views.unfollow, name='social-unfollow'),
|
||||
url(r'^comments/?$', views.story_comments, name='social-story-comments'),
|
||||
url(r'^(?P<user_id>\d+)/(?P<username>\w+)/?$', views.shared_story_feed, name='shared-story-feed'),
|
||||
url(r'^(?P<username>\w+)/?$', views.shared_stories_public, name='shared-stories-public'),
|
||||
)
|
||||
|
|
|
@ -18,6 +18,16 @@ from utils import PyRSS2Gen as RSS
|
|||
from vendor import facebook
|
||||
from vendor import tweepy
|
||||
|
||||
@json.json_view
|
||||
def story_comments(request):
|
||||
feed_id = int(request.POST['feed_id'])
|
||||
story_id = request.POST['story_id']
|
||||
full = bool(request.POST.get('full', True))
|
||||
|
||||
shared_stories = MSharedStory.objects.filter(story_feed_id=feed_id, story_guid=story_id)
|
||||
comments = [s.comments_with_author(full=full) for s in shared_stories]
|
||||
|
||||
return {'comments': comments}
|
||||
|
||||
@ajax_login_required
|
||||
@json.json_view
|
||||
|
|
|
@ -965,6 +965,13 @@ NEWSBLUR.AssetModel.Reader.prototype = {
|
|||
this.make_request('/social/unfollow', {'user_id': user_id}, pre_callback);
|
||||
},
|
||||
|
||||
load_public_story_comments: function(story_id, feed_id, callback) {
|
||||
this.make_request('/social/comments', {
|
||||
'story_id': story_id,
|
||||
'feed_id': feed_id
|
||||
}, callback);
|
||||
},
|
||||
|
||||
recalculate_story_scores: function(feed_id) {
|
||||
_.each(this.stories, _.bind(function(story, i) {
|
||||
if (story.story_feed_id != feed_id) return;
|
||||
|
|
|
@ -3813,54 +3813,6 @@
|
|||
return $story_content;
|
||||
},
|
||||
|
||||
make_story_share_comments: function(story) {
|
||||
var $comments = $([]);
|
||||
console.log(["story", story]);
|
||||
|
||||
// var $share = $.make('div', { className: 'NB-story-comments-sharers' }, 'Shared by: ');
|
||||
|
||||
if (story.comment_count_shared) {
|
||||
_.each(story.comments, _.bind(function(comment) {
|
||||
var $comment = this.make_story_share_comment(comment);
|
||||
$comments.push($comment);
|
||||
}, this));
|
||||
}
|
||||
|
||||
if (story.comment_count_public) {
|
||||
var $public_teaser = $.make('div', { className: 'NB-story-comments-public-teaser-wrapper' }, [
|
||||
$.make('div', { className: 'NB-story-comments-public-teaser' }, [
|
||||
'There ',
|
||||
Inflector.pluralize('is', story.comment_count_public),
|
||||
' ',
|
||||
$.make('b', story.comment_count_public),
|
||||
' public ',
|
||||
Inflector.pluralize('comment', story.comment_count_public)
|
||||
])
|
||||
]);
|
||||
$comments.push($public_teaser);
|
||||
}
|
||||
|
||||
return $comments;
|
||||
},
|
||||
|
||||
make_story_share_comment: function(comment) {
|
||||
console.log(["make_story_share_comment", comment, this.model.following_profiles, this.model.following_profiles.find(comment.user_id)]);
|
||||
var user = this.model.following_profiles.find(comment.user_id);
|
||||
|
||||
var $comment = $.make('div', { className: 'NB-story-comment' }, [
|
||||
$.make('div', { className: 'NB-user-avatar' }, [
|
||||
$.make('img', { src: user.get('photo_url') })
|
||||
]),
|
||||
$.make('div', { className: 'NB-story-comment-author-container' }, [
|
||||
$.make('div', { className: 'NB-story-comment-username' }, user.get('username')),
|
||||
$.make('div', { className: 'NB-story-comment-date' }, comment.shared_date + ' ago')
|
||||
]),
|
||||
$.make('div', { className: 'NB-story-comment-content' }, comment.comments)
|
||||
]);
|
||||
|
||||
return $comment;
|
||||
},
|
||||
|
||||
make_story_feed_title: function(story) {
|
||||
var title = story.story_title;
|
||||
var feed_titles = this.model.classifiers[story.story_feed_id] &&
|
||||
|
@ -4123,6 +4075,77 @@
|
|||
$story_titles.append($notice);
|
||||
},
|
||||
|
||||
// ==================
|
||||
// = Story Comments =
|
||||
// ==================
|
||||
|
||||
make_story_share_comments: function(story) {
|
||||
var $comments = $([]);
|
||||
console.log(["story", story]);
|
||||
|
||||
// var $share = $.make('div', { className: 'NB-story-comments-sharers' }, 'Shared by: ');
|
||||
|
||||
if (story.comment_count_shared) {
|
||||
_.each(story.comments, _.bind(function(comment) {
|
||||
var $comment = this.make_story_share_comment(comment);
|
||||
$comments.push($comment);
|
||||
}, this));
|
||||
}
|
||||
|
||||
if (story.comment_count_public) {
|
||||
var $public_teaser = $.make('div', { className: 'NB-story-comments-public-teaser-wrapper' }, [
|
||||
$.make('div', { className: 'NB-story-comments-public-teaser' }, [
|
||||
'There ',
|
||||
Inflector.pluralize('is', story.comment_count_public),
|
||||
' ',
|
||||
$.make('b', story.comment_count_public),
|
||||
' public ',
|
||||
Inflector.pluralize('comment', story.comment_count_public)
|
||||
])
|
||||
]);
|
||||
$comments.push($public_teaser);
|
||||
}
|
||||
|
||||
return $comments;
|
||||
},
|
||||
|
||||
make_story_share_comment: function(comment) {
|
||||
console.log(["make_story_share_comment", comment, this.model.following_profiles, this.model.following_profiles.find(comment.user_id)]);
|
||||
var user = this.model.following_profiles.find(comment.user_id);
|
||||
if (!user) {
|
||||
user = new NEWSBLUR.Models.User(comment.author);
|
||||
}
|
||||
|
||||
var $comment = $.make('div', { className: 'NB-story-comment' }, [
|
||||
$.make('div', { className: 'NB-user-avatar' }, [
|
||||
$.make('img', { src: user.get('photo_url') })
|
||||
]),
|
||||
$.make('div', { className: 'NB-story-comment-author-container' }, [
|
||||
$.make('div', { className: 'NB-story-comment-username' }, user.get('username')),
|
||||
$.make('div', { className: 'NB-story-comment-date' }, comment.shared_date + ' ago')
|
||||
]),
|
||||
$.make('div', { className: 'NB-story-comment-content' }, comment.comments)
|
||||
]);
|
||||
|
||||
return $comment;
|
||||
},
|
||||
|
||||
load_public_story_comments: function(story_id) {
|
||||
var story = this.model.get_story(story_id);
|
||||
this.model.load_public_story_comments(story_id, story.story_feed_id, _.bind(function(data) {
|
||||
console.log(["comments", data]);
|
||||
var $comments = $.make('div', { className: 'NB-story-comments-public' });
|
||||
|
||||
_.each(data.comments, _.bind(function(comment) {
|
||||
var $comment = this.make_story_share_comment(comment);
|
||||
$comments.append($comment);
|
||||
}, this));
|
||||
|
||||
var $story = this.find_story_in_feed_view(story_id);
|
||||
$('.NB-story-comments-public-teaser-wrapper', $story).replaceWith($comments);
|
||||
}, this));
|
||||
},
|
||||
|
||||
// ===================
|
||||
// = Taskbar - Story =
|
||||
// ===================
|
||||
|
@ -6319,6 +6342,11 @@
|
|||
e.preventDefault();
|
||||
self.open_feedchooser_modal();
|
||||
});
|
||||
$.targetIs(e, { tagSelector: '.NB-story-comments-public-teaser' }, function($t, $p){
|
||||
e.preventDefault();
|
||||
var story_id = $t.closest('.NB-feed-story').data('story_id');
|
||||
self.load_public_story_comments(story_id);
|
||||
});
|
||||
|
||||
|
||||
// = Taskbar ======================================================
|
||||
|
|
Loading…
Add table
Reference in a new issue