forked from MirrorHub/mautrix-whatsapp
Maybe improve connecting errors
This commit is contained in:
parent
2381eb029b
commit
97e740d93d
1 changed files with 5 additions and 5 deletions
10
user.go
10
user.go
|
@ -161,14 +161,15 @@ func (user *User) Connect(evenIfNoSession bool) bool {
|
||||||
_ = user.Conn.SetClientName("Mautrix-WhatsApp bridge", "mx-wa")
|
_ = user.Conn.SetClientName("Mautrix-WhatsApp bridge", "mx-wa")
|
||||||
user.log.Debugln("WhatsApp connection successful")
|
user.log.Debugln("WhatsApp connection successful")
|
||||||
user.Conn.AddHandler(user)
|
user.Conn.AddHandler(user)
|
||||||
user.RestoreSession()
|
return user.RestoreSession()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) RestoreSession() bool {
|
func (user *User) RestoreSession() bool {
|
||||||
if user.Session != nil {
|
if user.Session != nil {
|
||||||
sess, err := user.Conn.RestoreWithSession(*user.Session)
|
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)
|
user.log.Errorln("Failed to restore session:", err)
|
||||||
msg := format.RenderMarkdown(fmt.Sprintf("\u26a0 Failed to connect to WhatsApp. Make sure WhatsApp "+
|
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.",
|
"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.Connected = true
|
||||||
user.SetSession(&sess)
|
user.SetSession(&sess)
|
||||||
user.log.Debugln("Session restored successfully")
|
user.log.Debugln("Session restored successfully")
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
return false
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) IsLoggedIn() bool {
|
func (user *User) IsLoggedIn() bool {
|
||||||
|
|
Loading…
Reference in a new issue