summary refs log tree commit diff
path: root/synapse/handlers/register.py
diff options
context:
space:
mode:
authorMatthew Hodgson <matthew@matrix.org>2015-02-07 13:32:14 +0000
committerMatthew Hodgson <matthew@matrix.org>2015-02-07 13:32:14 +0000
commit582019f870adbc4a8a8a9ef97b527e0fead77761 (patch)
tree64ee36588a1fdf1bd70c9831059a3948ef0b1951 /synapse/handlers/register.py
parentcreate identicons for new users by default as default avatars, and provide sc... (diff)
downloadsynapse-582019f870adbc4a8a8a9ef97b527e0fead77761.tar.xz
...and here's the actual impl. git fail.
Diffstat (limited to 'synapse/handlers/register.py')
-rw-r--r--synapse/handlers/register.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py
index 66a89c10b2..2b9d860084 100644
--- a/synapse/handlers/register.py
+++ b/synapse/handlers/register.py
@@ -99,6 +99,20 @@ class RegistrationHandler(BaseHandler):
                         raise RegistrationError(
                             500, "Cannot generate user ID.")
 
+        # create a default avatar for the user
+        # XXX: ideally clients would explicitly specify one, but given they don't
+        # and we want consistent and pretty identicons for random users, we'll
+        # do it here.
+        auth_user = UserID.from_string(user_id)
+        identicon_resource = self.hs.get_resource_for_media_repository().getChildWithDefault("identicon", None)
+        upload_resource = self.hs.get_resource_for_media_repository().getChildWithDefault("upload", None)
+        identicon_bytes = identicon_resource.generate_identicon(user_id, 320, 320)
+        content_uri = yield upload_resource.create_content(
+            "image/png", None, identicon_bytes, len(identicon_bytes), auth_user
+        )
+        profile_handler = self.hs.get_handlers().profile_handler
+        profile_handler.set_avatar_url(auth_user, auth_user, ("%s#auto" % content_uri))
+        
         defer.returnValue((user_id, token))
 
     @defer.inlineCallbacks