From b65c157d8642f9a952b28975c4bd3d60551ed0fb Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Thu, 4 Jun 2015 15:38:21 -0700 Subject: [PATCH] Adding story_hash to interactions and activities. (For #693). Note that comment_like's may have a null story_hash, although future comment_like's wont. --- apps/social/models.py | 16 ++++++++++++++-- apps/social/views.py | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/apps/social/models.py b/apps/social/models.py index 7ecc291bb..17d8968b8 100644 --- a/apps/social/models.py +++ b/apps/social/models.py @@ -2761,6 +2761,10 @@ class MInteraction(mongo.Document): self.category, self.content and self.content[:20]) def canonical(self): + story_hash = None + if self.story_feed_id: + story_hash = MStory.ensure_story_hash(self.content_id, story_feed_id=self.story_feed_id) + return { 'date': self.date, 'category': self.category, @@ -2770,6 +2774,7 @@ class MInteraction(mongo.Document): 'feed_id': self.feed_id, 'story_feed_id': self.story_feed_id, 'content_id': self.content_id, + 'story_hash': story_hash, } @classmethod @@ -2885,11 +2890,12 @@ class MInteraction(mongo.Document): cls.publish_update_to_subscribers(user_id) @classmethod - def new_comment_like(cls, liking_user_id, comment_user_id, story_id, story_title, comments): + def new_comment_like(cls, liking_user_id, comment_user_id, story_id, story_feed_id, story_title, comments): cls.objects.get_or_create(user_id=comment_user_id, with_user_id=liking_user_id, category="comment_like", feed_id="social:%s" % comment_user_id, + story_feed_id=story_feed_id, content_id=story_id, defaults={ "title": story_title, @@ -2992,6 +2998,10 @@ class MActivity(mongo.Document): return "<%s> %s - %s" % (user.username, self.category, self.content and self.content[:20]) def canonical(self): + story_hash = None + if self.story_feed_id: + story_hash = MStory.ensure_story_hash(self.content_id, story_feed_id=self.story_feed_id) + return { 'date': self.date, 'category': self.category, @@ -3002,6 +3012,7 @@ class MActivity(mongo.Document): 'feed_id': self.feed_id or self.story_feed_id, 'story_feed_id': self.story_feed_id or self.feed_id, 'content_id': self.content_id, + 'story_hash': story_hash, } @classmethod @@ -3127,11 +3138,12 @@ class MActivity(mongo.Document): original.delete() @classmethod - def new_comment_like(cls, liking_user_id, comment_user_id, story_id, story_title, comments): + def new_comment_like(cls, liking_user_id, comment_user_id, story_id, story_feed_id, story_title, comments): cls.objects.get_or_create(user_id=liking_user_id, with_user_id=comment_user_id, category="comment_like", feed_id="social:%s" % comment_user_id, + story_feed_id=story_feed_id, content_id=story_id, defaults={ "title": story_title, diff --git a/apps/social/views.py b/apps/social/views.py index 50b65c67d..9cdfdec36 100644 --- a/apps/social/views.py +++ b/apps/social/views.py @@ -1185,11 +1185,13 @@ def like_comment(request): MActivity.new_comment_like(liking_user_id=request.user.pk, comment_user_id=comment['user_id'], story_id=story_id, + story_feed_id=feed_id, story_title=shared_story.story_title, comments=shared_story.comments) MInteraction.new_comment_like(liking_user_id=request.user.pk, comment_user_id=comment['user_id'], story_id=story_id, + story_feed_id=feed_id, story_title=shared_story.story_title, comments=shared_story.comments)