Send phone not responding alerts to management room

This commit is contained in:
Tulir Asokan 2023-10-05 12:56:42 +03:00
parent 766d79562a
commit 500f030fb3

28
user.go
View file

@ -68,15 +68,16 @@ type User struct {
spaceMembershipChecked bool spaceMembershipChecked bool
longPollingError error longPollingError error
browserInactiveType status.BridgeStateErrorCode browserInactiveType status.BridgeStateErrorCode
batteryLow bool batteryLow bool
mobileData bool mobileData bool
phoneResponding bool phoneResponding bool
ready bool ready bool
sessionID string sessionID string
batteryLowAlertSent time.Time batteryLowAlertSent time.Time
pollErrorAlertSent bool pollErrorAlertSent bool
phoneNotRespondingAlertSent bool
loginInProgress atomic.Bool loginInProgress atomic.Bool
pairSuccessChan chan struct{} pairSuccessChan chan struct{}
@ -576,9 +577,18 @@ func (user *User) syncHandleEvent(event any) {
case *events.PhoneNotResponding: case *events.PhoneNotResponding:
user.phoneResponding = false user.phoneResponding = false
user.BridgeState.Send(status.BridgeState{StateEvent: status.StateConnected}) user.BridgeState.Send(status.BridgeState{StateEvent: status.StateConnected})
// TODO make this properly configurable
if user.zlog.Trace().Enabled() && !user.phoneNotRespondingAlertSent {
go user.sendMarkdownBridgeAlert(false, "Phone is not responding")
user.phoneNotRespondingAlertSent = true
}
case *events.PhoneRespondingAgain: case *events.PhoneRespondingAgain:
user.phoneResponding = true user.phoneResponding = true
user.BridgeState.Send(status.BridgeState{StateEvent: status.StateConnected}) user.BridgeState.Send(status.BridgeState{StateEvent: status.StateConnected})
if user.phoneNotRespondingAlertSent {
go user.sendMarkdownBridgeAlert(false, "Phone is responding again")
user.phoneNotRespondingAlertSent = false
}
case *events.PingFailed: case *events.PingFailed:
if errors.Is(v.Error, events.ErrRequestedEntityNotFound) { if errors.Is(v.Error, events.ErrRequestedEntityNotFound) {
go user.Logout(status.BridgeState{ go user.Logout(status.BridgeState{