Browse Source

fix #924: events are now marked as read by default for users that caused them

Rafał Pitoń 7 years ago
parent
commit
c38230c828

+ 4 - 0
misago/threads/events.py

@@ -1,5 +1,7 @@
 from django.utils import timezone
 
+from misago.readtracker import poststracker
+
 from .models import Post
 
 
@@ -31,4 +33,6 @@ def record_event(request, thread, event_type, context=None, commit=True):
         if commit:
             thread.category.save()
 
+    poststracker.save_read(request.user, event)
+
     return event

+ 11 - 0
misago/threads/tests/test_events.py

@@ -58,3 +58,14 @@ class EventsAPITests(TestCase):
         self.assertEqual(event_post.event_context, context)
         self.assertEqual(event_post.poster_id, request.user.pk)
         self.assertEqual(event_post.poster_ip, request.user_ip)
+
+    def test_record_event_is_read(self):
+        """record_event makes recorded event read to its author"""
+        request = MockRequest(self.user)
+        event = record_event(request, self.thread, 'announcement')
+
+        self.user.postread_set.get(
+            category=self.category,
+            thread=self.thread,
+            post=event,
+        )

+ 4 - 4
misago/threads/tests/test_thread_merge_api.py

@@ -313,14 +313,14 @@ class ThreadMergeApiTests(ThreadsApiTestCase):
         self.assertContains(response, other_thread.get_absolute_url(), status_code=200)
 
         # posts reads are kept
-        postread_set = self.user.postread_set.order_by('post_id')
+        postreads = self.user.postread_set.filter(post__is_event=False).order_by('id')
 
         self.assertEqual(
-            list(postread_set.values_list('post_id', flat=True)),
+            list(postreads.values_list('post_id', flat=True)),
             [self.thread.first_post_id, other_thread.first_post_id]
         )
-        self.assertEqual(postread_set.filter(thread=other_thread).count(), 2)
-        self.assertEqual(postread_set.filter(category=self.category_b).count(), 2)
+        self.assertEqual(postreads.filter(thread=other_thread).count(), 2)
+        self.assertEqual(postreads.filter(category=self.category_b).count(), 2)
 
     def test_merge_threads_kept_subs(self):
         """api keeps other thread's subscription after merge"""

+ 4 - 2
misago/threads/tests/test_thread_patch_api.py

@@ -580,8 +580,10 @@ class ThreadMoveApiTests(ThreadPatchApiTestCase):
         self.assertEqual(response.status_code, 200)
 
         # thread read was moved to new category
-        self.assertEqual(self.user.postread_set.count(), 1)
-        self.user.postread_set.get(category=self.category_b)
+        postreads = self.user.postread_set.filter(post__is_event=False).order_by('id')
+
+        self.assertEqual(postreads.count(), 1)
+        postreads.get(category=self.category_b)
 
     def test_move_thread_subscriptions(self):
         """api moves thread subscriptions together with thread"""

+ 1 - 1
misago/threads/tests/test_thread_postsplit_api.py

@@ -648,7 +648,7 @@ class ThreadPostSplitApiTestCase(AuthenticatedUserTestCase):
         self.assertEqual(split_thread.post_set.filter(pk__in=self.posts).count(), 2)
 
         # postreads were removed
-        postreads = self.user.postread_set.order_by('id')
+        postreads = self.user.postread_set.filter(post__is_event=False).order_by('id')
 
         postreads_threads = list(postreads.values_list('thread_id', flat=True))
         self.assertEqual(postreads_threads, [self.thread.pk])

+ 4 - 4
misago/threads/tests/test_threads_merge_api.py

@@ -786,14 +786,14 @@ class ThreadsMergeApiTests(ThreadsApiTestCase):
         self.assertEqual([t.pk for t in Thread.objects.all()], [new_thread.pk])
 
         # posts reads are kept
-        postread_set = self.user.postread_set.order_by('post_id')
+        postreads = self.user.postread_set.filter(post__is_event=False).order_by('id')
 
         self.assertEqual(
-            list(postread_set.values_list('post_id', flat=True)),
+            list(postreads.values_list('post_id', flat=True)),
             [self.thread.first_post_id, thread.first_post_id]
         )
-        self.assertEqual(postread_set.filter(thread=new_thread).count(), 2)
-        self.assertEqual(postread_set.filter(category=self.category).count(), 2)
+        self.assertEqual(postreads.filter(thread=new_thread).count(), 2)
+        self.assertEqual(postreads.filter(category=self.category).count(), 2)
 
         # subscriptions are kept
         self.assertEqual(self.user.subscription_set.count(), 1)