Fix membership event processing

This commit is contained in:
Tulir Asokan 2018-03-23 14:20:46 +02:00
parent a5e7ca227c
commit 7cc55ade30

View File

@ -404,21 +404,33 @@ func (view *MainView) getMembershipEventContent(evt *gomatrix.Event) (sender, te
if len(displayname) == 0 { if len(displayname) == 0 {
displayname = *evt.StateKey displayname = *evt.StateKey
} }
prevMembership := "leave"
prevDisplayname := ""
if evt.Unsigned.PrevContent != nil {
prevMembership, _ = evt.Unsigned.PrevContent["membership"].(string)
prevDisplayname, _ = evt.Unsigned.PrevContent["displayname"].(string)
}
if membership == "invite" { if membership != prevMembership {
sender = "---" switch membership {
text = fmt.Sprintf("%s invited %s.", evt.Sender, displayname) case "invite":
} else if membership == "join" { sender = "---"
sender = "-->" text = fmt.Sprintf("%s invited %s.", evt.Sender, displayname)
text = fmt.Sprintf("%s joined the room.", displayname) case "join":
} else if membership == "leave" { sender = "-->"
sender = "<--" text = fmt.Sprintf("%s joined the room.", displayname)
if evt.Sender != *evt.StateKey { case "leave":
reason, _ := evt.Content["reason"].(string) sender = "<--"
text = fmt.Sprintf("%s kicked %s: %s", evt.Sender, displayname, reason) if evt.Sender != *evt.StateKey {
} else { reason, _ := evt.Content["reason"].(string)
text = fmt.Sprintf("%s left the room.", displayname) text = fmt.Sprintf("%s kicked %s: %s", evt.Sender, displayname, reason)
} else {
text = fmt.Sprintf("%s left the room.", displayname)
}
} }
} else if displayname != prevDisplayname {
sender = "---"
text = fmt.Sprintf("%s changed their display name to %s.", prevDisplayname, displayname)
} }
return return
} }