From 625e110aab3f04e4e4a4f87f11e9674ca071deb7 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 4 May 2022 11:17:34 +0300 Subject: [PATCH] Improve logging when phone is seen again --- commands.go | 4 ++++ user.go | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/commands.go b/commands.go index a289eab..b959cc7 100644 --- a/commands.go +++ b/commands.go @@ -26,6 +26,7 @@ import ( "sort" "strconv" "strings" + "time" "github.com/skip2/go-qrcode" "github.com/tidwall/gjson" @@ -710,6 +711,9 @@ func (handler *CommandHandler) CommandPing(ce *CommandEvent) { ce.Reply("You're logged in as +%s (device #%d), but you don't have a WhatsApp connection.", ce.User.JID.User, ce.User.JID.Device) } else { ce.Reply("Logged in as +%s (device #%d), connection to WhatsApp OK (probably)", ce.User.JID.User, ce.User.JID.Device) + if !ce.User.PhoneRecentlySeen(false) { + ce.Reply("Phone hasn't been seen in %s", formatDisconnectTime(time.Now().Sub(ce.User.PhoneLastSeen))) + } } } diff --git a/user.go b/user.go index 5d3acf8..3904925 100644 --- a/user.go +++ b/user.go @@ -536,9 +536,13 @@ func (user *User) phoneSeen(ts time.Time) { // The last seen timestamp isn't going to be perfectly accurate in any case, // so don't spam the database with an update every time there's an event. return - } else if !user.PhoneRecentlySeen(false) && user.GetPrevBridgeState().Error == WAPhoneOffline && user.IsConnected() { - user.log.Debugfln("Saw phone after current bridge state said it has been offline, switching state back to connected") - go user.sendBridgeState(BridgeState{StateEvent: StateConnected}) + } else if !user.PhoneRecentlySeen(false) { + if user.GetPrevBridgeState().Error == WAPhoneOffline && user.IsConnected() { + user.log.Debugfln("Saw phone after current bridge state said it has been offline, switching state back to connected") + go user.sendBridgeState(BridgeState{StateEvent: StateConnected}) + } else { + user.log.Debugfln("Saw phone after current bridge state said it has been offline, not sending new bridge state (prev: %s, connected: %t)", user.GetPrevBridgeState().Error, user.IsConnected()) + } } user.PhoneLastSeen = ts go user.Update()