syncprivatethreads.py 699 B

1234567891011121314151617181920
  1. from misago.categories.models import PRIVATE_THREADS_ROOT_NAME
  2. from ...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,
  15. exclude_user=self.user
  16. )