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: