diff --git a/ui/messages/html/parser.go b/ui/messages/html/parser.go index 7f955cd..e474030 100644 --- a/ui/messages/html/parser.go +++ b/ui/messages/html/parser.go @@ -495,13 +495,18 @@ func Parse(prefs *config.UserPreferences, room *rooms.Room, content *event.Messa parser := htmlParser{room: room, prefs: prefs, evt: evt} root := parser.Parse(htmlData) - beRoot := root.(*ContainerEntity) - beRoot.Block = false - if len(beRoot.Children) > 0 { - beChild, ok := beRoot.Children[0].(*ContainerEntity) - if ok && beChild.Tag == "p" { - // Hacky fix for m.emote - beChild.Block = false + if root == nil { + return nil + } + beRoot, ok := root.(*ContainerEntity) + if ok { + beRoot.Block = false + if len(beRoot.Children) > 0 { + beChild, ok := beRoot.Children[0].(*ContainerEntity) + if ok && beChild.Tag == "p" { + // Hacky fix for m.emote + beChild.Block = false + } } } diff --git a/ui/messages/parser.go b/ui/messages/parser.go index 79cc683..dc9733e 100644 --- a/ui/messages/parser.go +++ b/ui/messages/parser.go @@ -204,11 +204,21 @@ func ParseMessage(matrix ifc.MatrixContainer, room *rooms.Room, evt *muksevt.Eve } switch content.MsgType { case event.MsgText, event.MsgNotice, event.MsgEmote: - if content.Format == event.FormatHTML { - return NewHTMLMessage(evt, displayname, html.Parse(matrix.Preferences(), room, content, evt, displayname)) + var htmlEntity html.Entity + if content.Format == event.FormatHTML && len(content.FormattedBody) > 0 { + htmlEntity = html.Parse(matrix.Preferences(), room, content, evt, displayname) + if htmlEntity == nil { + htmlEntity = html.NewTextEntity("Malformed message") + htmlEntity.AdjustStyle(html.AdjustStyleTextColor(tcell.ColorRed), html.AdjustStyleReasonNormal) + } + } else if len(content.Body) > 0 { + content.Body = strings.Replace(content.Body, "\t", " ", -1) + htmlEntity = html.TextToEntity(content.Body, evt.ID, matrix.Preferences().EnableInlineURLs()) + } else { + htmlEntity = html.NewTextEntity("Blank message") + htmlEntity.AdjustStyle(html.AdjustStyleTextColor(tcell.ColorRed), html.AdjustStyleReasonNormal) } - content.Body = strings.Replace(content.Body, "\t", " ", -1) - return NewHTMLMessage(evt, displayname, html.TextToEntity(content.Body, evt.ID, matrix.Preferences().EnableInlineURLs())) + return NewHTMLMessage(evt, displayname, htmlEntity) case event.MsgImage, event.MsgVideo, event.MsgAudio, event.MsgFile: msg := NewFileMessage(matrix, evt, displayname) if !matrix.Preferences().DisableDownloads {