diff --git a/appservice.py b/appservice.py index cf967f2..d881b5f 100644 --- a/appservice.py +++ b/appservice.py @@ -56,15 +56,21 @@ def on_receive_events(transaction): text = "* " + get_displayname(event["user_id"]) + " " + event['content']['body'] elif event['content']['msgtype'] == 'm.image': 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["title"] = event['content']['body'] value["url"] = imgurl value["width"] = event['content']['info']['w'] value["height"] = event['content']['info']['h'] - value["thumbnail_width"] = event['content']['info']['thumbnail_info']['w'] - value["thumbnail_height"] = event['content']['info']['thumbnail_info']['h'] - value["thumbnail_url"] = thmburl + if 'thumbnail_info' in event['content']['info']: + thmburl = app.config['MATRIX_HOST'] + '/_matrix/media/r0/download/' + event['content']['info']['thumbnail_url'][6:] + 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} embed = [rawitem] if user: