aboutsummaryrefslogtreecommitdiff
path: root/ui/messages
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-05-22 17:36:41 +0300
committerTulir Asokan <tulir@maunium.net>2018-05-22 17:36:41 +0300
commitc87097627e89ffbe7dd92f3bc3ffe62f43ba2ca7 (patch)
tree4f9a28fb4245fdd719a1ca4fcf01894a6653f900 /ui/messages
parentff5c1292fe8f08f1334c80580d710a642e508940 (diff)
Split up getMembershipEventContent()
Diffstat (limited to 'ui/messages')
-rw-r--r--ui/messages/parser/parser.go75
1 files changed, 40 insertions, 35 deletions
diff --git a/ui/messages/parser/parser.go b/ui/messages/parser/parser.go
index 647b931..1fb64c4 100644
--- a/ui/messages/parser/parser.go
+++ b/ui/messages/parser/parser.go
@@ -78,6 +78,45 @@ func ParseMessage(matrix ifc.MatrixContainer, room *rooms.Room, evt *gomatrix.Ev
return nil
}
+func getMembershipChangeMessage(evt *gomatrix.Event, membership, prevMembership, senderDisplayname, displayname, prevDisplayname string) (sender string, text tstring.TString) {
+ switch membership {
+ case "invite":
+ sender = "---"
+ 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(*evt.StateKey))
+ case "leave":
+ sender = "<--"
+ if evt.Sender != *evt.StateKey {
+ if prevMembership == "ban" {
+ text = tstring.NewColorTString(fmt.Sprintf("%s unbanned %s", senderDisplayname, displayname), tcell.ColorGreen)
+ text.Colorize(len(senderDisplayname)+len(" unbanned "), len(displayname), widget.GetHashColor(*evt.StateKey))
+ } else {
+ reason, _ := evt.Content["reason"].(string)
+ text = tstring.NewColorTString(fmt.Sprintf("%s kicked %s: %s", senderDisplayname, displayname, reason), tcell.ColorRed)
+ text.Colorize(len(senderDisplayname)+len(" kicked "), len(displayname), widget.GetHashColor(*evt.StateKey))
+ }
+ text.Colorize(0, len(senderDisplayname), widget.GetHashColor(evt.Sender))
+ } else {
+ if displayname == *evt.StateKey {
+ displayname = prevDisplayname
+ }
+ text = tstring.NewColorTString(fmt.Sprintf("%s left the room.", displayname), tcell.ColorRed)
+ text.Colorize(0, len(displayname), widget.GetHashColor(*evt.StateKey))
+ }
+ case "ban":
+ reason, _ := evt.Content["reason"].(string)
+ text = tstring.NewColorTString(fmt.Sprintf("%s banned %s: %s", senderDisplayname, displayname, reason), tcell.ColorRed)
+ text.Colorize(len(senderDisplayname)+len(" banned "), len(displayname), widget.GetHashColor(*evt.StateKey))
+ text.Colorize(0, len(senderDisplayname), widget.GetHashColor(evt.Sender))
+ }
+ return
+}
+
func getMembershipEventContent(room *rooms.Room, evt *gomatrix.Event) (sender string, text tstring.TString) {
member := room.GetMember(evt.Sender)
senderDisplayname := evt.Sender
@@ -102,41 +141,7 @@ func getMembershipEventContent(room *rooms.Room, evt *gomatrix.Event) (sender st
}
if membership != prevMembership {
- switch membership {
- case "invite":
- sender = "---"
- 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(*evt.StateKey))
- case "leave":
- sender = "<--"
- if evt.Sender != *evt.StateKey {
- if prevMembership == "ban" {
- text = tstring.NewColorTString(fmt.Sprintf("%s unbanned %s", senderDisplayname, displayname), tcell.ColorGreen)
- text.Colorize(len(senderDisplayname)+len(" unbanned "), len(displayname), widget.GetHashColor(*evt.StateKey))
- } else {
- reason, _ := evt.Content["reason"].(string)
- text = tstring.NewColorTString(fmt.Sprintf("%s kicked %s: %s", senderDisplayname, displayname, reason), tcell.ColorRed)
- text.Colorize(len(senderDisplayname)+len(" kicked "), len(displayname), widget.GetHashColor(*evt.StateKey))
- }
- text.Colorize(0, len(senderDisplayname), widget.GetHashColor(evt.Sender))
- } else {
- if displayname == *evt.StateKey {
- displayname = prevDisplayname
- }
- text = tstring.NewColorTString(fmt.Sprintf("%s left the room.", displayname), tcell.ColorRed)
- text.Colorize(0, len(displayname), widget.GetHashColor(*evt.StateKey))
- }
- case "ban":
- reason, _ := evt.Content["reason"].(string)
- text = tstring.NewColorTString(fmt.Sprintf("%s banned %s: %s", senderDisplayname, displayname, reason), tcell.ColorRed)
- text.Colorize(len(senderDisplayname)+len(" banned "), len(displayname), widget.GetHashColor(*evt.StateKey))
- text.Colorize(0, len(senderDisplayname), widget.GetHashColor(evt.Sender))
- }
+ sender, text = getMembershipChangeMessage(evt, membership, prevMembership, senderDisplayname, displayname, prevDisplayname)
} else if displayname != prevDisplayname {
sender = "---"
text = tstring.NewColorTString(fmt.Sprintf("%s changed their display name to %s.", prevDisplayname, displayname), tcell.ColorGreen)