Title now correctly applied to Matrix messages (#545)

This commit is contained in:
Chris Caron 2022-03-26 19:49:07 -04:00 committed by GitHub
parent 259462efcc
commit 4cc5be0d6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,7 +42,6 @@ from ..common import NotifyImageSize
from ..common import NotifyFormat from ..common import NotifyFormat
from ..utils import parse_bool from ..utils import parse_bool
from ..utils import parse_list from ..utils import parse_list
from ..utils import apply_template
from ..utils import is_hostname from ..utils import is_hostname
from ..utils import validate_regex from ..utils import validate_regex
from ..AppriseLocale import gettext_lazy as _ from ..AppriseLocale import gettext_lazy as _
@ -470,21 +469,16 @@ class NotifyMatrix(NotifyBase):
} }
if self.notify_format == NotifyFormat.HTML: if self.notify_format == NotifyFormat.HTML:
# Add additional information to our content; use {{app_title}} payload['text'] = '{title}{body}'.format(
# to apply the title to the html body title='' if not title else '<h1>{}</h1>'.format(
tokens = { NotifyMatrix.escape_html(title)),
'app_title': NotifyMatrix.escape_html( body=body)
title, whitespace=False),
}
payload['text'] = apply_template(body, **tokens)
elif self.notify_format == NotifyFormat.MARKDOWN: elif self.notify_format == NotifyFormat.MARKDOWN:
# Add additional information to our content; use {{app_title}} payload['text'] = '{title}{body}'.format(
# to apply the title to the html body title='' if not title else '<h1>{}</h1>'.format(
tokens = { NotifyMatrix.escape_html(title)),
'app_title': title, body=markdown(body))
}
payload['text'] = markdown(apply_template(body, **tokens))
else: # NotifyFormat.TEXT else: # NotifyFormat.TEXT
payload['text'] = \ payload['text'] = \
@ -583,32 +577,29 @@ class NotifyMatrix(NotifyBase):
payload = { payload = {
'msgtype': 'm.{}'.format(self.msgtype), 'msgtype': 'm.{}'.format(self.msgtype),
'body': '{title}{body}'.format( 'body': '{title}{body}'.format(
title='' if not title else '{}\r\n'.format(title), title='' if not title else '# {}\r\n'.format(title),
body=body), body=body),
} }
# Update our payload advance formatting for the services that # Update our payload advance formatting for the services that
# support them. # support them.
if self.notify_format == NotifyFormat.HTML: if self.notify_format == NotifyFormat.HTML:
# Add additional information to our content; use {{app_title}}
# to apply the title to the html body
tokens = {
'app_title': NotifyMatrix.escape_html(
title, whitespace=False),
}
payload.update({ payload.update({
'format': 'org.matrix.custom.html', 'format': 'org.matrix.custom.html',
'formatted_body': apply_template(body, **tokens), 'formatted_body': '{title}{body}'.format(
title='' if not title else '<h1>{}</h1>'.format(title),
body=body,
)
}) })
elif self.notify_format == NotifyFormat.MARKDOWN: elif self.notify_format == NotifyFormat.MARKDOWN:
tokens = {
'app_title': title,
}
payload.update({ payload.update({
'format': 'org.matrix.custom.html', 'format': 'org.matrix.custom.html',
'formatted_body': markdown(apply_template(body, **tokens)) 'formatted_body': '{title}{body}'.format(
title='' if not title else '<h1>{}</h1>'.format(
NotifyMatrix.escape_html(title, whitespace=False)),
body=markdown(body),
)
}) })
# Build our path # Build our path