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"
"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)))
}
}
}

10
user.go
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,
// 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()