initial_sync.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2014-2016 OpenMarket Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from twisted.internet import defer
  16. from synapse.streams.config import PaginationConfig
  17. from .base import ClientV1RestServlet, client_path_patterns
  18. # TODO: Needs unit testing
  19. class InitialSyncRestServlet(ClientV1RestServlet):
  20. PATTERNS = client_path_patterns("/initialSync$")
  21. def __init__(self, hs):
  22. super(InitialSyncRestServlet, self).__init__(hs)
  23. self.initial_sync_handler = hs.get_initial_sync_handler()
  24. @defer.inlineCallbacks
  25. def on_GET(self, request):
  26. requester = yield self.auth.get_user_by_req(request)
  27. as_client_event = "raw" not in request.args
  28. pagination_config = PaginationConfig.from_request(request)
  29. include_archived = request.args.get("archived", None) == ["true"]
  30. content = yield self.initial_sync_handler.snapshot_all_rooms(
  31. user_id=requester.user.to_string(),
  32. pagin_config=pagination_config,
  33. as_client_event=as_client_event,
  34. include_archived=include_archived,
  35. )
  36. defer.returnValue((200, content))
  37. def register_servlets(hs, http_server):
  38. InitialSyncRestServlet(hs).register(http_server)