Make room name from aliases calculation consistent

This commit is contained in:
Tulir Asokan 2018-04-22 23:23:30 +03:00
parent 64fa922ec0
commit 1085ddc390

View File

@ -18,6 +18,7 @@ package rooms
import (
"fmt"
"sort"
"sync"
"maunium.net/go/gomatrix"
@ -126,8 +127,12 @@ func (room *Room) UpdateState(event *gomatrix.Event) {
case "m.room.topic":
room.topicCache = ""
}
if event.StateKey == nil {
room.State[event.Type][""] = event
} else {
room.State[event.Type][*event.StateKey] = event
}
}
// GetStateEvent returns the state event for the given type/state_key combo, or nil.
func (room *Room) GetStateEvent(eventType string, stateKey string) *gomatrix.Event {
@ -201,13 +206,10 @@ func (room *Room) updateNameFromNameEvent() {
func (room *Room) updateNameFromAliases() {
// TODO the spec says clients should not use m.room.aliases for room names.
// However, Riot also uses m.room.aliases, so this is here now.
aliasEvents := room.GetStateEvents("m.room.aliases")
for _, event := range aliasEvents {
aliases, _ := event.Content["aliases"].([]interface{})
aliases := room.GetAliases()
if len(aliases) > 0 {
room.nameCache, _ = aliases[0].(string)
break
}
sort.Sort(sort.StringSlice(aliases))
room.nameCache = aliases[0]
}
}