diff --git a/commands.go b/commands.go index dd3d407..f8d1758 100644 --- a/commands.go +++ b/commands.go @@ -106,6 +106,7 @@ func fnSearchContacts(ce *WrappedCommandEvent) { return } + // TODO trim whitespace from args first contacts, err := ce.Bridge.IM.SearchContactList(ce.RawArgs) if err != nil { ce.Reply("Failed to search contacts: %s", err) diff --git a/imessage/bluebubbles/api.go b/imessage/bluebubbles/api.go index 32aacae..30c7d51 100644 --- a/imessage/bluebubbles/api.go +++ b/imessage/bluebubbles/api.go @@ -11,6 +11,7 @@ import ( "net/http" "net/url" "os" + "strconv" "strings" "time" "unicode" @@ -700,8 +701,6 @@ func (bb *blueBubbles) SearchContactList(input string) ([]*imessage.Contact, err matches := fuzzy.Find(strings.ToLower(input), contactFields) - bb.log.Trace().Interface("matches", matches).Str("input", input).Str("name", contact.FirstName+" "+contact.LastName).Msg("Fuzzy Match test") - if len(matches) > 0 { //&& matches[0].Score >= 0 imessageContact, _ := bb.convertBBContactToiMessageContact(contact) matchedContacts = append(matchedContacts, imessageContact) @@ -761,8 +760,6 @@ func (bb *blueBubbles) refreshContactsList() error { return err } - bb.log.Trace().Int("bbContactCount", len(contactResponse.Data)).Msg("refreshContactsList") - // save contacts for later bb.contacts = contactResponse.Data bb.contactsLastRefresh = time.Now() @@ -1260,13 +1257,25 @@ func (bb *blueBubbles) apiPostAsFormData(path string, formData map[string]interf } func (bb *blueBubbles) convertBBContactToiMessageContact(bbContact Contact) (*imessage.Contact, error) { + var convertedId string + switch id := bbContact.ID.(type) { + case string: + // ID is already a string, use it as is + convertedId = id + case int: + // ID is an integer, convert it to a string + convertedId = strconv.Itoa(id) + default: + convertedId = "" + } + return &imessage.Contact{ FirstName: bbContact.FirstName, LastName: bbContact.LastName, Nickname: bbContact.Nickname, Phones: convertPhones(bbContact.PhoneNumbers), Emails: convertEmails(bbContact.Emails), - UserGUID: bbContact.ID, + UserGUID: convertedId, // TODO Avatar: , }, nil } diff --git a/imessage/bluebubbles/interface.go b/imessage/bluebubbles/interface.go index 4f53cd8..a757237 100644 --- a/imessage/bluebubbles/interface.go +++ b/imessage/bluebubbles/interface.go @@ -115,7 +115,9 @@ type Contact struct { Birthday string `json:"birthday,omitempty"` Avatar string `json:"avatar,omitempty"` SourceType string `json:"sourceType,omitempty"` - ID string `json:"id,omitempty"` + // DEVNOTE: This field is almost always a string, + // but at least one user was getting an error because this was a number for them + ID interface{} `json:"id,omitempty"` } type PhoneNumber struct {