@@ -137,7 +137,6 @@ type Messenger struct {
137137
138138 started bool
139139 paused atomic.Bool
140- backgroundMode atomic.Bool // true when the app UI is not visible; gates background history syncs
141140 quit chan struct {}
142141 ctx context.Context
143142 cancel context.CancelFunc
@@ -548,29 +547,6 @@ func (m *Messenger) processSentMessage(id string) error {
548547 return nil
549548}
550549
551- func (m * Messenger ) ToForeground () {
552- m .SetPaused (false )
553- if m .httpServer != nil {
554- m .httpServer .ToForeground ()
555- }
556- m .backgroundMode .Store (false )
557- if m .messaging != nil {
558- m .messaging .SetFilterBackgroundMode (false )
559- }
560- m .asyncRequestAllHistoricMessages ()
561- }
562-
563- func (m * Messenger ) ToBackground () {
564- m .SetPaused (true )
565- if m .httpServer != nil {
566- m .httpServer .ToBackground ()
567- }
568- m .backgroundMode .Store (true )
569- if m .messaging != nil {
570- m .messaging .SetFilterBackgroundMode (true )
571- }
572- }
573-
574550func (m * Messenger ) SetPaused (paused bool ) {
575551 m .paused .Store (paused )
576552 if m .ensVerifier != nil {
@@ -593,6 +569,16 @@ func (m *Messenger) SetPaused(paused bool) {
593569 m .logger .Warn ("failed to pause data sync" , zap .Error (err ))
594570 }
595571 }
572+ if ! paused {
573+ if m .httpServer != nil {
574+ m .httpServer .ToForeground ()
575+ }
576+ if m .started {
577+ m .asyncRequestAllHistoricMessages ()
578+ }
579+ } else if m .httpServer != nil {
580+ m .httpServer .ToBackground ()
581+ }
596582 // ToDo: the current ArchiveManager does not provide SetPaused method yet
597583 // if m.archiveManager != nil {
598584 // m.archiveManager.SetPaused(paused)
@@ -833,9 +819,8 @@ func (m *Messenger) handleConnectionChange(online bool) {
833819 }
834820
835821 // Start fetching messages from store nodes.
836- // Skip when backgrounded: the sync will run in ToForeground()
837- // when the app returns to foreground.
838- if online && ! m .backgroundMode .Load () {
822+ // Skip when backgrounded: the sync will run when the app returns to foreground.
823+ if online && ! m .isPaused () {
839824 m .asyncRequestAllHistoricMessages ()
840825 }
841826
0 commit comments