summary refs log tree commit diff
path: root/synapse/events/__init__.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-12-05 16:20:48 +0000
committerErik Johnston <erik@matrix.org>2014-12-05 16:20:48 +0000
commit6630e1b5795667fd947cc5b0d5d2b00da97325e3 (patch)
treece141a61defe211cac454a5953106f6e351fe260 /synapse/events/__init__.py
parentMerge branch 'develop' of github.com:matrix-org/synapse into events_refactor (diff)
downloadsynapse-6630e1b5795667fd947cc5b0d5d2b00da97325e3.tar.xz
Start making more things use EventContext rather than event.*
Diffstat (limited to 'synapse/events/__init__.py')
-rw-r--r--synapse/events/__init__.py35
1 files changed, 33 insertions, 2 deletions
diff --git a/synapse/events/__init__.py b/synapse/events/__init__.py
index 58edf2bc8f..e81b995d39 100644
--- a/synapse/events/__init__.py
+++ b/synapse/events/__init__.py
@@ -17,8 +17,8 @@ from frozendict import frozendict
 
 
 def _freeze(o):
-    if isinstance(o, dict):
-        return frozendict({k: _freeze(v) for k,v in o.items()})
+    if isinstance(o, dict) or isinstance(o, frozendict):
+        return frozendict({k: _freeze(v) for k, v in o.items()})
 
     if isinstance(o, basestring):
         return o
@@ -31,6 +31,21 @@ def _freeze(o):
     return o
 
 
+def _unfreeze(o):
+    if isinstance(o, frozendict) or isinstance(o, dict):
+        return dict({k: _unfreeze(v) for k, v in o.items()})
+
+    if isinstance(o, basestring):
+        return o
+
+    try:
+        return [_unfreeze(i) for i in o]
+    except TypeError:
+        pass
+
+    return o
+
+
 class _EventInternalMetadata(object):
     def __init__(self, internal_metadata_dict):
         self.__dict__ = internal_metadata_dict
@@ -69,6 +84,7 @@ class EventBase(object):
         )
 
     auth_events = _event_dict_property("auth_events")
+    depth = _event_dict_property("depth")
     content = _event_dict_property("content")
     event_id = _event_dict_property("event_id")
     hashes = _event_dict_property("hashes")
@@ -81,6 +97,10 @@ class EventBase(object):
     type = _event_dict_property("type")
     user_id = _event_dict_property("sender")
 
+    @property
+    def membership(self):
+        return self.content["membership"]
+
     def is_state(self):
         return hasattr(self, "state_key")
 
@@ -134,3 +154,14 @@ class FrozenEvent(EventBase):
         e.internal_metadata = event.internal_metadata
 
         return e
+
+    def get_dict(self):
+        # We need to unfreeze what we return
+
+        d = _unfreeze(self._event_dict)
+        d.update({
+            "signatures": self.signatures,
+            "unsigned": self.unsigned,
+        })
+
+        return d