summary refs log tree commit diff
path: root/synapse/handlers/_base.py
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2014-08-26 18:49:51 +0100
committerMark Haines <mark.haines@matrix.org>2014-08-26 18:49:51 +0100
commita498df042839aa166e6fed4f42212f07a2dcf9ca (patch)
tree7a24a55b2d272978f3fcf2b0efa2b519d7183f5d /synapse/handlers/_base.py
parentMove pdu and event persistence into a single persist_event function (diff)
downloadsynapse-a498df042839aa166e6fed4f42212f07a2dcf9ca.tar.xz
Move new event boilerplate in room handlers into a method on a base clase.
Diffstat (limited to 'synapse/handlers/_base.py')
-rw-r--r--synapse/handlers/_base.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/synapse/handlers/_base.py b/synapse/handlers/_base.py
index 3f07b5aa4a..32c0d6b8aa 100644
--- a/synapse/handlers/_base.py
+++ b/synapse/handlers/_base.py
@@ -13,7 +13,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-
+from twisted.internet import defer
 
 class BaseHandler(object):
 
@@ -26,3 +26,21 @@ class BaseHandler(object):
         self.state_handler = hs.get_state_handler()
         self.distributor = hs.get_distributor()
         self.hs = hs
+
+
+class BaseRoomHandler(BaseHandler):
+
+    @defer.inlineCallbacks
+    def _on_new_room_event(self, event, snapshot, extra_destinations=[]):
+        store_id = yield self.store.persist_event(event)
+
+        destinations = set(extra_destinations)
+        # Send a PDU to all hosts who have joined the room.
+        destinations.update((yield self.store.get_joined_hosts_for_room(
+            event.room_id
+        )))
+        event.destinations = list(destinations)
+
+        self.notifier.on_new_room_event(event, store_id)
+
+        yield self.hs.get_federation().handle_new_event(event, snapshot)