X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/2e2524881dfe8f6c5cabfd9d342d5d3492953bd4..12bd9e96f3b3e67290484e3829461e054110db27:/whatsapp_find.go?ds=inline diff --git a/whatsapp_find.go b/whatsapp_find.go index 545e01c..9e3cbf8 100644 --- a/whatsapp_find.go +++ b/whatsapp_find.go @@ -61,6 +61,7 @@ func whatsappFind(ctx context.Context, link WhatsAppLink, groups *WhatsAppGroups } var matches []WhatsAppMatch + for jid, contact := range contacts { names := []string{contact.FullName, contact.FirstName, contact.BusinessName, contact.PushName} shown := slices.IndexFunc(names, func(name string) bool { @@ -111,14 +112,15 @@ func whatsappFold(text string) string { return strings.ToLower(strings.TrimSpace(folded)) } -// whatsappFindAnswer returns the answer of whatsappFind for name with matches. Without -// groups, the answer says that it has no groups. +// whatsappFindAnswer returns the answer of whatsappFind for name with matches. +// Without groups, the answer says that it has no groups. func whatsappFindAnswer(name string, matches []WhatsAppMatch, groups bool) string { slices.SortFunc(matches, func(a, b WhatsAppMatch) int { return cmp.Or(strings.Compare(whatsappFold(a.name), whatsappFold(b.name)), strings.Compare(a.id, b.id)) }) var lines []string + for _, match := range matches[:min(len(matches), whatsappFindMatches)] { lines = append(lines, match.id+" | "+match.name+" | "+match.kind) }