mirror of
https://codeberg.org/june64/mrvc.git
synced 2026-01-10 16:06:33 +01:00
move room ID resolution and given alias information to roomInfoTree
Move room ID resolution into roomInfoTree and therefore store given alias information in RoomInfoTree as well.
This commit is contained in:
parent
7a444ccc7a
commit
f805786ae0
2 changed files with 55 additions and 34 deletions
36
main.go
36
main.go
|
|
@ -73,43 +73,15 @@ func main() {
|
|||
fclient.WithTimeout(config.HomeserverVersionInfoTimeout),
|
||||
)
|
||||
|
||||
roomIDSet := make(map[id.RoomID]bool)
|
||||
aliasSetByRoomID := make(map[id.RoomID](map[string]bool))
|
||||
for _, room := range config.Rooms {
|
||||
// Check, if given room is an alias and try to resolve it into a room id.
|
||||
if strings.HasPrefix(room, "#") {
|
||||
resolvedAlias, err := client.ResolveAlias(context.Background(), id.RoomAlias(room))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
roomIDSet[resolvedAlias.RoomID] = true
|
||||
|
||||
aliasSet, ok := aliasSetByRoomID[resolvedAlias.RoomID]
|
||||
if !ok {
|
||||
aliasSet = make(map[string]bool)
|
||||
aliasSetByRoomID[resolvedAlias.RoomID] = aliasSet
|
||||
}
|
||||
aliasSet[room] = true
|
||||
} else {
|
||||
roomIDSet[id.RoomID(room)] = true
|
||||
}
|
||||
}
|
||||
|
||||
roomIDs := make([]id.RoomID, 0, len(roomIDSet))
|
||||
for roomID := range roomIDSet {
|
||||
roomIDs = append(roomIDs, roomID)
|
||||
}
|
||||
|
||||
roomInfoTree := roominfotree.Get(roomIDs, client, federationClient)
|
||||
roomInfoTree := roominfotree.Get(config.Rooms, client, federationClient)
|
||||
|
||||
for roomID, roomInfo := range roomInfoTree {
|
||||
fmt.Println("Room:")
|
||||
fmt.Printf(" %s -> %d\n", roomID, roomInfo.MemberCount)
|
||||
aliasSet, ok := aliasSetByRoomID[roomID]
|
||||
if ok {
|
||||
aliases := roomInfo.GivenAliases
|
||||
if len(aliases) > 0 {
|
||||
fmt.Println("Given Aliases:")
|
||||
for alias := range aliasSet {
|
||||
for _, alias := range aliases {
|
||||
fmt.Printf(" %s\n", alias)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue