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}
|
parser := htmlParser{room: room, prefs: prefs, evt: evt}
|
||||||
root := parser.Parse(htmlData)
|
root := parser.Parse(htmlData)
|
||||||
beRoot := root.(*ContainerEntity)
|
if root == nil {
|
||||||
beRoot.Block = false
|
return nil
|
||||||
if len(beRoot.Children) > 0 {
|
}
|
||||||
beChild, ok := beRoot.Children[0].(*ContainerEntity)
|
beRoot, ok := root.(*ContainerEntity)
|
||||||
if ok && beChild.Tag == "p" {
|
if ok {
|
||||||
// Hacky fix for m.emote
|
beRoot.Block = false
|
||||||
beChild.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 {
|
switch content.MsgType {
|
||||||
case event.MsgText, event.MsgNotice, event.MsgEmote:
|
case event.MsgText, event.MsgNotice, event.MsgEmote:
|
||||||
if content.Format == event.FormatHTML {
|
var htmlEntity html.Entity
|
||||||
return NewHTMLMessage(evt, displayname, html.Parse(matrix.Preferences(), room, content, evt, displayname))
|
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, htmlEntity)
|
||||||
return NewHTMLMessage(evt, displayname, html.TextToEntity(content.Body, evt.ID, matrix.Preferences().EnableInlineURLs()))
|
|
||||||
case event.MsgImage, event.MsgVideo, event.MsgAudio, event.MsgFile:
|
case event.MsgImage, event.MsgVideo, event.MsgAudio, event.MsgFile:
|
||||||
msg := NewFileMessage(matrix, evt, displayname)
|
msg := NewFileMessage(matrix, evt, displayname)
|
||||||
if !matrix.Preferences().DisableDownloads {
|
if !matrix.Preferences().DisableDownloads {
|
||||||
|
Loading…
Reference in New Issue
Block a user