@@ -93,8 +93,11 @@ func (bb *blueBubbles) Start(readyCallback func()) error {
93
93
94
94
go bb .PollForWebsocketMessages ()
95
95
96
+ // Preload some caches
96
97
bb .usingPrivateApi = bb .isPrivateApi ()
98
+ bb .RefreshContactList ()
97
99
100
+ // Notify main this API is fully loaded
98
101
readyCallback ()
99
102
100
103
return nil
@@ -709,11 +712,9 @@ func (bb *blueBubbles) matchHandleToContact(address string) *Contact {
709
712
710
713
var contact * Contact
711
714
712
- contacts := bb .getContactList ()
713
-
714
715
numericAddress := numericOnly (address )
715
716
716
- for _ , c := range contacts {
717
+ for _ , c := range bb . contacts {
717
718
// extract only the numbers of every phone (removes `-` and `+`)
718
719
var numericPhones []string
719
720
for _ , e := range c .PhoneNumbers {
@@ -754,9 +755,7 @@ func (bb *blueBubbles) SearchContactList(input string) ([]*imessage.Contact, err
754
755
755
756
var matchedContacts []* imessage.Contact
756
757
757
- contacts := bb .getContactList ()
758
-
759
- for _ , contact := range contacts {
758
+ for _ , contact := range bb .contacts {
760
759
761
760
contactFields := []string {
762
761
strings .ToLower (contact .FirstName + " " + contact .LastName ),
@@ -804,28 +803,15 @@ func (bb *blueBubbles) GetContactInfo(identifier string) (resp *imessage.Contact
804
803
func (bb * blueBubbles ) GetContactList () (resp []* imessage.Contact , err error ) {
805
804
bb .log .Trace ().Msg ("GetContactList" )
806
805
807
- contactResponse := bb .getContactList ()
808
-
809
- for _ , contact := range contactResponse {
806
+ for _ , contact := range bb .contacts {
810
807
imessageContact , _ := bb .convertBBContactToiMessageContact (& contact )
811
808
resp = append (resp , imessageContact )
812
809
}
813
810
814
811
return resp , nil
815
812
}
816
813
817
- // Updates the cache if necessary, and returns the list
818
- func (bb * blueBubbles ) getContactList () []Contact {
819
-
820
- if bb .contacts == nil ||
821
- bb .contactsLastRefresh .Add (1 * time .Hour ).Compare (time .Now ()) < 0 {
822
- bb .refreshContactsList ()
823
- }
824
-
825
- return bb .contacts
826
- }
827
-
828
- func (bb * blueBubbles ) refreshContactsList () error {
814
+ func (bb * blueBubbles ) RefreshContactList () error {
829
815
bb .log .Trace ().Msg ("refreshContactsList" )
830
816
831
817
var contactResponse ContactResponse
@@ -945,7 +931,7 @@ func (bb *blueBubbles) SendMessage(chatID, text string, replyTo string, replyToP
945
931
bb .log .Trace ().Str ("chatID" , chatID ).Str ("text" , text ).Str ("replyTo" , replyTo ).Int ("replyToPart" , replyToPart ).Any ("richLink" , richLink ).Interface ("metadata" , metadata ).Msg ("SendMessage" )
946
932
947
933
var method string
948
- if replyTo != "" || bb . usingPrivateApi {
934
+ if replyTo != "" {
949
935
method = "private-api"
950
936
} else {
951
937
// we have to use apple-script and send a second message
0 commit comments