From 73241b6f2195f4fb20563133b0b8beed1da311cd Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 15 Mar 2022 16:04:10 +0200 Subject: [PATCH] Add proper bridge state errors for different logout types --- bridgestate.go | 4 ++++ user.go | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/bridgestate.go b/bridgestate.go index 9b2f444..0ba1365 100644 --- a/bridgestate.go +++ b/bridgestate.go @@ -48,6 +48,8 @@ type BridgeErrorCode string const ( WALoggedOut BridgeErrorCode = "wa-logged-out" + WAAccountBanned BridgeErrorCode = "wa-account-banned" + WAUnknownLogout BridgeErrorCode = "wa-unknown-logout" WANotConnected BridgeErrorCode = "wa-not-connected" WAConnecting BridgeErrorCode = "wa-connecting" WAServerTimeout BridgeErrorCode = "wa-server-timeout" @@ -56,6 +58,8 @@ const ( var bridgeHumanErrors = map[BridgeErrorCode]string{ WALoggedOut: "You were logged out from another device. Relogin to continue using the bridge.", + WAAccountBanned: "Your account was banned from WhatsApp. You can contact support from the WhatsApp mobile app on your phone.", + WAUnknownLogout: "You were logged out for an unknown reason. Relogin to continue using the bridge.", WANotConnected: "You're not connected to WhatsApp", WAConnecting: "Reconnecting to WhatsApp...", WAServerTimeout: "The WhatsApp web servers are not responding. The bridge will try to reconnect.", diff --git a/user.go b/user.go index 01a323e..7b08a9a 100644 --- a/user.go +++ b/user.go @@ -875,7 +875,13 @@ func (user *User) UpdateDirectChats(chats map[id.UserID][]id.RoomID) { } func (user *User) handleLoggedOut(onConnect bool, reason events.ConnectFailureReason) { - user.removeFromJIDMap(BridgeState{StateEvent: StateBadCredentials, Error: WALoggedOut, Message: reason.String()}) + errorCode := WAUnknownLogout + if reason == events.ConnectFailureLoggedOut { + errorCode = WALoggedOut + } else if reason == events.ConnectFailureBanned { + errorCode = WAAccountBanned + } + user.removeFromJIDMap(BridgeState{StateEvent: StateBadCredentials, Error: errorCode}) user.DeleteConnection() user.Session = nil user.JID = types.EmptyJID