Bläddra i källkod

Add error code for normal transient disconnects

Tulir Asokan 2 år sedan
förälder
incheckning
0723d60205
2 ändrade filer med 3 tillägg och 1 borttagningar
  1. 2 0
      bridgestate.go
  2. 1 1
      user.go

+ 2 - 0
bridgestate.go

@@ -33,6 +33,7 @@ const (
 	WAKeepaliveTimeout status.BridgeStateErrorCode = "wa-keepalive-timeout"
 	WAPhoneOffline     status.BridgeStateErrorCode = "wa-phone-offline"
 	WAConnectionFailed status.BridgeStateErrorCode = "wa-connection-failed"
+	WADisconnected     status.BridgeStateErrorCode = "wa-transient-disconnect"
 )
 
 func init() {
@@ -45,6 +46,7 @@ func init() {
 		WAKeepaliveTimeout: "The WhatsApp web servers are not responding. The bridge will try to reconnect.",
 		WAPhoneOffline:     "Your phone hasn't been seen in over 12 days. The bridge is currently connected, but will get disconnected if you don't open the app soon.",
 		WAConnectionFailed: "Connecting to the WhatsApp web servers failed.",
+		WADisconnected:     "Disconnected from WhatsApp. Trying to reconnect.",
 	})
 }
 

+ 1 - 1
user.go

@@ -841,7 +841,7 @@ func (user *User) HandleEvent(event interface{}) {
 		// Don't send the normal transient disconnect state if we're already in a different transient disconnect state.
 		// TODO remove this if/when the phone offline state is moved to a sub-state of CONNECTED
 		if user.BridgeState.GetPrev().Error != WAPhoneOffline && user.PhoneRecentlySeen(false) {
-			go user.BridgeState.Send(status.BridgeState{StateEvent: status.StateTransientDisconnect, Message: "Disconnected from WhatsApp. Trying to reconnect."})
+			go user.BridgeState.Send(status.BridgeState{StateEvent: status.StateTransientDisconnect, Error: WADisconnected})
 		}
 		user.bridge.Metrics.TrackConnectionState(user.JID, false)
 	case *events.Contact: