From 3d3f7d068161a3dc549eb88c0967f0916860580f Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Wed, 16 Jan 2019 17:29:49 -0800 Subject: [PATCH] Check for existing avatar entry to properly update fixes #39 --- pnut-matrix.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pnut-matrix.py b/pnut-matrix.py index 5ff4464..8a1aee0 100644 --- a/pnut-matrix.py +++ b/pnut-matrix.py @@ -194,8 +194,12 @@ def set_matrix_avatar(user): try: matrix_api.set_avatar_url(matrix_id, ul['content_uri']) - avatar = Avatars(pnut_user=user.username, avatar=user.content.avatar_image.link) - db_session.add(avatar) + avatar = Avatars.query.filter(Avatars.pnut_user == user.username).one_or_none() + if avatar is None: + avatar = Avatars(pnut_user=user.username, avatar=user.content.avatar_image.link) + db_session.add(avatar) + else: + avatar.avatar = user.content.avatar_image.link db_session.commit() except MatrixRequestError: