From 804af961941fca941e3a4310d9f1b908210078b1 Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Thu, 4 May 2017 17:17:45 -0700 Subject: [PATCH] adjust leave action to match up with admin room rather than state_key --- appservice.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/appservice.py b/appservice.py index b442ba9..c944a9f 100644 --- a/appservice.py +++ b/appservice.py @@ -110,9 +110,7 @@ def on_receive_events(transaction): if event['state_key'] == app.config['MATRIX_AS_ID']: - if event['content']['membership'] == 'invite' - and 'is_direct' in event['content'] - and event['content']['is_direct'] == True: + if event['content']['membership'] == 'invite' and 'is_direct' in event['content'] and event['content']['is_direct'] == True: logging.info('>> GOT INVITE') txId += 1 @@ -126,7 +124,9 @@ def on_receive_events(transaction): db.session.add(addadminrm) db.session.commit() - elif event['membership'] == 'leave': + elif event['membership'] == 'leave': + adminrm = MatrixAdminRooms.query.filter_by(room_id=event['room_id']).first() + if adminrm: logging.info('>> GOT LEAVE') txId += 1 url = app.config['MATRIX_HOST'] @@ -135,7 +135,6 @@ def on_receive_events(transaction): r = requests.post(url, headers={"Content-Type": "application/json"}, data=json.dumps({})) if r.status_code == 200: - adminrm = MatrixAdminRooms.query.filter_by(room_id=event['room_id']).first() db.session.delete(adminrm) db.session.commit()