Fix rendering empty/malformed messages
This commit is contained in:
parent
1e6174f828
commit
030c0c6ec5
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user