Check for existing avatar entry to properly update fixes #39

This commit is contained in:
Morgan McMillian 2019-01-16 17:29:49 -08:00
parent f21e153beb
commit 3d3f7d0681

View file

@ -194,8 +194,12 @@ def set_matrix_avatar(user):
try: try:
matrix_api.set_avatar_url(matrix_id, ul['content_uri']) matrix_api.set_avatar_url(matrix_id, ul['content_uri'])
avatar = Avatars(pnut_user=user.username, avatar=user.content.avatar_image.link) avatar = Avatars.query.filter(Avatars.pnut_user == user.username).one_or_none()
db_session.add(avatar) 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() db_session.commit()
except MatrixRequestError: except MatrixRequestError: