From dffdfa75a6393d2fe840e8a2eff048ddd4fe7f0e Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Sat, 28 Jul 2012 12:37:16 -0700 Subject: [PATCH] Fixing interactions on favorites, replies (to include titles), and wording in api docs. --- apps/reader/views.py | 2 +- apps/social/models.py | 25 ++++++++++++++----------- apps/social/views.py | 21 ++++++++++++--------- templates/static/api.yml | 10 +++++----- 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/apps/reader/views.py b/apps/reader/views.py index 7d8fa9034..4fea846cb 100644 --- a/apps/reader/views.py +++ b/apps/reader/views.py @@ -1400,7 +1400,7 @@ def send_story_email(request): code = -1 message = 'You need to provide your name.' else: - story = MStory.objects(story_feed_id=feed_id, story_guid=story_id)[0] + story = MStory.find_story(story_feed_id=feed_id, story_guid=story_id) story = Feed.format_story(story, feed_id, text=True) feed = Feed.objects.get(pk=story['story_feed_id']) text = render_to_string('mail/email_story_text.xhtml', locals()) diff --git a/apps/social/models.py b/apps/social/models.py index 375923c18..80b851263 100644 --- a/apps/social/models.py +++ b/apps/social/models.py @@ -1942,13 +1942,14 @@ class MInteraction(mongo.Document): dupe.delete() @classmethod - def new_comment_reply(cls, user_id, reply_user_id, reply_content, social_feed_id, story_id, original_message=None): + def new_comment_reply(cls, user_id, reply_user_id, reply_content, social_feed_id, story_id, story_title=None, original_message=None): params = { 'user_id': user_id, 'with_user_id': reply_user_id, 'category': 'comment_reply', 'content': reply_content, 'feed_id': social_feed_id, + 'title': story_title, 'content_id': story_id, } if original_message: @@ -1965,26 +1966,27 @@ class MInteraction(mongo.Document): cls.objects.create(**params) @classmethod - def new_comment_like(cls, user_id, comment_user_id, story_feed_id, story_id, story_title, comments): + def new_comment_like(cls, liking_user_id, comment_user_id, social_feed_id, story_id, story_title, comments): params = { 'user_id': comment_user_id, - 'with_user_id': user_id, + 'with_user_id': liking_user_id, 'category': 'comment_like', - 'title': story_title, - 'feed_id': story_feed_id, + 'feed_id': social_feed_id, 'content_id': story_id, + 'title': story_title, 'content': comments, } cls.objects.create(**params) @classmethod - def new_reply_reply(cls, user_id, reply_user_id, reply_content, social_feed_id, story_id, original_message=None): + def new_reply_reply(cls, user_id, reply_user_id, reply_content, social_feed_id, story_id, story_title=None, original_message=None): params = { 'user_id': user_id, 'with_user_id': reply_user_id, 'category': 'reply_reply', 'content': reply_content, 'feed_id': social_feed_id, + 'title': story_title, 'content_id': story_id, } if original_message: @@ -2119,13 +2121,14 @@ class MActivity(mongo.Document): dupe.delete() @classmethod - def new_comment_reply(cls, user_id, comment_user_id, reply_content, story_feed_id, story_id, original_message=None): + def new_comment_reply(cls, user_id, comment_user_id, reply_content, story_feed_id, story_id, story_title=None, original_message=None): params = { 'user_id': user_id, 'with_user_id': comment_user_id, 'category': 'comment_reply', 'content': reply_content, 'feed_id': story_feed_id, + 'title': story_title, 'content_id': story_id, } if original_message: @@ -2142,12 +2145,12 @@ class MActivity(mongo.Document): cls.objects.create(**params) @classmethod - def new_comment_like(cls, user_id, comment_user_id, story_feed_id, story_id, story_title, comments): + def new_comment_like(cls, liking_user_id, comment_user_id, social_feed_id, story_id, story_title, comments): params = { - 'user_id': user_id, - 'with_user_id': comment_user_id, + 'user_id': comment_user_id, + 'with_user_id': liking_user_id, 'category': 'comment_like', - 'feed_id': story_feed_id, + 'feed_id': social_feed_id, 'content_id': story_id, 'title': story_title, 'content': comments, diff --git a/apps/social/views.py b/apps/social/views.py index 168487a23..2c286afb0 100644 --- a/apps/social/views.py +++ b/apps/social/views.py @@ -435,9 +435,9 @@ def save_comment_reply(request): story_id = request.POST['story_id'] comment_user_id = request.POST['comment_user_id'] reply_comments = request.POST.get('reply_comments') - original_message = request.POST.get('original_message') reply_id = request.POST.get('reply_id') format = request.REQUEST.get('format', 'json') + original_message = None if not reply_comments: return json.json_response(request, {'code': -1, 'message': 'Reply comments cannot be empty.'}) @@ -484,14 +484,16 @@ def save_comment_reply(request): reply_content=reply_comments, original_message=original_message, story_feed_id=feed_id, - story_id=story_id) + story_id=story_id, + story_title=shared_story.story_title) if comment['user_id'] != request.user.pk: MInteraction.new_comment_reply(user_id=comment['user_id'], reply_user_id=request.user.pk, reply_content=reply_comments, original_message=original_message, social_feed_id=comment_user_id, - story_id=story_id) + story_id=story_id, + story_title=shared_story.story_title) for user_id in set(reply_user_ids).difference([comment['user_id']]): if request.user.pk != user_id: @@ -500,7 +502,8 @@ def save_comment_reply(request): reply_content=reply_comments, original_message=original_message, social_feed_id=comment_user_id, - story_id=story_id) + story_id=story_id, + story_title=shared_story.story_title) EmailCommentReplies.apply_async(kwargs=dict(shared_story_id=shared_story.id, reply_id=reply.reply_id), countdown=60) @@ -744,15 +747,15 @@ def like_comment(request): shared_story.comments[:30], )) - MActivity.new_comment_like(user_id=request.user.pk, + MActivity.new_comment_like(liking_user_id=request.user.pk, comment_user_id=comment['user_id'], - story_feed_id=feed_id, + social_feed_id=comment['user_id'], story_id=story_id, story_title=shared_story.story_title, comments=shared_story.comments) - MInteraction.new_comment_like(user_id=request.user.pk, - comment_user_id=comment_user_id, - story_feed_id=feed_id, + MInteraction.new_comment_like(liking_user_id=request.user.pk, + comment_user_id=comment['user_id'], + social_feed_id=comment['user_id'], story_id=story_id, story_title=shared_story.story_title, comments=shared_story.comments) diff --git a/templates/static/api.yml b/templates/static/api.yml index cdab1ea1c..2704cfcc7 100644 --- a/templates/static/api.yml +++ b/templates/static/api.yml @@ -342,7 +342,7 @@ optional: true example: "['twitter', 'facebook']" - key: format - desc: "Return a JSON or HTML template" + desc: "Return JSON or a HTML template" optional: true default: "json" example: "html" @@ -363,7 +363,7 @@ required: true example: "http://blog.newsblur.com/post/1" - key: format - desc: "Return a JSON or HTML template" + desc: "Return JSON or a HTML template" optional: true default: "json" example: "html" @@ -537,7 +537,7 @@ optional: true example: "5000...0042" - key: format - desc: "Return a JSON or HTML template" + desc: "Return JSON or a HTML template" optional: true default: "json" example: "html" @@ -561,7 +561,7 @@ required: true example: "64" - key: format - desc: "Return a JSON or HTML template" + desc: "Return JSON or a HTML template" optional: true default: "json" example: "html" @@ -584,7 +584,7 @@ required: true example: "64" - key: format - desc: "Return a JSON or HTML template" + desc: "Return JSON or a HTML template" optional: true default: "json" example: "html"