func PopulatePublicRooms(ctx context.Context, roomIDs []string, rsAPI RoomserverInternalAPI) ([]gomatrixserverlib.PublicRoom, error) {
	avatarTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.avatar", StateKey: ""}
	nameTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.name", StateKey: ""}
	canonicalTuple := gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomCanonicalAlias, StateKey: ""}
	topicTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.topic", StateKey: ""}
	guestTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.guest_access", StateKey: ""}
	visibilityTuple := gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomHistoryVisibility, StateKey: ""}
	joinRuleTuple := gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomJoinRules, StateKey: ""}

	var stateRes QueryBulkStateContentResponse
	err := rsAPI.QueryBulkStateContent(ctx, &QueryBulkStateContentRequest{
		RoomIDs:        roomIDs,
		AllowWildcards: true,
		StateTuples: []gomatrixserverlib.StateKeyTuple{
			nameTuple, canonicalTuple, topicTuple, guestTuple, visibilityTuple, joinRuleTuple, avatarTuple,
			{EventType: gomatrixserverlib.MRoomMember, StateKey: "*"},
		},
	}, &stateRes)
	if err != nil {
		util.GetLogger(ctx).WithError(err).Error("QueryBulkStateContent failed")
		return nil, err
	}
	chunk := make([]gomatrixserverlib.PublicRoom, len(roomIDs))
	i := 0
	for roomID, data := range stateRes.Rooms {
		pub := gomatrixserverlib.PublicRoom{
			RoomID: roomID,
		}
		joinCount := 0
		var joinRule, guestAccess string
		for tuple, contentVal := range data {
			if tuple.EventType == gomatrixserverlib.MRoomMember && contentVal == "join" {
				joinCount++
				continue
			}
			switch tuple {
			case avatarTuple:
				pub.AvatarURL = contentVal
			case nameTuple:
				pub.Name = contentVal
			case topicTuple:
				pub.Topic = contentVal
			case canonicalTuple:
				pub.CanonicalAlias = contentVal
			case visibilityTuple:
				pub.WorldReadable = contentVal == "world_readable"
			// need both of these to determine whether guests can join
			case joinRuleTuple:
				joinRule = contentVal
			case guestTuple:
				guestAccess = contentVal
			}
		}
		if joinRule == gomatrixserverlib.Public && guestAccess == "can_join" {
			pub.GuestCanJoin = true
		}
		pub.JoinedMembersCount = joinCount
		chunk[i] = pub
		i++
	}
	return chunk, nil
}
// PopulatePublicRooms extracts PublicRoom information for all the provided room IDs. The IDs are not checked to see if they are visible in the
// published room directory.
// due to lots of switches
// nolint:gocyclo
PopulatePublicRooms extracts PublicRoom information for all the provided room IDs. The IDs are not checked to see if they are visible in the
published room directory.
due to lots of switches
nolint:gocyclo
// PopulatePublicRooms extracts PublicRoom information for all the provided room IDs . The IDs are not checked to see if they are visible in the // published room directory . // due to lots of switches // nolint : gocyclo
func PopulatePublicRooms(ctx context.Context, roomIDs []string, rsAPI RoomserverInternalAPI) ([]gomatrixserverlib.PublicRoom, error) {
	avatarTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.avatar", StateKey: ""}
	nameTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.name", StateKey: ""}
	canonicalTuple := gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomCanonicalAlias, StateKey: ""}
	topicTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.topic", StateKey: ""}
	guestTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.guest_access", StateKey: ""}
	visibilityTuple := gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomHistoryVisibility, StateKey: ""}
	joinRuleTuple := gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomJoinRules, StateKey: ""}
	var stateRes QueryBulkStateContentResponse
	err := rsAPI.QueryBulkStateContent(ctx, &QueryBulkStateContentRequest{
		RoomIDs:        roomIDs,
		AllowWildcards: true,
		StateTuples: []gomatrixserverlib.StateKeyTuple{
			nameTuple, canonicalTuple, topicTuple, guestTuple, visibilityTuple, joinRuleTuple, avatarTuple,
			{EventType: gomatrixserverlib.MRoomMember, StateKey: "*"},
		},
	}, &stateRes)
	if err != nil {
		util.GetLogger(ctx).WithError(err).Error("QueryBulkStateContent failed")
		return nil, err
	}
	chunk := make([]gomatrixserverlib.PublicRoom, len(roomIDs))
	i := 0
	for roomID, data := range stateRes.Rooms {
		pub := gomatrixserverlib.PublicRoom{
			RoomID: roomID,
		}
		joinCount := 0
		var joinRule, guestAccess string
		for tuple, contentVal := range data {
			if tuple.EventType == gomatrixserverlib.MRoomMember && contentVal == "join" {
				joinCount++
				continue
			}
			switch tuple {
			case avatarTuple:
				pub.AvatarURL = contentVal
			case nameTuple:
				pub.Name = contentVal
			case topicTuple:
				pub.Topic = contentVal
			case canonicalTuple:
				pub.CanonicalAlias = contentVal
			case visibilityTuple:
				pub.WorldReadable = contentVal == "world_readable"
			case joinRuleTuple:
				joinRule = contentVal
			case guestTuple:
				guestAccess = contentVal
			}
		}
		if joinRule == gomatrixserverlib.Public && guestAccess == "can_join" {
			pub.GuestCanJoin = true
		}
		pub.JoinedMembersCount = joinCount
		chunk[i] = pub
		i++
	}
	return chunk, nil
}
func PopulatePublicRooms ( ctx context . Context , roomIDs [ ] string , rsAPI RoomserverInternalAPI ) ( [ ] gomatrixserverlib . PublicRoom , error ) { avatarTuple := gomatrixserverlib . StateKeyTuple { EventType : " " , StateKey : " " } nameTuple := gomatrixserverlib . StateKeyTuple { EventType : " " , StateKey : " " } canonicalTuple := gomatrixserverlib . StateKeyTuple { EventType : gomatrixserverlib . MRoomCanonicalAlias , StateKey : " " } topicTuple := gomatrixserverlib . StateKeyTuple { EventType : " " , StateKey : " " } guestTuple := gomatrixserverlib . StateKeyTuple { EventType : " " , StateKey : " " } visibilityTuple := gomatrixserverlib . StateKeyTuple { EventType : gomatrixserverlib . MRoomHistoryVisibility , StateKey : " " } joinRuleTuple := gomatrixserverlib . StateKeyTuple { EventType : gomatrixserverlib . MRoomJoinRules , StateKey : " " } var stateRes QueryBulkStateContentResponse err := rsAPI . QueryBulkStateContent ( ctx , & QueryBulkStateContentRequest { RoomIDs : roomIDs , AllowWildcards : true , StateTuples : [ ] gomatrixserverlib . StateKeyTuple { nameTuple , canonicalTuple , topicTuple , guestTuple , visibilityTuple , joinRuleTuple , avatarTuple , { EventType : gomatrixserverlib . MRoomMember , StateKey : " " } , } , } , & stateRes ) if err != nil { util . GetLogger ( ctx ) . WithError ( err ) . Error ( " " ) return nil , err } chunk := make ( [ ] gomatrixserverlib . PublicRoom , len ( roomIDs ) ) i := 0 for roomID , data := range stateRes . Rooms { pub := gomatrixserverlib . PublicRoom { RoomID : roomID , } joinCount := 0 var joinRule , guestAccess string for tuple , contentVal := range data { if tuple . EventType == gomatrixserverlib . MRoomMember && contentVal == " " { joinCount ++ continue } switch tuple { case avatarTuple : pub . AvatarURL = contentVal case nameTuple : pub . Name = contentVal case topicTuple : pub . Topic = contentVal case canonicalTuple : pub . CanonicalAlias = contentVal case visibilityTuple : pub . WorldReadable = contentVal == " " case joinRuleTuple : joinRule = contentVal case guestTuple : guestAccess = contentVal } } if joinRule == gomatrixserverlib . Public && guestAccess == " " { pub . GuestCanJoin = true } pub . JoinedMembersCount = joinCount chunk [ i ] = pub i ++ } return chunk , nil }
PopulatePublicRooms extracts PublicRoom information for all the provided room IDs.
PopulatePublicRooms extracts PublicRoom information for all the provided room IDs .
// need both of these to determine whether guests can join