Browse Source

fix #681: update thread subsription on post read

Rafał Pitoń 8 years ago
parent
commit
eabbed4d97

+ 5 - 2
misago/threads/api/postendpoints/read.py

@@ -7,7 +7,10 @@ def post_read_endpoint(request, thread, post):
     make_posts_read_aware(request.user, thread, [post])
     if not post.is_read:
         read_thread(request.user, thread, post)
-        if thread.subscription:
+        if thread.subscription and thread.subscription.last_read_on < post.posted_on:
             thread.subscription.last_read_on = post.posted_on
-        return Response({'thread_is_read': thread.last_post_on <= post.posted_on})
+            thread.subscription.save()
+        return Response({
+            'thread_is_read': thread.last_post_on <= post.posted_on
+        })
     return Response({'thread_is_read': True})

+ 2 - 1
misago/threads/tests/test_thread_postread_api.py

@@ -46,7 +46,7 @@ class PostReadApiTests(ThreadsApiTestCase):
             user=self.user,
             thread=self.thread,
             category=self.thread.category,
-            last_read_on=self.thread.post_set.order_by('id').last().posted_on
+            last_read_on=self.thread.post_set.order_by('id').first().posted_on
         )
 
         response = self.client.post(self.api_link)
@@ -61,3 +61,4 @@ class PostReadApiTests(ThreadsApiTestCase):
 
         subscription = self.thread.subscription_set.order_by('id').last()
         self.assertEqual(subscription.last_read_on, self.post.posted_on)
+