mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-10-31 20:08:55 +01:00
Improve logging when phone is seen again
This commit is contained in:
parent
7c579ad972
commit
625e110aab
2 changed files with 11 additions and 3 deletions
|
@ -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)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
user.go
10
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,
|
// 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) {
|
||||||
user.log.Debugfln("Saw phone after current bridge state said it has been offline, switching state back to connected")
|
if user.GetPrevBridgeState().Error == WAPhoneOffline && user.IsConnected() {
|
||||||
go user.sendBridgeState(BridgeState{StateEvent: StateConnected})
|
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
|
user.PhoneLastSeen = ts
|
||||||
go user.Update()
|
go user.Update()
|
||||||
|
|
Loading…
Reference in a new issue