summary refs log tree commit diff
path: root/synapse/handlers/state_deltas.py
diff options
context:
space:
mode:
authorDavid Robertson <davidr@element.io>2021-09-10 10:54:38 +0100
committerGitHub <noreply@github.com>2021-09-10 10:54:38 +0100
commit318162f5debc595d3381337fe363fa7936cc7843 (patch)
tree2a6451443ea2e9ecd6fe8ff973ab202abe48b42e /synapse/handlers/state_deltas.py
parentRemove fixed and flakey tests from the sytest blacklist (#10788) (diff)
downloadsynapse-318162f5debc595d3381337fe363fa7936cc7843.tar.xz
Easy refactors of the user directory (#10789)
No functional changes here. This came out as I was working to tackle #5677 
Diffstat (limited to 'synapse/handlers/state_deltas.py')
-rw-r--r--synapse/handlers/state_deltas.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/synapse/handlers/state_deltas.py b/synapse/handlers/state_deltas.py
index 077c7c0649..d30ba2b724 100644
--- a/synapse/handlers/state_deltas.py
+++ b/synapse/handlers/state_deltas.py
@@ -13,6 +13,7 @@
 # limitations under the License.
 
 import logging
+from enum import Enum, auto
 from typing import TYPE_CHECKING, Optional
 
 if TYPE_CHECKING:
@@ -21,6 +22,12 @@ if TYPE_CHECKING:
 logger = logging.getLogger(__name__)
 
 
+class MatchChange(Enum):
+    no_change = auto()
+    now_true = auto()
+    now_false = auto()
+
+
 class StateDeltasHandler:
     def __init__(self, hs: "HomeServer"):
         self.store = hs.get_datastore()
@@ -31,18 +38,12 @@ class StateDeltasHandler:
         event_id: Optional[str],
         key_name: str,
         public_value: str,
-    ) -> Optional[bool]:
+    ) -> MatchChange:
         """Given two events check if the `key_name` field in content changed
         from not matching `public_value` to doing so.
 
         For example, check if `history_visibility` (`key_name`) changed from
         `shared` to `world_readable` (`public_value`).
-
-        Returns:
-            None if the field in the events either both match `public_value`
-            or if neither do, i.e. there has been no change.
-            True if it didn't match `public_value` but now does
-            False if it did match `public_value` but now doesn't
         """
         prev_event = None
         event = None
@@ -54,7 +55,7 @@ class StateDeltasHandler:
 
         if not event and not prev_event:
             logger.debug("Neither event exists: %r %r", prev_event_id, event_id)
-            return None
+            return MatchChange.no_change
 
         prev_value = None
         value = None
@@ -68,8 +69,8 @@ class StateDeltasHandler:
         logger.debug("prev_value: %r -> value: %r", prev_value, value)
 
         if value == public_value and prev_value != public_value:
-            return True
+            return MatchChange.now_true
         elif value != public_value and prev_value == public_value:
-            return False
+            return MatchChange.now_false
         else:
-            return None
+            return MatchChange.no_change