Skip to content

Commit

Permalink
Merge pull request #180 from mautrix/feat/start-dm-command
Browse files Browse the repository at this point in the history
Feat/start dm command
  • Loading branch information
trek-boldly-go authored Jan 31, 2024
2 parents 8f528ba + 9e5aee5 commit 4171ab0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 14 additions & 5 deletions imessage/bluebubbles/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"net/url"
"os"
"strconv"
"strings"
"time"
"unicode"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion imessage/bluebubbles/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4171ab0

Please sign in to comment.