// FilterByType filters messages based on a query.
// If includeAllErrors then MessageUnboxedError are all returned. Otherwise, they are filtered based on type.
// Messages whose type cannot be determined are considered errors.
4161
func FilterByType(msgs []chat1.MessageUnboxed, query *chat1.GetThreadQuery, includeAllErrors bool) (res []chat1.MessageUnboxed) {
	useTypeFilter := (query != nil && len(query.MessageTypes) > 0)

	typmap := make(map[chat1.MessageType]bool)
	if useTypeFilter {
		for _, mt := range query.MessageTypes {
			typmap[mt] = true
		}
	}

	for _, msg := range msgs {
		state, err := msg.State()
		if err != nil {
			if includeAllErrors {
				res = append(res, msg)
			}
			continue
		}
		switch state {
		case chat1.MessageUnboxedState_ERROR:
			if includeAllErrors {
				res = append(res, msg)
			}
		case chat1.MessageUnboxedState_PLACEHOLDER:
			// We don't know what the type is for these, so just include them
			res = append(res, msg)
		default:
			_, match := typmap[msg.GetMessageType()]
			if !useTypeFilter || match {
				res = append(res, msg)
			}
		}
	}
	return res
}
845718
func (s *SortGeoDistance) filterTermsByType(terms []string) []string {
	var termsWithShiftZero []string
	for _, term := range terms {
		valid, shift := numeric.ValidPrefixCodedTerm(term)
		if valid && shift == 0 {
			termsWithShiftZero = append(termsWithShiftZero, term)
		}
	}
	return termsWithShiftZero
}
566936
func UserFilterByEmail(email string) func(db *gorm.DB) *gorm.DB {
	return func(db *gorm.DB) *gorm.DB {
		return db.Where("email = ?", email)
	}
}
734827
func (idx *CfIndex) FilterHashesByBlockHashes(blockHashes []*chainhash.Hash,
	filterType wire.FilterType) ([][]byte, error) {
	return idx.entriesByBlockHashes(cfHashKeys, filterType, blockHashes)
}
237547
func (api *MobileGatewayAPI) FilterBy(key string, value interface{}) *MobileGatewayAPI {
	api.filterBy(key, value, false)
	return api
}
174996
func GetByFilters(skip int, filters ...Filter) (callinfo CallInfo, ok bool) {
	filters = append(FilterCommons, filters...)
	for {
		skip++

		if callinfo, ok = retrieveCallInfo(skip); !ok {
			return
		}

		valid, stop := filterAll(callinfo, filters...)
		if valid {
			return callinfo, true
		}
		if stop {
			return callinfo, false
		}
	}
}
1356545
func (api *AutoBackupAPI) FilterBy(key string, value interface{}) *AutoBackupAPI {
	api.filterBy(key, value, false)
	return api
}
215484
func (i *InitContext) GetByType(t Type) (map[string]*Plugin, error) {
	p, ok := i.plugins.byTypeAndID[t]
	if !ok {
		return nil, errors.Wrapf(errdefs.ErrNotFound, "no plugins registered for %s", t)
	}

	return p, nil
}
515536
func (m *Message) PartsFilter(filter func(*Message) bool) []*Message {

	messages := make([]*Message, 0, 1)
	if m.HasParts() {
		for _, part := range m.Parts {
			if filter(part) {
				messages = append(messages, part)
			}
		}
	}
	return messages
}
433483
func (api *PrivateHostAPI) FilterBy(key string, value interface{}) *PrivateHostAPI {
	api.filterBy(key, value, false)
	return api
}
305986
func (o *InvitationManager) FilterByUser(username string, status string) ([]JoinOrganizationInvitation, error) {
	orgRequests := []JoinOrganizationInvitation{}
	if status == "" {
		return o.GetByUser(username)
	}
	qry := bson.M{
		"user":   username,
		"status": status,
	}
	err := o.collection.Find(qry).All(&orgRequests)
	return orgRequests, err
}
898754
func (api *ProductDiskAPI) FilterBy(key string, value interface{}) *ProductDiskAPI {
	api.filterBy(key, value, false)
	return api
}
132599
func FilterByIssuer(iss string) (CertificateFilter, error) {
	issFilter, err := regexp.Compile(iss)
	if err != nil {
		return nil, err
	}

	return func(cm *CertificateMetadata) bool {
		return issFilter.MatchString(cm.Issuer)
	}, nil
}
1196190
func (api *SubnetAPI) FilterBy(key string, value interface{}) *SubnetAPI {
	api.filterBy(key, value, false)
	return api
}
283678
func (api *IPv6NetAPI) FilterBy(key string, value interface{}) *IPv6NetAPI {
	api.filterBy(key, value, false)
	return api
}
146264
func (t Types) GetByType(tp string) (Type, bool) {
	for _, tt := range t {
		if strings.EqualFold(tt.Type(), tp) {
			return tt, true
		}
	}

	if !strings.Contains(tp, "+") {
		// Try with the main and sub type
		parts := strings.Split(tp, "/")
		if len(parts) == 2 {
			return t.GetByMainSubType(parts[0], parts[1])
		}
	}

	return Type{}, false
}
1092529
func (cm AsStandard) MFilterType(filter string) *metadata.MFilterType {
	mft := metadata.MFilterType{}
	mi := metadata.MIFilterType
	for _, cd := range cm.Elements[mi.Name] {
		if cd.Attr["Filter"] != filter {
			continue
		}
		metadata.FieldTransfer(cd.Attr).To(&mft)
		for _, entry := range cd.Entries() {
			tmp := metadata.FilterType{}
			entry.SetFields(&tmp)
			mft.FilterType = append(mft.FilterType, tmp)
		}
	}
	return &mft
}