Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Ensure that a URL exists in the content during push. (#8965)
Browse files Browse the repository at this point in the history
This fixes an KeyError exception, after this PR the content
is just considered unknown.
  • Loading branch information
clokep authored Dec 18, 2020
1 parent a7a9139 commit 4136255
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/8965.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a longstanding bug where a `m.image` event without a `url` would cause errors on push.
6 changes: 5 additions & 1 deletion synapse/push/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,11 @@ def add_text_message_vars(
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,
Expand Down
2 changes: 1 addition & 1 deletion synapse/res/templates/notif.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
<img src="{{ message.image_url|mxc_to_http(640, 480, scale) }}" />
{%- elif message.msgtype == "m.file" %}
<span class="filename">{{ message.body_text_plain }}</span>
Expand Down

0 comments on commit 4136255

Please sign in to comment.