threadstracker.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from django.db import transaction
  2. from django.utils import timezone
  3. from misago.threads.models import Post
  4. from misago.threads.permissions import exclude_invisible_posts
  5. from .dates import get_cutoff_date
  6. from .models import CategoryRead, ThreadRead
  7. def make_read_aware(user, threads):
  8. if not threads:
  9. return
  10. if not hasattr(threads, '__iter__'):
  11. threads = [threads]
  12. make_read(threads)
  13. if user.is_anonymous:
  14. return
  15. categories = [t.category for t in threads]
  16. queryset = Post.objects.filter(
  17. thread__in=threads,
  18. posted_on__gt=get_cutoff_date(user),
  19. ).values_list('thread', flat=True).distinct()
  20. queryset = queryset.exclude(id__in=user.postread_set.values('post'))
  21. queryset = exclude_invisible_posts(user, categories, queryset)
  22. unread_threads = list(queryset)
  23. for thread in threads:
  24. if thread.pk in unread_threads:
  25. thread.is_read = False
  26. thread.is_new = True
  27. def make_read(threads):
  28. for thread in threads:
  29. thread.is_read = True
  30. thread.is_new = False
  31. # Noop placeholders for exploding tests suite
  32. def make_posts_read_aware(*args, **kwargs):
  33. from misago.core import deprecations
  34. deprecations.warn("threadstracker.make_posts_read_aware has been deprecated")
  35. def read_thread(*args, **kwargs):
  36. from misago.core import deprecations
  37. deprecations.warn("threadstracker.read_thread has been deprecated")