Skip to content
This repository has been archived by the owner on Oct 24, 2018. It is now read-only.

Fix the wrong displayname/avatar change messages (maybe) #45

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions telematrix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,14 @@ async def matrix_transaction(request):
db.session.add(sender)

msg = None
if 'unsigned' in event and 'prev_content' in event['unsigned']:
prev = event['unsigned']['prev_content']
if prev['membership'] == 'join':
if 'displayname' in prev and prev['displayname']:
oldname = prev['displayname']

msg = '> {} changed their display name to {}'\
.format(oldname, displayname)
print("DEBUG: {}".format(event))
if ('unsigned' in event and 'prev_content' in event['unsigned']) or 'prev_content' in event:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You seem to be checking for the same thing multiple times, mind rewriting this if statement to be a bit more efficient?

if 'unsigned' in event and 'prev_content' in event['unsigned']:
prev = event['unsigned']['prev_content']
elif 'prev_content' in event:
prev = event['prev_content']
if event['content']['displayname'] != prev['displayname']:
msg = '> {} changed their display name to {}'.format(prev['displayname'], event['content']['displayname'])
else:
msg = '> {} has joined the room'.format(displayname)

Expand Down