read.py 822 B

12345678910111213141516171819202122
  1. from rest_framework.response import Response
  2. from ....readtracker import poststracker, threadstracker
  3. from ....readtracker.signals import thread_read
  4. def post_read_endpoint(request, thread, post):
  5. poststracker.make_read_aware(request, post)
  6. if post.is_new:
  7. poststracker.save_read(request.user, post)
  8. if thread.subscription and thread.subscription.last_read_on < post.posted_on:
  9. thread.subscription.last_read_on = post.posted_on
  10. thread.subscription.save()
  11. threadstracker.make_read_aware(request, thread)
  12. # send signal if post read marked thread as read
  13. # used in some places, eg. syncing unread thread count
  14. if post.is_new and thread.is_read:
  15. thread_read.send(request.user, thread=thread)
  16. return Response({"thread_is_read": thread.is_read})