diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2022-07-13 13:23:16 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-13 13:23:16 -0400 |
commit | 1d5c80b16188c587427d663c3bec57e9c196dd1b (patch) | |
tree | e92bf886e44579a5f64d504728c677cb8a2d47f4 /synapse/rest/client/receipts.py | |
parent | Add prometheus counters for content types other than events (#13175) (diff) | |
download | synapse-1d5c80b16188c587427d663c3bec57e9c196dd1b.tar.xz |
Reduce duplicate code in receipts servlets. (#13198)
Diffstat (limited to 'synapse/rest/client/receipts.py')
-rw-r--r-- | synapse/rest/client/receipts.py | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/synapse/rest/client/receipts.py b/synapse/rest/client/receipts.py index 4b03eb876b..409bfd43c1 100644 --- a/synapse/rest/client/receipts.py +++ b/synapse/rest/client/receipts.py @@ -39,31 +39,27 @@ class ReceiptRestServlet(RestServlet): def __init__(self, hs: "HomeServer"): super().__init__() - self.hs = hs self.auth = hs.get_auth() self.receipts_handler = hs.get_receipts_handler() self.read_marker_handler = hs.get_read_marker_handler() self.presence_handler = hs.get_presence_handler() + self._known_receipt_types = {ReceiptTypes.READ} + if hs.config.experimental.msc2285_enabled: + self._known_receipt_types.update( + (ReceiptTypes.READ_PRIVATE, ReceiptTypes.FULLY_READ) + ) + async def on_POST( self, request: SynapseRequest, room_id: str, receipt_type: str, event_id: str ) -> Tuple[int, JsonDict]: requester = await self.auth.get_user_by_req(request) - if self.hs.config.experimental.msc2285_enabled and receipt_type not in [ - ReceiptTypes.READ, - ReceiptTypes.READ_PRIVATE, - ReceiptTypes.FULLY_READ, - ]: + if receipt_type not in self._known_receipt_types: raise SynapseError( 400, - "Receipt type must be 'm.read', 'org.matrix.msc2285.read.private' or 'm.fully_read'", + f"Receipt type must be {', '.join(self._known_receipt_types)}", ) - elif ( - not self.hs.config.experimental.msc2285_enabled - and receipt_type != ReceiptTypes.READ - ): - raise SynapseError(400, "Receipt type must be 'm.read'") parse_json_object_from_request(request, allow_empty_body=False) |