handle invite and leave notices

This commit is contained in:
Morgan McMillian 2017-05-03 23:01:51 -07:00
parent f94b5cf2fa
commit e129be8c86

View file

@ -71,12 +71,6 @@ def on_receive_events(transaction):
else:
text = None
# chan = MatrixRoom.query.filter_by(room_id=event['room_id']).first()
# if chan:
# chan_id = chan.pnut_chan
# else:
# return jsonify({})
if user == None and not chan.pnut_write:
txId += 1
url = app.config['MATRIX_HOST']
@ -112,6 +106,25 @@ def on_receive_events(transaction):
r = Pnut(token).delete_channel_post(r_event.pnut_chan, r_event.pnut_msgid)
elif event['type'] == 'm.room.member':
if event['content']['membership'] == 'invite' and event['content']['is_direct'] == True:
logging.info('>> GOT INVITE')
txId += 1
url = app.config['MATRIX_HOST']
url += '/_matrix/client/r0/join/' + event['room_id']
url += "?access_token=" + app.config['MATRIX_AS_TOKEN']
r = requests.post(url, headers={"Content-Type": "application/json"}, data=json.dumps({}))
elif event['membership'] == 'leave':
logging.info('>> GOT LEAVE')
txId += 1
url = app.config['MATRIX_HOST']
url += '/_matrix/client/r0/rooms/' + event['room_id'] + "/leave"
url += "?access_token=" + app.config['MATRIX_AS_TOKEN']
r = requests.post(url, headers={"Content-Type": "application/json"}, data=json.dumps({}))
return jsonify({})
@app.route("/rooms/<alias>")