fix: a few adjustments for matterbridge

- exposig Online info
- adding ability to disable backup loop and auto message loop

Issue #12710
This commit is contained in:
Michal Iskierko 2023-12-05 11:08:26 +01:00 committed by Michał Iskierko
parent 6599be1721
commit 53ac61bb8b
6 changed files with 36 additions and 12 deletions

View File

@ -11,4 +11,10 @@ type FeatureFlags struct {
// MailserverCycle indicates whether we should enable or not the mailserver cycle // MailserverCycle indicates whether we should enable or not the mailserver cycle
MailserverCycle bool MailserverCycle bool
// DisableCheckingForBackup disables backup loop
DisableCheckingForBackup bool
// DisableAutoMessageLoop disables auto message loop
DisableAutoMessageLoop bool
} }

View File

@ -796,10 +796,14 @@ func (m *Messenger) Start() (*MessengerResponse, error) {
m.watchPendingCommunityRequestToJoin() m.watchPendingCommunityRequestToJoin()
m.broadcastLatestUserStatus() m.broadcastLatestUserStatus()
m.timeoutAutomaticStatusUpdates() m.timeoutAutomaticStatusUpdates()
m.startBackupLoop() if !m.config.featureFlags.DisableCheckingForBackup {
err = m.startAutoMessageLoop() m.startBackupLoop()
if err != nil { }
return nil, err if !m.config.featureFlags.DisableAutoMessageLoop {
err = m.startAutoMessageLoop()
if err != nil {
return nil, err
}
} }
m.startSyncSettingsLoop() m.startSyncSettingsLoop()
m.startSettingsChangesLoop() m.startSettingsChangesLoop()
@ -930,7 +934,7 @@ func (m *Messenger) handleConnectionChange(online bool) {
m.ensVerifier.SetOnline(online) m.ensVerifier.SetOnline(online)
} }
func (m *Messenger) online() bool { func (m *Messenger) Online() bool {
switch m.transport.WakuVersion() { switch m.transport.WakuVersion() {
case 2: case 2:
return m.transport.PeerCount() > 0 return m.transport.PeerCount() > 0
@ -1443,13 +1447,13 @@ func (m *Messenger) handleENSVerificationSubscription(c chan []*ens.Verification
// watchConnectionChange checks the connection status and call handleConnectionChange when this changes // watchConnectionChange checks the connection status and call handleConnectionChange when this changes
func (m *Messenger) watchConnectionChange() { func (m *Messenger) watchConnectionChange() {
m.logger.Debug("watching connection changes") m.logger.Debug("watching connection changes")
state := m.online() state := m.Online()
m.handleConnectionChange(state) m.handleConnectionChange(state)
go func() { go func() {
for { for {
select { select {
case <-time.After(200 * time.Millisecond): case <-time.After(200 * time.Millisecond):
newState := m.online() newState := m.Online()
if state != newState { if state != newState {
state = newState state = newState
m.logger.Debug("connection changed", zap.Bool("online", state)) m.logger.Debug("connection changed", zap.Bool("online", state))
@ -1526,7 +1530,7 @@ func (m *Messenger) watchExpiredMessages() {
for { for {
select { select {
case <-time.After(time.Second): case <-time.After(time.Second):
if m.online() { if m.Online() {
err := m.resendExpiredMessages() err := m.resendExpiredMessages()
if err != nil { if err != nil {
m.logger.Debug("Error when resending expired emoji reactions", zap.Error(err)) m.logger.Debug("Error when resending expired emoji reactions", zap.Error(err))
@ -1609,7 +1613,7 @@ func (m *Messenger) PublishIdentityImage() error {
} }
// If not online, we schedule it // If not online, we schedule it
if !m.online() { if !m.Online() {
m.shouldPublishContactCode = true m.shouldPublishContactCode = true
return nil return nil
} }

View File

@ -38,7 +38,7 @@ func (m *Messenger) startBackupLoop() {
for { for {
select { select {
case <-ticker.C: case <-ticker.C:
if !m.online() { if !m.Online() {
continue continue
} }

View File

@ -427,7 +427,7 @@ func (m *Messenger) handleCommunitiesSubscription(c chan *communities.Subscripti
case <-ticker.C: case <-ticker.C:
// If we are not online, we don't even try // If we are not online, we don't even try
if !m.online() { if !m.Online() {
continue continue
} }

View File

@ -275,6 +275,20 @@ func WithPushNotifications() func(c *config) error {
} }
} }
func WithCheckingForBackupDisabled() func(c *config) error {
return func(c *config) error {
c.featureFlags.DisableCheckingForBackup = true
return nil
}
}
func WithAutoMessageDisabled() func(c *config) error {
return func(c *config) error {
c.featureFlags.DisableAutoMessageLoop = true
return nil
}
}
func WithEnvelopesMonitorConfig(emc *transport.EnvelopesMonitorConfig) Option { func WithEnvelopesMonitorConfig(emc *transport.EnvelopesMonitorConfig) Option {
return func(c *config) error { return func(c *config) error {
c.envelopesMonitorConfig = emc c.envelopesMonitorConfig = emc

View File

@ -41,7 +41,7 @@ var maxTopicsPerRequest int = 10
var ErrNoFiltersForChat = errors.New("no filter registered for given chat") var ErrNoFiltersForChat = errors.New("no filter registered for given chat")
func (m *Messenger) shouldSync() (bool, error) { func (m *Messenger) shouldSync() (bool, error) {
if m.mailserverCycle.activeMailserver == nil || !m.online() { if m.mailserverCycle.activeMailserver == nil || !m.Online() {
return false, nil return false, nil
} }