From 4a95af63c383cdae07dad7b2e3ff72d8070649c9 Mon Sep 17 00:00:00 2001 From: trek-boldly-go Date: Tue, 30 Jan 2024 17:55:21 -0600 Subject: [PATCH 1/2] account for the contact id to possibly be number --- commands.go | 1 + imessage/bluebubbles/api.go | 17 ++++++++++++++++- imessage/bluebubbles/interface.go | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) 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 0c7100c..69cf32d 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,6 +701,7 @@ func (bb *blueBubbles) SearchContactList(input string) ([]*imessage.Contact, err matches := fuzzy.Find(strings.ToLower(input), contactFields) + // TODO remove 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 @@ -761,6 +763,7 @@ func (bb *blueBubbles) refreshContactsList() error { return err } + // TODO remove bb.log.Trace().Int("bbContactCount", len(contactResponse.Data)).Msg("refreshContactsList") // save contacts for later @@ -1260,13 +1263,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 95903ac..019b7ca 100644 --- a/imessage/bluebubbles/interface.go +++ b/imessage/bluebubbles/interface.go @@ -115,7 +115,7 @@ type Contact struct { Birthday string `json:"birthday,omitempty"` Avatar string `json:"avatar,omitempty"` SourceType string `json:"sourceType,omitempty"` - ID string `json:"id,omitempty"` + ID interface{} `json:"id,omitempty"` } type PhoneNumber struct { From 9e5aee5b9f8aad41da794cd78424711d3ad5ecaa Mon Sep 17 00:00:00 2001 From: trek-boldly-go Date: Tue, 30 Jan 2024 18:47:23 -0600 Subject: [PATCH 2/2] add devnote --- imessage/bluebubbles/api.go | 6 ------ imessage/bluebubbles/interface.go | 4 +++- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/imessage/bluebubbles/api.go b/imessage/bluebubbles/api.go index 69cf32d..850d453 100644 --- a/imessage/bluebubbles/api.go +++ b/imessage/bluebubbles/api.go @@ -701,9 +701,6 @@ func (bb *blueBubbles) SearchContactList(input string) ([]*imessage.Contact, err matches := fuzzy.Find(strings.ToLower(input), contactFields) - // TODO remove - 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) @@ -763,9 +760,6 @@ func (bb *blueBubbles) refreshContactsList() error { return err } - // TODO remove - bb.log.Trace().Int("bbContactCount", len(contactResponse.Data)).Msg("refreshContactsList") - // save contacts for later bb.contacts = contactResponse.Data bb.contactsLastRefresh = time.Now() diff --git a/imessage/bluebubbles/interface.go b/imessage/bluebubbles/interface.go index 019b7ca..fce5535 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 interface{} `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 {