Make room name from aliases calculation consistent
This commit is contained in:
parent
64fa922ec0
commit
1085ddc390
@ -18,6 +18,7 @@ package rooms
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"maunium.net/go/gomatrix"
|
"maunium.net/go/gomatrix"
|
||||||
@ -126,7 +127,11 @@ func (room *Room) UpdateState(event *gomatrix.Event) {
|
|||||||
case "m.room.topic":
|
case "m.room.topic":
|
||||||
room.topicCache = ""
|
room.topicCache = ""
|
||||||
}
|
}
|
||||||
|
if event.StateKey == nil {
|
||||||
|
room.State[event.Type][""] = event
|
||||||
|
} else {
|
||||||
room.State[event.Type][*event.StateKey] = event
|
room.State[event.Type][*event.StateKey] = event
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStateEvent returns the state event for the given type/state_key combo, or nil.
|
// GetStateEvent returns the state event for the given type/state_key combo, or nil.
|
||||||
@ -179,7 +184,7 @@ func (room *Room) GetAliases() []string {
|
|||||||
newAliases := make([]string, len(room.aliasesCache)+len(aliases))
|
newAliases := make([]string, len(room.aliasesCache)+len(aliases))
|
||||||
copy(newAliases, room.aliasesCache)
|
copy(newAliases, room.aliasesCache)
|
||||||
for index, alias := range aliases {
|
for index, alias := range aliases {
|
||||||
newAliases[len(room.aliasesCache) + index], _ = alias.(string)
|
newAliases[len(room.aliasesCache)+index], _ = alias.(string)
|
||||||
}
|
}
|
||||||
room.aliasesCache = newAliases
|
room.aliasesCache = newAliases
|
||||||
}
|
}
|
||||||
@ -201,13 +206,10 @@ func (room *Room) updateNameFromNameEvent() {
|
|||||||
func (room *Room) updateNameFromAliases() {
|
func (room *Room) updateNameFromAliases() {
|
||||||
// TODO the spec says clients should not use m.room.aliases for room names.
|
// 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.
|
// However, Riot also uses m.room.aliases, so this is here now.
|
||||||
aliasEvents := room.GetStateEvents("m.room.aliases")
|
aliases := room.GetAliases()
|
||||||
for _, event := range aliasEvents {
|
|
||||||
aliases, _ := event.Content["aliases"].([]interface{})
|
|
||||||
if len(aliases) > 0 {
|
if len(aliases) > 0 {
|
||||||
room.nameCache, _ = aliases[0].(string)
|
sort.Sort(sort.StringSlice(aliases))
|
||||||
break
|
room.nameCache = aliases[0]
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user