fix keyerror when thumbnail isn't available

This commit is contained in:
Morgan McMillian 2017-06-02 06:55:14 -07:00
parent 9e8a6bd123
commit 76e1c15b69

View file

@ -56,15 +56,21 @@ def on_receive_events(transaction):
text = "* " + get_displayname(event["user_id"]) + " " + event['content']['body'] text = "* " + get_displayname(event["user_id"]) + " " + event['content']['body']
elif event['content']['msgtype'] == 'm.image': elif event['content']['msgtype'] == 'm.image':
imgurl = app.config['MATRIX_HOST'] + '/_matrix/media/r0/download/' + event['content']['url'][6:] imgurl = app.config['MATRIX_HOST'] + '/_matrix/media/r0/download/' + event['content']['url'][6:]
thmburl = app.config['MATRIX_HOST'] + '/_matrix/media/r0/download/' + event['content']['info']['thumbnail_url'][6:]
value = {"type": "photo", "version": "1.0"} value = {"type": "photo", "version": "1.0"}
value["title"] = event['content']['body'] value["title"] = event['content']['body']
value["url"] = imgurl value["url"] = imgurl
value["width"] = event['content']['info']['w'] value["width"] = event['content']['info']['w']
value["height"] = event['content']['info']['h'] value["height"] = event['content']['info']['h']
value["thumbnail_width"] = event['content']['info']['thumbnail_info']['w'] if 'thumbnail_info' in event['content']['info']:
value["thumbnail_height"] = event['content']['info']['thumbnail_info']['h'] thmburl = app.config['MATRIX_HOST'] + '/_matrix/media/r0/download/' + event['content']['info']['thumbnail_url'][6:]
value["thumbnail_url"] = thmburl value["thumbnail_width"] = event['content']['info']['thumbnail_info']['w']
value["thumbnail_height"] = event['content']['info']['thumbnail_info']['h']
value["thumbnail_url"] = thmburl
else:
value["thumbnail_width"] = event['content']['info']['w']
value["thumbnail_height"] = event['content']['info']['h']
value["thumbnail_url"] = imgurl
rawitem = {"type": "io.pnut.core.oembed", "value": value} rawitem = {"type": "io.pnut.core.oembed", "value": value}
embed = [rawitem] embed = [rawitem]
if user: if user: