Improve logging when phone is seen again

This commit is contained in:
Tulir Asokan 2022-05-04 11:17:34 +03:00
parent 7c579ad972
commit 625e110aab
2 changed files with 11 additions and 3 deletions

View file

@ -26,6 +26,7 @@ import (
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
"time"
"github.com/skip2/go-qrcode" "github.com/skip2/go-qrcode"
"github.com/tidwall/gjson" "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) 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 { } else {
ce.Reply("Logged in as +%s (device #%d), connection to WhatsApp OK (probably)", ce.User.JID.User, ce.User.JID.Device) 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)))
}
} }
} }

View file

@ -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, // 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. // so don't spam the database with an update every time there's an event.
return return
} else if !user.PhoneRecentlySeen(false) && user.GetPrevBridgeState().Error == WAPhoneOffline && user.IsConnected() { } 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") 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}) 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 user.PhoneLastSeen = ts
go user.Update() go user.Update()