summary refs log tree commit diff
path: root/synapse/events
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2019-05-20 15:54:42 +0100
committerGitHub <noreply@github.com>2019-05-20 15:54:42 +0100
commit5206648a4a2c94543d46e5c22da6fd595b120eeb (patch)
tree5f4263dc0233062e0217433c6674ec92e122b8fe /synapse/events
parentMerge pull request #5211 from matrix-org/erikj/fixup_reaction_constants (diff)
downloadsynapse-5206648a4a2c94543d46e5c22da6fd595b120eeb.tar.xz
Add a test room version which updates event ID format (#5210)
Implements MSC1884
Diffstat (limited to 'synapse/events')
-rw-r--r--synapse/events/__init__.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/synapse/events/__init__.py b/synapse/events/__init__.py
index 12056d5be2..badeb903fc 100644
--- a/synapse/events/__init__.py
+++ b/synapse/events/__init__.py
@@ -335,13 +335,32 @@ class FrozenEventV2(EventBase):
         return self.__repr__()
 
     def __repr__(self):
-        return "<FrozenEventV2 event_id='%s', type='%s', state_key='%s'>" % (
+        return "<%s event_id='%s', type='%s', state_key='%s'>" % (
+            self.__class__.__name__,
             self.event_id,
             self.get("type", None),
             self.get("state_key", None),
         )
 
 
+class FrozenEventV3(FrozenEventV2):
+    """FrozenEventV3, which differs from FrozenEventV2 only in the event_id format"""
+    format_version = EventFormatVersions.V3  # All events of this type are V3
+
+    @property
+    def event_id(self):
+        # We have to import this here as otherwise we get an import loop which
+        # is hard to break.
+        from synapse.crypto.event_signing import compute_event_reference_hash
+
+        if self._event_id:
+            return self._event_id
+        self._event_id = "$" + encode_base64(
+            compute_event_reference_hash(self)[1], urlsafe=True
+        )
+        return self._event_id
+
+
 def room_version_to_event_format(room_version):
     """Converts a room version string to the event format
 
@@ -376,6 +395,8 @@ def event_type_from_format_version(format_version):
         return FrozenEvent
     elif format_version == EventFormatVersions.V2:
         return FrozenEventV2
+    elif format_version == EventFormatVersions.V3:
+        return FrozenEventV3
     else:
         raise Exception(
             "No event format %r" % (format_version,)