Example #1
0
    def test_user_unread_post(self):
        """tracked post is marked as unread for authenticated users"""
        post = testutils.reply_thread(self.thread, posted_on=timezone.now())

        poststracker.make_read_aware(self.user, post)
        self.assertFalse(post.is_read)
        self.assertTrue(post.is_new)
Example #2
0
    def test_anon_post_after_cutoff(self):
        """tracked post is marked as read for anonymous users"""
        post = testutils.reply_thread(self.thread, posted_on=timezone.now())

        poststracker.make_read_aware(AnonymousUser(), post)
        self.assertTrue(post.is_read)
        self.assertFalse(post.is_new)
Example #3
0
    def test_user_created_after_post(self):
        """tracked post older than user is marked as read"""
        posted_on = timezone.now() - timedelta(days=1)
        post = testutils.reply_thread(self.thread, posted_on=posted_on)

        poststracker.make_read_aware(self.user, post)
        self.assertTrue(post.is_read)
        self.assertFalse(post.is_new)
Example #4
0
    def __init__(self, request, thread, page):
        try:
            thread_model = thread.unwrap()
        except AttributeError:
            thread_model = thread

        posts_queryset = self.get_posts_queryset(request, thread_model)

        posts_limit = settings.MISAGO_POSTS_PER_PAGE
        posts_orphans = settings.MISAGO_POSTS_TAIL
        list_page = paginate(posts_queryset,
                             page,
                             posts_limit,
                             posts_orphans,
                             paginator=PostsPaginator)
        paginator = pagination_dict(list_page)

        posts = list(list_page.object_list)
        posters = []

        for post in posts:
            post.category = thread.category
            post.thread = thread_model

            if post.poster:
                posters.append(post.poster)

        make_users_status_aware(request.user, posters)

        if thread.category.acl['can_see_posts_likes']:
            add_likes_to_posts(request.user, posts)

        # add events to posts
        if thread_model.has_events:
            first_post = None
            if list_page.has_previous():
                first_post = posts[0]
            last_post = None
            if list_page.has_next():
                last_post = posts[-1]

            events_limit = settings.MISAGO_EVENTS_PER_PAGE
            posts += self.get_events_queryset(request, thread_model,
                                              events_limit, first_post,
                                              last_post)

            # sort both by pk
            posts.sort(key=lambda p: p.pk)

        # make posts and events ACL and reads aware
        add_acl(request.user, posts)
        make_read_aware(request.user, posts)

        self._user = request.user

        self.posts = posts
        self.paginator = paginator
Example #5
0
    def test_user_post_before_cutoff(self):
        """untracked post is marked as read for authenticated users"""
        posted_on = timezone.now() - timedelta(
            days=settings.MISAGO_READTRACKER_CUTOFF)
        post = testutils.reply_thread(self.thread, posted_on=posted_on)

        poststracker.make_read_aware(self.user, post)
        self.assertTrue(post.is_read)
        self.assertFalse(post.is_new)
Example #6
0
    def test_anon_post_before_cutoff(self):
        """non-tracked post is marked as read for anonymous users"""
        posted_on = timezone.now() - timedelta(
            days=settings.MISAGO_READTRACKER_CUTOFF)
        post = testutils.reply_thread(self.thread, posted_on=posted_on)

        poststracker.make_read_aware(AnonymousUser(), post)
        self.assertTrue(post.is_read)
        self.assertFalse(post.is_new)
def post_read_endpoint(request, thread, post):
    poststracker.make_read_aware(request.user, post)
    if post.is_new:
        poststracker.save_read(request.user, post)
        if thread.subscription and thread.subscription.last_read_on < post.posted_on:
            thread.subscription.last_read_on = post.posted_on
            thread.subscription.save()

    threadstracker.make_read_aware(request.user, thread)

    # send signal if post read marked thread as read
    # used in some places, eg. syncing unread thread count
    if post.is_new and thread.is_read:
        thread_read.send(request.user, thread=thread)

    return Response({'thread_is_read': thread.is_read})
Example #8
0
 def test_falsy_value(self):
     """passing falsy value to readtracker causes no errors"""
     poststracker.make_read_aware(self.user, None)
     poststracker.make_read_aware(self.user, False)
     poststracker.make_read_aware(self.user, [])