push.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2021 The Matrix.org Foundation C.I.C.
  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. import logging
  16. from typing import TYPE_CHECKING
  17. from synapse.http.servlet import parse_json_object_from_request
  18. from synapse.replication.http._base import ReplicationEndpoint
  19. if TYPE_CHECKING:
  20. from synapse.server import HomeServer
  21. logger = logging.getLogger(__name__)
  22. class ReplicationRemovePusherRestServlet(ReplicationEndpoint):
  23. """Deletes the given pusher.
  24. Request format:
  25. POST /_synapse/replication/remove_pusher/:user_id
  26. {
  27. "app_id": "<some_id>",
  28. "pushkey": "<some_key>"
  29. }
  30. """
  31. NAME = "add_user_account_data"
  32. PATH_ARGS = ("user_id",)
  33. CACHE = False
  34. def __init__(self, hs: "HomeServer"):
  35. super().__init__(hs)
  36. self.pusher_pool = hs.get_pusherpool()
  37. @staticmethod
  38. async def _serialize_payload(app_id, pushkey, user_id):
  39. payload = {
  40. "app_id": app_id,
  41. "pushkey": pushkey,
  42. }
  43. return payload
  44. async def _handle_request(self, request, user_id):
  45. content = parse_json_object_from_request(request)
  46. app_id = content["app_id"]
  47. pushkey = content["pushkey"]
  48. await self.pusher_pool.remove_pusher(app_id, pushkey, user_id)
  49. return 200, {}
  50. def register_servlets(hs, http_server):
  51. ReplicationRemovePusherRestServlet(hs).register(http_server)