only pay attention to memeber events if they involve the AS user id.
Should resolve issue #8
This commit is contained in:
parent
ea684e1462
commit
dfccd44b1d
1 changed files with 29 additions and 14 deletions
|
@ -108,13 +108,23 @@ def on_receive_events(transaction):
|
||||||
|
|
||||||
elif event['type'] == 'm.room.member':
|
elif event['type'] == 'm.room.member':
|
||||||
|
|
||||||
if event['content']['membership'] == 'invite' and event['content']['is_direct'] == True:
|
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:
|
||||||
|
|
||||||
logging.info('>> GOT INVITE')
|
logging.info('>> GOT INVITE')
|
||||||
txId += 1
|
txId += 1
|
||||||
url = app.config['MATRIX_HOST']
|
url = app.config['MATRIX_HOST']
|
||||||
url += '/_matrix/client/r0/join/' + event['room_id']
|
url += '/_matrix/client/r0/join/' + event['room_id']
|
||||||
url += "?access_token=" + app.config['MATRIX_AS_TOKEN']
|
url += "?access_token=" + app.config['MATRIX_AS_TOKEN']
|
||||||
r = requests.post(url, headers={"Content-Type": "application/json"}, data=json.dumps({}))
|
r = requests.post(url, headers={"Content-Type": "application/json"},
|
||||||
|
data=json.dumps({}))
|
||||||
|
if r.status_code == 200:
|
||||||
|
addadminrm = MatrixAdminRooms(matrix_id=event['sender'], room_id=event['room_id'])
|
||||||
|
db.session.add(addadminrm)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
elif event['membership'] == 'leave':
|
elif event['membership'] == 'leave':
|
||||||
logging.info('>> GOT LEAVE')
|
logging.info('>> GOT LEAVE')
|
||||||
|
@ -122,7 +132,12 @@ def on_receive_events(transaction):
|
||||||
url = app.config['MATRIX_HOST']
|
url = app.config['MATRIX_HOST']
|
||||||
url += '/_matrix/client/r0/rooms/' + event['room_id'] + "/leave"
|
url += '/_matrix/client/r0/rooms/' + event['room_id'] + "/leave"
|
||||||
url += "?access_token=" + app.config['MATRIX_AS_TOKEN']
|
url += "?access_token=" + app.config['MATRIX_AS_TOKEN']
|
||||||
r = requests.post(url, headers={"Content-Type": "application/json"}, data=json.dumps({}))
|
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()
|
||||||
|
|
||||||
|
|
||||||
return jsonify({})
|
return jsonify({})
|
||||||
|
|
Loading…
Reference in a new issue