aboutsummaryrefslogtreecommitdiff
path: root/ui/messages/parser
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-04-18 17:33:59 +0300
committerTulir Asokan <tulir@maunium.net>2018-04-18 17:33:59 +0300
commit3b2d5fa0349bf01217f6954813c669680cdd16d4 (patch)
tree11e9c8a6e22bd37f5203a7f9debf8d609bbc1e7a /ui/messages/parser
parent670d369c92bc3c450071c1a10ec5d034a53258ea (diff)
Fix nick coloring
Diffstat (limited to 'ui/messages/parser')
-rw-r--r--ui/messages/parser/htmlparser.go10
-rw-r--r--ui/messages/parser/parser.go33
2 files changed, 26 insertions, 17 deletions
diff --git a/ui/messages/parser/htmlparser.go b/ui/messages/parser/htmlparser.go
index 5e3b289..8577ee7 100644
--- a/ui/messages/parser/htmlparser.go
+++ b/ui/messages/parser/htmlparser.go
@@ -37,8 +37,9 @@ var matrixToURL = regexp.MustCompile("^(?:https?://)?(?:www\\.)?matrix\\.to/#/([
type MatrixHTMLProcessor struct {
text tstring.TString
- sender string
- msgtype string
+ senderID string
+ sender string
+ msgtype string
indent string
listType string
@@ -57,7 +58,7 @@ func (parser *MatrixHTMLProcessor) newline() {
func (parser *MatrixHTMLProcessor) Preprocess() {
if parser.msgtype == "m.emote" {
- parser.text = tstring.NewColorTString(fmt.Sprintf("* %s ", parser.sender), widget.GetHashColor(parser.sender))
+ parser.text = tstring.NewColorTString(fmt.Sprintf("* %s ", parser.sender), widget.GetHashColor(parser.senderID))
}
}
@@ -147,7 +148,7 @@ func (parser *MatrixHTMLProcessor) HandleEndTag(tagName string) {
pillTarget := match[1]
if pillTarget[0] == '@' {
if member := parser.room.GetMember(pillTarget); member != nil {
- parser.text = parser.text.AppendColor(member.DisplayName, widget.GetHashColor(member.DisplayName))
+ parser.text = parser.text.AppendColor(member.DisplayName, widget.GetHashColor(member.UserID))
} else {
parser.text = parser.text.Append(pillTarget)
}
@@ -185,6 +186,7 @@ func ParseHTMLMessage(room *rooms.Room, evt *gomatrix.Event, senderDisplayname s
room: room,
text: tstring.NewBlankTString(),
msgtype: msgtype,
+ senderID: evt.Sender,
sender: senderDisplayname,
indent: "",
listType: "",
diff --git a/ui/messages/parser/parser.go b/ui/messages/parser/parser.go
index d12383a..fbb2bf5 100644
--- a/ui/messages/parser/parser.go
+++ b/ui/messages/parser/parser.go
@@ -79,16 +79,19 @@ func ParseMessage(gmx ifc.Gomuks, room *rooms.Room, evt *gomatrix.Event) message
func getMembershipEventContent(room *rooms.Room, evt *gomatrix.Event) (sender string, text tstring.TString) {
member := room.GetMember(evt.Sender)
+ senderDisplayname := evt.Sender
if member != nil {
- evt.Sender = member.DisplayName
+ senderDisplayname = member.DisplayName
}
+
membership, _ := evt.Content["membership"].(string)
displayname, _ := evt.Content["displayname"].(string)
if len(displayname) == 0 {
displayname = *evt.StateKey
}
+
prevMembership := "leave"
- prevDisplayname := ""
+ prevDisplayname := *evt.StateKey
if evt.Unsigned.PrevContent != nil {
prevMembership, _ = evt.Unsigned.PrevContent["membership"].(string)
prevDisplayname, _ = evt.Unsigned.PrevContent["displayname"].(string)
@@ -98,36 +101,40 @@ func getMembershipEventContent(room *rooms.Room, evt *gomatrix.Event) (sender st
switch membership {
case "invite":
sender = "---"
- text = tstring.NewColorTString(fmt.Sprintf("%s invited %s.", evt.Sender, displayname), tcell.ColorGreen)
- text.Colorize(0, len(evt.Sender), widget.GetHashColor(evt.Sender))
- text.Colorize(len(evt.Sender)+len(" invited "), len(displayname), widget.GetHashColor(displayname))
+ text = tstring.NewColorTString(fmt.Sprintf("%s invited %s.", senderDisplayname, displayname), tcell.ColorGreen)
+ text.Colorize(0, len(senderDisplayname), widget.GetHashColor(evt.Sender))
+ text.Colorize(len(senderDisplayname)+len(" invited "), len(displayname), widget.GetHashColor(*evt.StateKey))
case "join":
sender = "-->"
text = tstring.NewColorTString(fmt.Sprintf("%s joined the room.", displayname), tcell.ColorGreen)
- text.Colorize(0, len(displayname), widget.GetHashColor(displayname))
+ text.Colorize(0, len(displayname), widget.GetHashColor(*evt.StateKey))
case "leave":
sender = "<--"
if evt.Sender != *evt.StateKey {
reason, _ := evt.Content["reason"].(string)
- text = tstring.NewColorTString(fmt.Sprintf("%s kicked %s: %s", evt.Sender, displayname, reason), tcell.ColorRed)
- text.Colorize(0, len(evt.Sender), widget.GetHashColor(evt.Sender))
- text.Colorize(len(evt.Sender)+len(" kicked "), len(displayname), widget.GetHashColor(displayname))
+ text = tstring.NewColorTString(fmt.Sprintf("%s kicked %s: %s", senderDisplayname, displayname, reason), tcell.ColorRed)
+ text.Colorize(0, len(senderDisplayname), widget.GetHashColor(evt.Sender))
+ text.Colorize(len(senderDisplayname)+len(" kicked "), len(displayname), widget.GetHashColor(*evt.StateKey))
} else {
text = tstring.NewColorTString(fmt.Sprintf("%s left the room.", displayname), tcell.ColorRed)
- text.Colorize(0, len(displayname), widget.GetHashColor(displayname))
+ text.Colorize(0, len(displayname), widget.GetHashColor(*evt.StateKey))
}
}
} else if displayname != prevDisplayname {
sender = "---"
- text = tstring.NewColorTString(fmt.Sprintf("%s changed their display name to %s.", prevDisplayname, displayname), tcell.ColorYellow)
- text.Colorize(0, len(prevDisplayname), widget.GetHashColor(prevDisplayname))
- text.Colorize(len(prevDisplayname)+len(" changed their display name to "), len(displayname), widget.GetHashColor(displayname))
+ text = tstring.NewColorTString(fmt.Sprintf("%s changed their display name to %s.", prevDisplayname, displayname), tcell.ColorGreen)
+ text.Colorize(0, len(prevDisplayname), widget.GetHashColor(*evt.StateKey))
+ text.Colorize(len(prevDisplayname)+len(" changed their display name to "), len(displayname), widget.GetHashColor(*evt.StateKey))
}
return
}
func ParseMembershipEvent(room *rooms.Room, evt *gomatrix.Event) messages.UIMessage {
displayname, text := getMembershipEventContent(room, evt)
+ if len(text) == 0 {
+ return nil
+ }
+
ts := unixToTime(evt.Timestamp)
return messages.NewExpandedTextMessage(evt.ID, evt.Sender, displayname, "m.room.membership", text, ts)
}