Ping again if stream goes to sleep soon after connection

This commit is contained in:
Tulir Asokan
2020-09-17 18:48:37 +03:00
parent 01101c1272
commit 4b3c411f2f
2 changed files with 31 additions and 6 deletions

17
user.go
View File

@@ -62,6 +62,7 @@ type User struct {
cleanDisconnection bool
batteryWarningsSent int
lastReconnection int64
chatListReceived chan struct{}
syncPortalsDone chan struct{}
@@ -480,6 +481,7 @@ func (user *User) postConnPing() bool {
func (user *User) intPostLogin() {
defer user.syncWait.Done()
user.lastReconnection = time.Now().Unix()
user.createCommunity()
user.tryAutomaticDoublePuppeting()
@@ -502,6 +504,21 @@ func (user *User) intPostLogin() {
}
}
func (user *User) HandleStreamEvent(evt whatsappExt.StreamEvent) {
if evt.Type == whatsappExt.StreamSleep {
if user.lastReconnection+60 > time.Now().Unix() {
user.lastReconnection = 0
user.log.Infoln("Stream went to sleep soon after reconnection, making new post-connection ping in 20 seconds")
go func() {
time.Sleep(20 * time.Second)
user.postConnPing()
}()
}
} else {
user.log.Infofln("Stream event: %+v", evt)
}
}
func (user *User) HandleChatList(chats []whatsapp.Chat) {
user.log.Infoln("Chat list received")
chatMap := make(map[string]whatsapp.Chat)