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,14 +404,22 @@ 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 {
switch membership {
case "invite":
sender = "---" sender = "---"
text = fmt.Sprintf("%s invited %s.", evt.Sender, displayname) text = fmt.Sprintf("%s invited %s.", evt.Sender, displayname)
} else if membership == "join" { case "join":
sender = "-->" sender = "-->"
text = fmt.Sprintf("%s joined the room.", displayname) text = fmt.Sprintf("%s joined the room.", displayname)
} else if membership == "leave" { case "leave":
sender = "<--" sender = "<--"
if evt.Sender != *evt.StateKey { if evt.Sender != *evt.StateKey {
reason, _ := evt.Content["reason"].(string) reason, _ := evt.Content["reason"].(string)
@ -420,6 +428,10 @@ func (view *MainView) getMembershipEventContent(evt *gomatrix.Event) (sender, te
text = fmt.Sprintf("%s left the room.", displayname) 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
} }