mirror of
https://codeberg.org/june64/mrvc.git
synced 2026-01-10 16:06:33 +01:00
introduce configuration options for recursively getting rooms
Introduce option for configuring maximum depth and option for only including suggested rooms.
This commit is contained in:
parent
919127e255
commit
6309b94498
3 changed files with 38 additions and 12 deletions
|
|
@ -97,16 +97,12 @@ func resolveRooms(rooms []string, client *mautrix.Client) ([]id.RoomID, map[id.R
|
|||
return roomIDs, aliasesByRoomID
|
||||
}
|
||||
|
||||
func getChildRoomChunks(roomID id.RoomID, client *mautrix.Client) []*mautrix.ChildRoomsChunk {
|
||||
var maxDepth *int
|
||||
maxDepth = nil
|
||||
suggestedOnly := false
|
||||
|
||||
func getChildRoomChunks(roomID id.RoomID, recursionMaxDepth *int, recursionSuggestedOnly bool, client *mautrix.Client) []*mautrix.ChildRoomsChunk {
|
||||
var childRoomChunks []*mautrix.ChildRoomsChunk
|
||||
|
||||
hierarchyRequest := mautrix.ReqHierarchy{
|
||||
MaxDepth: maxDepth,
|
||||
SuggestedOnly: suggestedOnly,
|
||||
MaxDepth: recursionMaxDepth,
|
||||
SuggestedOnly: recursionSuggestedOnly,
|
||||
}
|
||||
finishedRequesting := false
|
||||
for !finishedRequesting {
|
||||
|
|
@ -132,13 +128,13 @@ func getChildRoomChunks(roomID id.RoomID, client *mautrix.Client) []*mautrix.Chi
|
|||
return childRoomChunks
|
||||
}
|
||||
|
||||
func addChildRooms(givenRoomIDs []id.RoomID, client *mautrix.Client) []id.RoomID {
|
||||
func addChildRooms(givenRoomIDs []id.RoomID, recursionMaxDepth *int, recursionSuggestedOnly bool, client *mautrix.Client) []id.RoomID {
|
||||
roomIDSet := make(map[id.RoomID]bool)
|
||||
|
||||
for _, givenRoomID := range givenRoomIDs {
|
||||
roomIDSet[givenRoomID] = true
|
||||
|
||||
childRoomChunks := getChildRoomChunks(givenRoomID, client)
|
||||
childRoomChunks := getChildRoomChunks(givenRoomID, recursionMaxDepth, recursionSuggestedOnly, client)
|
||||
for _, childRoomChunk := range childRoomChunks {
|
||||
roomIDSet[childRoomChunk.PublicRoomInfo.RoomID] = true
|
||||
}
|
||||
|
|
@ -228,10 +224,10 @@ func getServerVersionInfoByHomeserver(homeservers []string, federationClient *fc
|
|||
return serverVersionInfoByHomeserver
|
||||
}
|
||||
|
||||
func Get(rooms []string, recursive bool, client *mautrix.Client, federationClient *fclient.Client) RoomInfoTree {
|
||||
func Get(rooms []string, recursive bool, recursionMaxDepth *int, recursionSuggestedOnly bool, client *mautrix.Client, federationClient *fclient.Client) RoomInfoTree {
|
||||
roomIDs, aliasesByRoomID := resolveRooms(rooms, client)
|
||||
if recursive {
|
||||
roomIDs = addChildRooms(roomIDs, client)
|
||||
roomIDs = addChildRooms(roomIDs, recursionMaxDepth, recursionSuggestedOnly, client)
|
||||
}
|
||||
membersByHomeserverByRoomID := getMembersByHomeserverByRoomID(roomIDs, client)
|
||||
homeservers := getHomeservers(membersByHomeserverByRoomID)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue