summary refs log tree commit diff
path: root/synapse/handlers/user_directory.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-06-01 15:39:51 +0100
committerErik Johnston <erik@matrix.org>2017-06-01 15:39:51 +0100
commit1a01af079e97d25bbac46127b8bd069189c02c97 (patch)
tree6451d37794ea282887b2edc64228a6fbdf430ec5 /synapse/handlers/user_directory.py
parentFix sqlite (diff)
downloadsynapse-1a01af079e97d25bbac46127b8bd069189c02c97.tar.xz
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.