syncprivatethreads.py 683 B

123456789101112131415161718
  1. from misago.categories import PRIVATE_THREADS_ROOT_NAME
  2. from misago.threads.participants import set_users_unread_private_threads_sync
  3. from . import PostingEndpoint, PostingMiddleware
  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. )