From 97e740d93d9dce9ae0979b86b50440112045d6b9 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 16 May 2019 18:24:54 +0300 Subject: [PATCH] Maybe improve connecting errors --- user.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/user.go b/user.go index 52d0ece..01e7891 100644 --- a/user.go +++ b/user.go @@ -161,14 +161,15 @@ func (user *User) Connect(evenIfNoSession bool) bool { _ = user.Conn.SetClientName("Mautrix-WhatsApp bridge", "mx-wa") user.log.Debugln("WhatsApp connection successful") user.Conn.AddHandler(user) - user.RestoreSession() - return true + return user.RestoreSession() } func (user *User) RestoreSession() bool { if user.Session != nil { sess, err := user.Conn.RestoreWithSession(*user.Session) - if err != nil { + if err == whatsapp.ErrAlreadyLoggedIn { + return true + } else if err != nil { user.log.Errorln("Failed to restore session:", err) msg := format.RenderMarkdown(fmt.Sprintf("\u26a0 Failed to connect to WhatsApp. Make sure WhatsApp "+ "on your phone is reachable and use `%s reconnect` to try connecting again.", @@ -179,9 +180,8 @@ func (user *User) RestoreSession() bool { user.Connected = true user.SetSession(&sess) user.log.Debugln("Session restored successfully") - return true } - return false + return true } func (user *User) IsLoggedIn() bool {