From 8931b14c4e40261e6161a3c776bf16cc0fdd1f3a Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Wed, 29 Jan 2020 20:40:06 +0100 Subject: [PATCH] Explicitly init messenger (#1821) Messenger needs to wait until all the topics/mailservers are loaded in the client, so we explicitly add a way to call Init. --- VERSION | 2 +- protocol/messenger.go | 10 ++++------ services/ext/api.go | 4 ++++ services/ext/service.go | 7 +++++-- services/shhext/api_nimbus.go | 4 ++++ .../status-im/status-go/protocol/messenger.go | 10 ++++------ 6 files changed, 22 insertions(+), 15 deletions(-) diff --git a/VERSION b/VERSION index 9b0025a78..72a8a6313 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.40.0 +0.41.0 diff --git a/protocol/messenger.go b/protocol/messenger.go index 8b013d789..9428a4ac5 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -367,17 +367,15 @@ func NewMessenger( logger: logger, } - // Start all services immediately. - // TODO: consider removing identity as an argument to Start(). - if err := encryptionProtocol.Start(identity); err != nil { - return nil, err - } - logger.Debug("messages persistence", zap.Bool("enabled", c.messagesPersistenceEnabled)) return messenger, nil } +func (m *Messenger) Start() error { + return m.encryptor.Start(m.identity) +} + // Init analyzes chats and contacts in order to setup filters // which are responsible for retrieving messages. func (m *Messenger) Init() error { diff --git a/services/ext/api.go b/services/ext/api.go index 80fd0be8e..3d3188c85 100644 --- a/services/ext/api.go +++ b/services/ext/api.go @@ -330,6 +330,10 @@ func (api *PublicAPI) ChatMessages(chatID, cursor string, limit int) (*Applicati }, nil } +func (api *PublicAPI) StartMessenger() error { + return api.service.StartMessenger() +} + func (api *PublicAPI) DeleteMessage(id string) error { return api.service.messenger.DeleteMessage(id) } diff --git a/services/ext/service.go b/services/ext/service.go index 12b9bc51a..547bc5cc2 100644 --- a/services/ext/service.go +++ b/services/ext/service.go @@ -165,12 +165,15 @@ func (s *Service) InitProtocol(identity *ecdsa.PrivateKey, db *sql.DB) error { / } s.accountsDB = accounts.NewDB(db) s.messenger = messenger + return messenger.Init() +} + +func (s *Service) StartMessenger() error { // Start a loop that retrieves all messages and propagates them to status-react. s.cancelMessenger = make(chan struct{}) go s.retrieveMessagesLoop(time.Second, s.cancelMessenger) go s.verifyTransactionLoop(30*time.Second, s.cancelMessenger) - - return s.messenger.Init() + return s.messenger.Start() } func (s *Service) retrieveMessagesLoop(tick time.Duration, cancel <-chan struct{}) { diff --git a/services/shhext/api_nimbus.go b/services/shhext/api_nimbus.go index 4ec231749..7fd4c686a 100644 --- a/services/shhext/api_nimbus.go +++ b/services/shhext/api_nimbus.go @@ -521,6 +521,10 @@ func (api *NimbusPublicAPI) UpdateMessageOutgoingStatus(id, newOutgoingStatus st return api.service.messenger.UpdateMessageOutgoingStatus(id, newOutgoingStatus) } +func (api *PublicAPI) StartMessenger() error { + return api.service.StartMessenger() +} + func (api *NimbusPublicAPI) SendChatMessage(ctx context.Context, message *protocol.Message) (*protocol.MessengerResponse, error) { return api.service.messenger.SendChatMessage(ctx, message) } diff --git a/vendor/github.com/status-im/status-go/protocol/messenger.go b/vendor/github.com/status-im/status-go/protocol/messenger.go index 8b013d789..9428a4ac5 100644 --- a/vendor/github.com/status-im/status-go/protocol/messenger.go +++ b/vendor/github.com/status-im/status-go/protocol/messenger.go @@ -367,17 +367,15 @@ func NewMessenger( logger: logger, } - // Start all services immediately. - // TODO: consider removing identity as an argument to Start(). - if err := encryptionProtocol.Start(identity); err != nil { - return nil, err - } - logger.Debug("messages persistence", zap.Bool("enabled", c.messagesPersistenceEnabled)) return messenger, nil } +func (m *Messenger) Start() error { + return m.encryptor.Start(m.identity) +} + // Init analyzes chats and contacts in order to setup filters // which are responsible for retrieving messages. func (m *Messenger) Init() error {