1
0
Fork 0
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:
June 2025-08-18 23:16:54 +02:00
commit f805786ae0
Signed by: june
SSH key fingerprint: SHA256:o9EAq4Y9N9K0pBQeBTqhSDrND5E7oB+60ZNx0U1yPe0
2 changed files with 55 additions and 34 deletions

36
main.go
View file

@ -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)
}
}