syncprivatethreads.py 667 B

1234567891011121314151617
  1. from . import PostingEndpoint, PostingMiddleware
  2. from ....categories import PRIVATE_THREADS_ROOT_NAME
  3. from ...participants import set_users_unread_private_threads_sync
  4. class SyncPrivateThreadsMiddleware(PostingMiddleware):
  5. """middleware that sets private thread participants to sync unread threads"""
  6. def use_this_middleware(self):
  7. if self.mode == PostingEndpoint.REPLY:
  8. return self.thread.thread_type.root_name == PRIVATE_THREADS_ROOT_NAME
  9. return False
  10. def post_save(self, serializer):
  11. set_users_unread_private_threads_sync(
  12. participants=self.thread.participants_list, exclude_user=self.user
  13. )