summary refs log tree commit diff
path: root/synapse/handlers/user_directory.py
diff options
context:
space:
mode:
authorErik Johnston <erikj@jki.re>2017-06-01 17:33:20 +0100
committerGitHub <noreply@github.com>2017-06-01 17:33:20 +0100
commit8d34120a533889eb783c9b858d7d5dae5018ee3e (patch)
tree6451d37794ea282887b2edc64228a6fbdf430ec5 /synapse/handlers/user_directory.py
parentMerge pull request #2252 from matrix-org/erikj/user_dir (diff)
parentHandle profile updates in user directory (diff)
downloadsynapse-8d34120a533889eb783c9b858d7d5dae5018ee3e.tar.xz
Merge pull request #2253 from matrix-org/erikj/user_dir
Handle profile updates in user directory
Diffstat (limited to 'synapse/handlers/user_directory.py')
-rw-r--r--synapse/handlers/user_directory.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/synapse/handlers/user_directory.py b/synapse/handlers/user_directory.py
index d795a9f8d5..0182cf86d6 100644
--- a/synapse/handlers/user_directory.py
+++ b/synapse/handlers/user_directory.py
@@ -192,6 +192,8 @@ class UserDirectoyHandler(object):
                 )
 
                 if change is None:
+                    # Handle any profile changes
+                    yield self._handle_profile_change(state_key, prev_event_id, event_id)
                     continue
 
                 if not change:
@@ -360,6 +362,29 @@ class UserDirectoyHandler(object):
             yield self.store.remove_from_user_in_public_room(user_id)
 
     @defer.inlineCallbacks
+    def _handle_profile_change(self, user_id, prev_event_id, event_id):
+        """Check member event changes for any profile changes and update the
+        database if there are.
+        """
+        if not prev_event_id or not event_id:
+            return
+
+        prev_event = yield self.store.get_event(prev_event_id)
+        event = yield self.store.get_event(event_id)
+
+        if event.membership != Membership.JOIN:
+            return
+
+        prev_name = prev_event.content.get("displayname")
+        new_name = event.content.get("displayname")
+
+        prev_avatar = prev_event.content.get("avatar_url")
+        new_avatar = event.content.get("avatar_url")
+
+        if prev_name != new_name or prev_avatar != new_avatar:
+            yield self.store.update_profile_in_user_dir(user_id, new_name, new_avatar)
+
+    @defer.inlineCallbacks
     def _get_key_change(self, prev_event_id, event_id, key_name, public_value):
         """Given two events check if the `key_name` field in content changed
         from not matching `public_value` to doing so.