Skip to content

Commit

Permalink
fix incorrect use of pointer when matching contacts based on address
Browse files Browse the repository at this point in the history
  • Loading branch information
trek-boldly-go committed Feb 6, 2024
1 parent 61637d6 commit dc20080
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions imessage/bluebubbles/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,13 @@ func (bb *blueBubbles) GetChatsWithMessagesAfter(minDate time.Time) (resp []imes

func (bb *blueBubbles) matchHandleToContact(address string) *Contact {

var contact *Contact
var matchedContact *Contact

numericAddress := numericOnly(address)

for _, c := range bb.contacts {
var contact *Contact

// extract only the numbers of every phone (removes `-` and `+`)
var numericPhones []string
for _, e := range c.PhoneNumbers {
Expand All @@ -701,34 +703,33 @@ func (bb *blueBubbles) matchHandleToContact(address string) *Contact {
var phoneStrings = convertPhones(c.PhoneNumbers)

// check for exact matches for either an email or phone
if strings.Contains(address, "@") && containsString(emailStrings, address) {
contact = &c
if c.SourceType == "api" {
break
if strings.Contains(address, "@") {
if containsString(emailStrings, address) {
contact = &c
}
} else if containsString(phoneStrings, numericAddress) {
contact = &c
if c.SourceType == "api" {
break
}
}

for _, p := range numericPhones {
matchLengths := []int{15, 14, 13, 12, 11, 10, 9, 8, 7}
if containsInt(matchLengths, len(p)) && strings.HasSuffix(numericAddress, p) {
contact = &c
if c.SourceType == "api" {
break
}
}
}

if contact != nil && c.SourceType == "api" {
break
// Contacts with a source type of "api" were imported into BB and preferable
if contact != nil && contact.SourceType == "api" {
return contact
}

// Contacts with a source type of "db" are stored on the mac and can be used as fallback in case an imported one isn't found
if contact != nil && matchedContact == nil {
matchedContact = contact
}
}

return contact
return matchedContact
}

func (bb *blueBubbles) SearchContactList(input string) ([]*imessage.Contact, error) {
Expand Down Expand Up @@ -771,6 +772,8 @@ func (bb *blueBubbles) GetContactInfo(identifier string) (resp *imessage.Contact

contact := bb.matchHandleToContact(identifier)

bb.log.Trace().Str("identifier", identifier).Interface("contact", contact).Msg("GetContactInfo: found a contact")

if contact != nil {
resp, _ = bb.convertBBContactToiMessageContact(contact)
return resp, nil
Expand Down

0 comments on commit dc20080

Please sign in to comment.