syncprivatethreads.py 693 B

1234567891011121314151617181920
  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. """
  6. Middleware that sets private thread participants to sync unread threads
  7. """
  8. def use_this_middleware(self):
  9. if self.mode == PostingEndpoint.REPLY:
  10. return self.thread.thread_type.root_name == PRIVATE_THREADS_ROOT_NAME
  11. return False
  12. def post_save(self, serializer):
  13. set_users_unread_private_threads_sync(
  14. participants=self.thread.participants_list, exclude_user=self.user
  15. )