From 15e84f68617cb6e2778d335272048edf4c85dc59 Mon Sep 17 00:00:00 2001 From: Max Sandholm Date: Tue, 4 Apr 2017 00:07:07 +0300 Subject: [PATCH] Handle users without profile pictures correctly --- telematrix/__init__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/telematrix/__init__.py b/telematrix/__init__.py index f3663b6..c6b9ea9 100644 --- a/telematrix/__init__.py +++ b/telematrix/__init__.py @@ -471,14 +471,20 @@ async def update_matrix_displayname_avatar(tg_user): await matrix_put('client', 'profile/{}/displayname'.format(user_id), user_id, {'displayname': name}) db_user.name = name if db_user.profile_pic_id != pp_file_id: - pp_uri, _ = await upload_tgfile_to_matrix(pp_file_id, user_id) - await matrix_put('client', 'profile/{}/avatar_url'.format(user_id), user_id, {'avatar_url':pp_uri}) + if pp_file_id: + pp_uri, _ = await upload_tgfile_to_matrix(pp_file_id, user_id) + await matrix_put('client', 'profile/{}/avatar_url'.format(user_id), user_id, {'avatar_url':pp_uri}) + else: + await matrix_put('client', 'profile/{}/avatar_url'.format(user_id), user_id, {'avatar_url':None}) db_user.profile_pic_id = pp_file_id else: db_user = db.TgUser(tg_user['id'], name, pp_file_id) await matrix_put('client', 'profile/{}/displayname'.format(user_id), user_id, {'displayname': name}) - pp_uri, _ = await upload_tgfile_to_matrix(pp_file_id, user_id) - await matrix_put('client', 'profile/{}/avatar_url'.format(user_id), user_id, {'avatar_url':pp_uri}) + if pp_file_id: + pp_uri, _ = await upload_tgfile_to_matrix(pp_file_id, user_id) + await matrix_put('client', 'profile/{}/avatar_url'.format(user_id), user_id, {'avatar_url':pp_uri}) + else: + await matrix_put('client', 'profile/{}/avatar_url'.format(user_id), user_id, {'avatar_url':None}) db.session.add(db_user) db.session.commit()