From 4136255d3cd733d3b9997f3f23a837d76cec7aaf Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Fri, 18 Dec 2020 07:26:15 -0500 Subject: [PATCH] Ensure that a URL exists in the content during push. (#8965) This fixes an KeyError exception, after this PR the content is just considered unknown. --- changelog.d/8965.bugfix | 1 + synapse/push/mailer.py | 6 +++++- synapse/res/templates/notif.html | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelog.d/8965.bugfix diff --git a/changelog.d/8965.bugfix b/changelog.d/8965.bugfix new file mode 100644 index 0000000000..cbccebddb5 --- /dev/null +++ b/changelog.d/8965.bugfix @@ -0,0 +1 @@ +Fix a longstanding bug where a `m.image` event without a `url` would cause errors on push. diff --git a/synapse/push/mailer.py b/synapse/push/mailer.py index 9ff092e8bb..4d875dcb91 100644 --- a/synapse/push/mailer.py +++ b/synapse/push/mailer.py @@ -486,7 +486,11 @@ class Mailer: def add_image_message_vars( self, messagevars: Dict[str, Any], event: EventBase ) -> None: - messagevars["image_url"] = event.content["url"] + """ + Potentially add an image URL to the message variables. + """ + if "url" in event.content: + messagevars["image_url"] = event.content["url"] async def make_summary_text( self, diff --git a/synapse/res/templates/notif.html b/synapse/res/templates/notif.html index 6d76064d13..0aaef97df8 100644 --- a/synapse/res/templates/notif.html +++ b/synapse/res/templates/notif.html @@ -29,7 +29,7 @@ {{ message.body_text_html }} {%- elif message.msgtype == "m.notice" %} {{ message.body_text_html }} - {%- elif message.msgtype == "m.image" %} + {%- elif message.msgtype == "m.image" and message.image_url %} {%- elif message.msgtype == "m.file" %} {{ message.body_text_plain }}