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.
This commit is contained in:
Andrea Maria Piana 2020-01-29 20:40:06 +01:00 committed by GitHub
parent 741f43cb0c
commit 8931b14c4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 15 deletions

View File

@ -1 +1 @@
0.40.0
0.41.0

View File

@ -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 {

View File

@ -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)
}

View File

@ -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{}) {

View File

@ -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)
}

View File

@ -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 {