diff --git a/libgm/event_handler.go b/libgm/event_handler.go index 3b19423..7cc705f 100644 --- a/libgm/event_handler.go +++ b/libgm/event_handler.go @@ -214,7 +214,9 @@ func (c *Client) handleUpdatesEvent(msg *IncomingRPCMessage) { c.triggerEvent(&events.GaiaLoggedOut{}) return } - c.bumpNextBugleDefaultCheck(DefaultBugleDefaultCheckInterval) + if !msg.IsOld { + c.bumpNextBugleDefaultCheck(DefaultBugleDefaultCheckInterval) + } data, ok := msg.DecryptedMessage.(*gmproto.UpdateEvents) if !ok { c.Logger.Error(). diff --git a/libgm/longpoll.go b/libgm/longpoll.go index 60804d6..09f7626 100644 --- a/libgm/longpoll.go +++ b/libgm/longpoll.go @@ -199,9 +199,8 @@ func (dp *dittoPinger) Loop() { case <-dp.stop: return } - if time.Until(dp.client.getNextBugleDefaultCheck()) <= 0 { + if dp.client.shouldDoBugleDefaultCheck() { go dp.BugleDefaultCheck() - dp.client.bumpNextBugleDefaultCheck(DefaultBugleDefaultCheckInterval) } } } @@ -226,10 +225,14 @@ func (dp *dittoPinger) BugleDefaultCheck() { } } -func (c *Client) getNextBugleDefaultCheck() time.Time { +func (c *Client) shouldDoBugleDefaultCheck() bool { c.nextBugleDefaultCheckLock.Lock() defer c.nextBugleDefaultCheckLock.Unlock() - return c.nextBugleDefaultCheck + if time.Until(c.nextBugleDefaultCheck) <= 0 { + c.nextBugleDefaultCheck = time.Now().Add(DefaultBugleDefaultCheckInterval) + return true + } + return false } func (c *Client) bumpNextBugleDefaultCheck(after time.Duration) {