aboutsummaryrefslogtreecommitdiff
path: root/ui/messages
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2019-04-10 17:08:39 +0300
committerTulir Asokan <tulir@maunium.net>2019-04-10 17:08:39 +0300
commit7e0278c571954564efca64a6ea114c0e80f11532 (patch)
tree7441b02cb074ba6d4e421fa0b36112905e48ebaa /ui/messages
parent45a68c7fb5d811036075c550fb6fa40069486bf1 (diff)
Fix m.emote rendering
Diffstat (limited to 'ui/messages')
-rw-r--r--ui/messages/base.go3
-rw-r--r--ui/messages/html/parser.go20
2 files changed, 22 insertions, 1 deletions
diff --git a/ui/messages/base.go b/ui/messages/base.go
index 32e1865..c377ccb 100644
--- a/ui/messages/base.go
+++ b/ui/messages/base.go
@@ -170,6 +170,9 @@ func (msg *BaseMessage) TextColor() tcell.Color {
//
// However, other messages are the default color instead of a color stored in the struct.
func (msg *BaseMessage) TimestampColor() tcell.Color {
+ if msg.MsgIsService {
+ return tcell.ColorGray
+ }
return msg.getStateSpecificColor()
}
diff --git a/ui/messages/html/parser.go b/ui/messages/html/parser.go
index dbd487e..0bdf483 100644
--- a/ui/messages/html/parser.go
+++ b/ui/messages/html/parser.go
@@ -305,6 +305,9 @@ func (parser *htmlParser) singleNodeToEntity(node *html.Node) Entity {
if !parser.keepLinebreak {
node.Data = strings.ReplaceAll(node.Data, "\n", "")
}
+ if len(node.Data) == 0 {
+ return nil
+ }
return &BaseEntity{
Tag: "text",
Text: node.Data,
@@ -347,6 +350,13 @@ func (parser *htmlParser) isBlockTag(tag string) bool {
func (parser *htmlParser) Parse(htmlData string) Entity {
node, _ := html.Parse(strings.NewReader(htmlData))
+ bodyNode := node.FirstChild.FirstChild
+ for bodyNode != nil && (bodyNode.Type != html.ElementNode || bodyNode.Data != "body") {
+ bodyNode = bodyNode.NextSibling
+ }
+ if bodyNode != nil {
+ return parser.singleNodeToEntity(bodyNode)
+ }
return parser.singleNodeToEntity(node)
}
@@ -362,7 +372,15 @@ func Parse(room *rooms.Room, evt *mautrix.Event, senderDisplayname string) Entit
parser := htmlParser{room: room}
root := parser.Parse(htmlData)
- root.(*BaseEntity).Block = false
+ beRoot := root.(*BaseEntity)
+ beRoot.Block = false
+ if len(beRoot.Children) > 0 {
+ beChild, ok := beRoot.Children[0].(*BaseEntity)
+ if ok && beChild.Tag == "p" {
+ // Hacky fix for m.emote
+ beChild.Block = false
+ }
+ }
if evt.Content.MsgType == mautrix.MsgEmote {
root = &BaseEntity{