From 43922cf09ecac38e2ac65039988d9d68672be6cd Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 27 Oct 2021 18:44:17 +0300 Subject: [PATCH] Pre-render markdown for undecryptable message notice --- portal.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/portal.go b/portal.go index 8d2ea1f..577ce41 100644 --- a/portal.go +++ b/portal.go @@ -308,8 +308,14 @@ func (portal *Portal) convertMessage(intent *appservice.IntentAPI, source *User, } } -const UndecryptableMessage = "Decrypting message from WhatsApp failed, waiting for sender to re-send... " + +const UndecryptableMessageNotice = "Decrypting message from WhatsApp failed, waiting for sender to re-send... " + "([learn more](https://faq.whatsapp.com/general/security-and-privacy/seeing-waiting-for-this-message-this-may-take-a-while))" +var undecryptableMessageContent event.MessageEventContent + +func init() { + undecryptableMessageContent = format.RenderMarkdown(UndecryptableMessageNotice, true, false) + undecryptableMessageContent.MsgType = event.MsgNotice +} func (portal *Portal) handleUndecryptableMessage(source *User, evt *events.UndecryptableMessage) { if len(portal.MXID) == 0 { @@ -323,8 +329,7 @@ func (portal *Portal) handleUndecryptableMessage(source *User, evt *events.Undec return } intent := portal.getMessageIntent(source, &evt.Info) - content := format.RenderMarkdown(UndecryptableMessage, true, false) - content.MsgType = event.MsgNotice + content := undecryptableMessageContent resp, err := portal.sendMessage(intent, event.EventMessage, &content, evt.Info.Timestamp.UnixMilli()) if err != nil { portal.log.Errorln("Failed to send decryption error of %s to Matrix: %v", evt.Info.ID, err)