summary refs log tree commit diff
path: root/synapse/rest/client/v1/room.py
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/rest/client/v1/room.py')
-rw-r--r--synapse/rest/client/v1/room.py97
1 files changed, 27 insertions, 70 deletions
diff --git a/synapse/rest/client/v1/room.py b/synapse/rest/client/v1/room.py
index 7af4077721..0622e64380 100644
--- a/synapse/rest/client/v1/room.py
+++ b/synapse/rest/client/v1/room.py
@@ -22,7 +22,6 @@ from synapse.streams.config import PaginationConfig
 from synapse.api.constants import EventTypes, Membership
 from synapse.api.filtering import Filter
 from synapse.types import UserID, RoomID, RoomAlias
-from synapse.util.async import ObservableDeferred
 from synapse.events.utils import serialize_event, format_event_for_client_v2
 from synapse.http.servlet import (
     parse_json_object_from_request, parse_string, parse_integer
@@ -56,17 +55,11 @@ class RoomCreateRestServlet(ClientV1RestServlet):
 
     @defer.inlineCallbacks
     def on_PUT(self, request, txn_id):
-        try:
-            res_deferred = self.txns.get_client_transaction(request, txn_id)
-            res = yield res_deferred.observe()
-            defer.returnValue(res)
-        except KeyError:
-            pass
-
-        res_deferred = ObservableDeferred(self.on_POST(request))
-        self.txns.store_client_transaction(request, txn_id, res_deferred)
-        response = yield res_deferred.observe()
-        defer.returnValue(response)
+        observable = self.txns.fetch_or_execute_request(
+            request, self.on_POST, request
+        )
+        res = yield observable.observe()
+        defer.returnValue(res)
 
     @defer.inlineCallbacks
     def on_POST(self, request):
@@ -217,19 +210,11 @@ class RoomSendEventRestServlet(ClientV1RestServlet):
 
     @defer.inlineCallbacks
     def on_PUT(self, request, room_id, event_type, txn_id):
-        try:
-            res_deferred = self.txns.get_client_transaction(request, txn_id)
-            res = yield res_deferred.observe()
-            defer.returnValue(res)
-        except KeyError:
-            pass
-
-        res_deferred = ObservableDeferred(
-            self.on_POST(request, room_id, event_type, txn_id)
+        observable = self.txns.fetch_or_execute_request(
+            request, self.on_POST, request, room_id, event_type, txn_id
         )
-        self.txns.store_client_transaction(request, txn_id, res_deferred)
-        response = yield res_deferred.observe()
-        defer.returnValue(response)
+        res = yield observable.observe()
+        defer.returnValue(res)
 
 
 # TODO: Needs unit testing for room ID + alias joins
@@ -288,17 +273,11 @@ class JoinRoomAliasServlet(ClientV1RestServlet):
 
     @defer.inlineCallbacks
     def on_PUT(self, request, room_identifier, txn_id):
-        try:
-            res_deferred = self.txns.get_client_transaction(request, txn_id)
-            res = yield res_deferred.observe()
-            defer.returnValue(res)
-        except KeyError:
-            pass
-
-        res_deferred = ObservableDeferred(self.on_POST(request, room_identifier, txn_id))
-        self.txns.store_client_transaction(request, txn_id, res_deferred)
-        response = yield res_deferred.observe()
-        defer.returnValue(response)
+        observable = self.txns.fetch_or_execute_request(
+            request, self.on_POST, request, room_identifier, txn_id
+        )
+        res = yield observable.observe()
+        defer.returnValue(res)
 
 
 # TODO: Needs unit testing
@@ -542,17 +521,11 @@ class RoomForgetRestServlet(ClientV1RestServlet):
 
     @defer.inlineCallbacks
     def on_PUT(self, request, room_id, txn_id):
-        try:
-            res_deferred = self.txns.get_client_transaction(request, txn_id)
-            res = yield res_deferred.observe()
-            defer.returnValue(res)
-        except KeyError:
-            pass
-
-        res_deferred = ObservableDeferred(self.on_POST(request, room_id, txn_id))
-        self.txns.store_client_transaction(request, txn_id, res_deferred)
-        response = yield res_deferred.observe()
-        defer.returnValue(response)
+        observable = self.txns.fetch_or_execute_request(
+            request, self.on_POST, request, room_id, txn_id
+        )
+        res = yield observable.observe()
+        defer.returnValue(res)
 
 
 # TODO: Needs unit testing
@@ -626,19 +599,11 @@ class RoomMembershipRestServlet(ClientV1RestServlet):
 
     @defer.inlineCallbacks
     def on_PUT(self, request, room_id, membership_action, txn_id):
-        try:
-            res_deferred = self.txns.get_client_transaction(request, txn_id)
-            res = yield res_deferred.observe()
-            defer.returnValue(res)
-        except KeyError:
-            pass
-
-        res_deferred = ObservableDeferred(
-            self.on_POST(request, room_id, membership_action, txn_id)
+        observable = self.txns.fetch_or_execute_request(
+            request, self.on_POST, request, room_id, membership_action, txn_id
         )
-        self.txns.store_client_transaction(request, txn_id, res_deferred)
-        response = yield res_deferred.observe()
-        defer.returnValue(response)
+        res = yield observable.observe()
+        defer.returnValue(res)
 
 
 class RoomRedactEventRestServlet(ClientV1RestServlet):
@@ -672,19 +637,11 @@ class RoomRedactEventRestServlet(ClientV1RestServlet):
 
     @defer.inlineCallbacks
     def on_PUT(self, request, room_id, event_id, txn_id):
-        try:
-            res_deferred = self.txns.get_client_transaction(request, txn_id)
-            res = yield res_deferred.observe()
-            defer.returnValue(res)
-        except KeyError:
-            pass
-
-        res_deferred = ObservableDeferred(
-            self.on_POST(request, room_id, event_id, txn_id)
+        observable = self.txns.fetch_or_execute_request(
+            request, self.on_POST, request, room_id, event_id, txn_id
         )
-        self.txns.store_client_transaction(request, txn_id, res_deferred)
-        response = yield res_deferred.observe()
-        defer.returnValue(response)
+        res = yield observable.observe()
+        defer.returnValue(res)
 
 
 class RoomTypingRestServlet(ClientV1RestServlet):