From 29ba2713368091e7b7039ced229701a185301edf Mon Sep 17 00:00:00 2001 From: nitely Date: Thu, 23 Mar 2017 23:34:50 -0300 Subject: [PATCH 1/2] topic.notification update mention if notification.date <= comment.date --- spirit/topic/notification/models.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/spirit/topic/notification/models.py b/spirit/topic/notification/models.py index 5cbc07a9e..269422f1b 100644 --- a/spirit/topic/notification/models.py +++ b/spirit/topic/notification/models.py @@ -98,14 +98,21 @@ def notify_new_mentions(cls, comment, mentions): topic=comment.topic, comment=comment, action=MENTION, - is_active=True - ) + is_active=True) except IntegrityError: pass - cls.objects\ - .filter(user__in=mentions.values(), topic=comment.topic, is_read=True)\ - .update(comment=comment, is_read=False, action=MENTION, date=timezone.now()) + (cls.objects + .filter( + user__in=mentions.values(), + topic=comment.topic, + is_read=True, + date__lte=comment.date) + .update( + comment=comment, + is_read=False, + action=MENTION, + date=timezone.now())) @classmethod def bulk_create(cls, users, comment): From 645f05c1485abe28390f3425294f22cf37437884 Mon Sep 17 00:00:00 2001 From: nitely Date: Thu, 23 Mar 2017 23:57:27 -0300 Subject: [PATCH 2/2] comment mentions on post_comment_update --- spirit/comment/utils.py | 5 ++++- spirit/comment/views.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/spirit/comment/utils.py b/spirit/comment/utils.py index 2a8a7c1dd..5f583d7e2 100644 --- a/spirit/comment/utils.py +++ b/spirit/comment/utils.py @@ -21,8 +21,11 @@ def pre_comment_update(comment): CommentHistory.create_maybe(comment) -def post_comment_update(comment): +def post_comment_update(comment, mentions=None): comment.increase_modified_count() comment.comment_html = post_render_static_polls(comment) CommentHistory.create(comment) + + TopicNotification.notify_new_mentions( + comment=comment, mentions=mentions) diff --git a/spirit/comment/views.py b/spirit/comment/views.py index 06de42a43..94ebc3ed2 100644 --- a/spirit/comment/views.py +++ b/spirit/comment/views.py @@ -68,7 +68,7 @@ def update(request, pk): if form.is_valid(): pre_comment_update(comment=Comment.objects.get(pk=comment.pk)) comment = form.save() - post_comment_update(comment=comment) + post_comment_update(comment=comment, mentions=form.mentions) return redirect(request.POST.get('next', comment.get_absolute_url())) else: form = CommentForm(instance=comment)