1# Copyright 2021 The Matrix.org Foundation C.I.C. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15import logging 16from typing import TYPE_CHECKING 17 18from synapse.http.servlet import parse_json_object_from_request 19from synapse.replication.http._base import ReplicationEndpoint 20 21if TYPE_CHECKING: 22 from synapse.server import HomeServer 23 24logger = logging.getLogger(__name__) 25 26 27class ReplicationRemovePusherRestServlet(ReplicationEndpoint): 28 """Deletes the given pusher. 29 30 Request format: 31 32 POST /_synapse/replication/remove_pusher/:user_id 33 34 { 35 "app_id": "<some_id>", 36 "pushkey": "<some_key>" 37 } 38 39 """ 40 41 NAME = "add_user_account_data" 42 PATH_ARGS = ("user_id",) 43 CACHE = False 44 45 def __init__(self, hs: "HomeServer"): 46 super().__init__(hs) 47 48 self.pusher_pool = hs.get_pusherpool() 49 50 @staticmethod 51 async def _serialize_payload(app_id, pushkey, user_id): 52 payload = { 53 "app_id": app_id, 54 "pushkey": pushkey, 55 } 56 57 return payload 58 59 async def _handle_request(self, request, user_id): 60 content = parse_json_object_from_request(request) 61 62 app_id = content["app_id"] 63 pushkey = content["pushkey"] 64 65 await self.pusher_pool.remove_pusher(app_id, pushkey, user_id) 66 67 return 200, {} 68 69 70def register_servlets(hs: "HomeServer", http_server): 71 ReplicationRemovePusherRestServlet(hs).register(http_server) 72