Display ban/unban events

This commit is contained in:
Tulir Asokan 2018-05-15 18:02:36 +03:00
parent 709a57d029
commit fdbb168e2b
2 changed files with 14 additions and 3 deletions

View File

@ -28,6 +28,7 @@ const (
MembershipJoin Membership = "join"
MembershipLeave Membership = "leave"
MembershipInvite Membership = "invite"
MembershipBan Membership = "ban"
MembershipKnock Membership = "knock"
)

View File

@ -115,10 +115,15 @@ func getMembershipEventContent(room *rooms.Room, evt *gomatrix.Event) (sender st
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(0, len(senderDisplayname), widget.GetHashColor(evt.Sender))
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
@ -126,6 +131,11 @@ func getMembershipEventContent(room *rooms.Room, evt *gomatrix.Event) (sender st
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))
}
} else if displayname != prevDisplayname {
sender = "---"