initial_sync.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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.http.servlet import RestServlet, parse_boolean
  17. from synapse.rest.client.v2_alpha._base import client_patterns
  18. from synapse.streams.config import PaginationConfig
  19. # TODO: Needs unit testing
  20. class InitialSyncRestServlet(RestServlet):
  21. PATTERNS = client_patterns("/initialSync$", v1=True)
  22. def __init__(self, hs):
  23. super(InitialSyncRestServlet, self).__init__()
  24. self.initial_sync_handler = hs.get_initial_sync_handler()
  25. self.auth = hs.get_auth()
  26. @defer.inlineCallbacks
  27. def on_GET(self, request):
  28. requester = yield self.auth.get_user_by_req(request)
  29. as_client_event = b"raw" not in request.args
  30. pagination_config = PaginationConfig.from_request(request)
  31. include_archived = parse_boolean(request, "archived", default=False)
  32. content = yield self.initial_sync_handler.snapshot_all_rooms(
  33. user_id=requester.user.to_string(),
  34. pagin_config=pagination_config,
  35. as_client_event=as_client_event,
  36. include_archived=include_archived,
  37. )
  38. return (200, content)
  39. def register_servlets(hs, http_server):
  40. InitialSyncRestServlet(hs).register(http_server)