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:
parent
741f43cb0c
commit
8931b14c4e
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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{}) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue