Fix rendering empty/malformed messages
This commit is contained in:
parent
1e6174f828
commit
030c0c6ec5
@ -495,7 +495,11 @@ 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)
|
||||
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)
|
||||
@ -504,6 +508,7 @@ func Parse(prefs *config.UserPreferences, room *rooms.Room, content *event.Messa
|
||||
beChild.Block = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if content.MsgType == event.MsgEmote {
|
||||
root = &ContainerEntity{
|
||||
|
@ -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)
|
||||
return NewHTMLMessage(evt, displayname, html.TextToEntity(content.Body, evt.ID, matrix.Preferences().EnableInlineURLs()))
|
||||
htmlEntity = html.TextToEntity(content.Body, evt.ID, matrix.Preferences().EnableInlineURLs())
|
||||
} else {
|
||||
htmlEntity = html.NewTextEntity("Blank message")
|
||||
htmlEntity.AdjustStyle(html.AdjustStyleTextColor(tcell.ColorRed), html.AdjustStyleReasonNormal)
|
||||
}
|
||||
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