From e6f9c36d8734b981f125d5a776ac45d6ec17c137 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 27 Sep 2023 12:35:11 +0300 Subject: [PATCH] Send event when ditto ping stops failing --- libgm/longpoll.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libgm/longpoll.go b/libgm/longpoll.go index f83f25d..c47ea4b 100644 --- a/libgm/longpoll.go +++ b/libgm/longpoll.go @@ -25,12 +25,18 @@ const phoneNotRespondingTimeout = 30 * time.Second func (c *Client) doDittoPinger(log *zerolog.Logger, dittoPing <-chan struct{}, stopPinger <-chan struct{}) { notResponding := false + pingFailed := false exit := false onRespond := func() { if notResponding { log.Debug().Msg("Ditto ping succeeded, phone is back online") c.triggerEvent(&events.PhoneRespondingAgain{}) notResponding = false + pingFailed = false + } else if pingFailed { + // TODO separate event? + c.triggerEvent(&events.PhoneRespondingAgain{}) + pingFailed = false } } doPing := func() { @@ -40,6 +46,7 @@ func (c *Client) doDittoPinger(log *zerolog.Logger, dittoPing <-chan struct{}, s c.triggerEvent(&events.PingFailed{ Error: fmt.Errorf("failed to notify ditto activity: %w", err), }) + pingFailed = true return } select {