Resync if hacky GET_UPDATES works
This commit is contained in:
parent
135bd5f5bb
commit
0b6648eeed
3 changed files with 27 additions and 2 deletions
|
@ -17,6 +17,8 @@ type AuthTokenRefreshed struct{}
|
||||||
|
|
||||||
type GaiaLoggedOut struct{}
|
type GaiaLoggedOut struct{}
|
||||||
|
|
||||||
|
type NoDataReceived struct{}
|
||||||
|
|
||||||
type AccountChange struct {
|
type AccountChange struct {
|
||||||
*gmproto.AccountChangeOrSomethingEvent
|
*gmproto.AccountChangeOrSomethingEvent
|
||||||
IsFake bool
|
IsFake bool
|
||||||
|
|
|
@ -206,7 +206,8 @@ func (dp *dittoPinger) Loop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dp *dittoPinger) HandleNoRecentUpdates() {
|
func (dp *dittoPinger) HandleNoRecentUpdates() {
|
||||||
dp.log.Debug().Msg("No data received recently, sending extra GET_UPDATES call")
|
dp.client.triggerEvent(&events.NoDataReceived{})
|
||||||
|
dp.log.Warn().Msg("No data received recently, sending extra GET_UPDATES call")
|
||||||
err := dp.client.sessionHandler.sendMessageNoResponse(SendMessageParams{
|
err := dp.client.sessionHandler.sendMessageNoResponse(SendMessageParams{
|
||||||
Action: gmproto.ActionType_GET_UPDATES,
|
Action: gmproto.ActionType_GET_UPDATES,
|
||||||
OmitTTL: true,
|
OmitTTL: true,
|
||||||
|
|
24
user.go
24
user.go
|
@ -77,6 +77,8 @@ type User struct {
|
||||||
pollErrorAlertSent bool
|
pollErrorAlertSent bool
|
||||||
phoneNotRespondingAlertSent bool
|
phoneNotRespondingAlertSent bool
|
||||||
didHackySetActive bool
|
didHackySetActive bool
|
||||||
|
noDataReceivedRecently bool
|
||||||
|
lastNoDataResync time.Time
|
||||||
|
|
||||||
loginInProgress atomic.Bool
|
loginInProgress atomic.Bool
|
||||||
pairSuccessChan chan struct{}
|
pairSuccessChan chan struct{}
|
||||||
|
@ -644,6 +646,7 @@ func (user *User) DeleteSession() {
|
||||||
user.Session = nil
|
user.Session = nil
|
||||||
user.SelfParticipantIDs = []string{}
|
user.SelfParticipantIDs = []string{}
|
||||||
user.didHackySetActive = false
|
user.didHackySetActive = false
|
||||||
|
user.noDataReceivedRecently = false
|
||||||
err := user.Update(context.TODO())
|
err := user.Update(context.TODO())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
user.zlog.Err(err).Msg("Failed to delete session from database")
|
user.zlog.Err(err).Msg("Failed to delete session from database")
|
||||||
|
@ -678,6 +681,7 @@ func (user *User) hackyResetActive() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
user.didHackySetActive = true
|
user.didHackySetActive = true
|
||||||
|
user.noDataReceivedRecently = false
|
||||||
time.Sleep(7 * time.Second)
|
time.Sleep(7 * time.Second)
|
||||||
if !user.ready && user.phoneResponding {
|
if !user.ready && user.phoneResponding {
|
||||||
user.zlog.Warn().Msg("Client is still not ready, trying to re-set active session")
|
user.zlog.Warn().Msg("Client is still not ready, trying to re-set active session")
|
||||||
|
@ -798,9 +802,11 @@ func (user *User) syncHandleEvent(event any) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
case *gmproto.Conversation:
|
case *gmproto.Conversation:
|
||||||
|
user.noDataReceivedRecently = false
|
||||||
go user.syncConversation(v, "event")
|
go user.syncConversation(v, "event")
|
||||||
//case *gmproto.Message:
|
//case *gmproto.Message:
|
||||||
case *libgm.WrappedMessage:
|
case *libgm.WrappedMessage:
|
||||||
|
user.noDataReceivedRecently = false
|
||||||
user.zlog.Debug().
|
user.zlog.Debug().
|
||||||
Str("conversation_id", v.GetConversationID()).
|
Str("conversation_id", v.GetConversationID()).
|
||||||
Str("participant_id", v.GetParticipantID()).
|
Str("participant_id", v.GetParticipantID()).
|
||||||
|
@ -815,9 +821,12 @@ func (user *User) syncHandleEvent(event any) {
|
||||||
case *gmproto.UserAlertEvent:
|
case *gmproto.UserAlertEvent:
|
||||||
user.handleUserAlert(v)
|
user.handleUserAlert(v)
|
||||||
case *gmproto.Settings:
|
case *gmproto.Settings:
|
||||||
|
user.noDataReceivedRecently = false
|
||||||
user.handleSettings(v)
|
user.handleSettings(v)
|
||||||
case *events.AccountChange:
|
case *events.AccountChange:
|
||||||
user.handleAccountChange(v)
|
user.handleAccountChange(v)
|
||||||
|
case *events.NoDataReceived:
|
||||||
|
user.noDataReceivedRecently = true
|
||||||
default:
|
default:
|
||||||
user.zlog.Trace().Any("data", v).Type("data_type", v).Msg("Unknown event")
|
user.zlog.Trace().Any("data", v).Type("data_type", v).Msg("Unknown event")
|
||||||
}
|
}
|
||||||
|
@ -903,6 +912,8 @@ func (user *User) handleUserAlert(v *gmproto.UserAlertEvent) {
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
user.zlog.Debug().Str("alert_type", v.GetAlertType().String()).Msg("Got user alert event")
|
user.zlog.Debug().Str("alert_type", v.GetAlertType().String()).Msg("Got user alert event")
|
||||||
becameInactive := false
|
becameInactive := false
|
||||||
|
hadNoDataReceived := user.noDataReceivedRecently
|
||||||
|
user.noDataReceivedRecently = false
|
||||||
switch v.GetAlertType() {
|
switch v.GetAlertType() {
|
||||||
case gmproto.AlertType_BROWSER_INACTIVE:
|
case gmproto.AlertType_BROWSER_INACTIVE:
|
||||||
user.browserInactiveType = GMBrowserInactive
|
user.browserInactiveType = GMBrowserInactive
|
||||||
|
@ -913,10 +924,19 @@ func (user *User) handleUserAlert(v *gmproto.UserAlertEvent) {
|
||||||
user.browserInactiveType = ""
|
user.browserInactiveType = ""
|
||||||
user.ready = true
|
user.ready = true
|
||||||
newSessionID := user.Client.CurrentSessionID()
|
newSessionID := user.Client.CurrentSessionID()
|
||||||
if user.sessionID != newSessionID || wasInactive {
|
if hadNoDataReceived && time.Since(user.lastNoDataResync) < 5*time.Hour {
|
||||||
|
user.zlog.Warn().Time("last_resync", user.lastNoDataResync).Msg("Frequent no data received resyncs")
|
||||||
|
hadNoDataReceived = false
|
||||||
|
}
|
||||||
|
if user.sessionID != newSessionID || wasInactive || hadNoDataReceived {
|
||||||
|
if hadNoDataReceived {
|
||||||
|
user.lastNoDataResync = time.Now()
|
||||||
|
}
|
||||||
user.zlog.Debug().
|
user.zlog.Debug().
|
||||||
Str("old_session_id", user.sessionID).
|
Str("old_session_id", user.sessionID).
|
||||||
Str("new_session_id", newSessionID).
|
Str("new_session_id", newSessionID).
|
||||||
|
Bool("was_inactive", wasInactive).
|
||||||
|
Bool("had_no_data_received", hadNoDataReceived).
|
||||||
Msg("Session ID changed for browser active event, resyncing")
|
Msg("Session ID changed for browser active event, resyncing")
|
||||||
user.sessionID = newSessionID
|
user.sessionID = newSessionID
|
||||||
go user.fetchAndSyncConversations()
|
go user.fetchAndSyncConversations()
|
||||||
|
@ -924,6 +944,8 @@ func (user *User) handleUserAlert(v *gmproto.UserAlertEvent) {
|
||||||
} else {
|
} else {
|
||||||
user.zlog.Debug().
|
user.zlog.Debug().
|
||||||
Str("session_id", user.sessionID).
|
Str("session_id", user.sessionID).
|
||||||
|
Bool("was_inactive", wasInactive).
|
||||||
|
Bool("had_no_data_received", hadNoDataReceived).
|
||||||
Msg("Session ID didn't change for browser active event, not resyncing")
|
Msg("Session ID didn't change for browser active event, not resyncing")
|
||||||
}
|
}
|
||||||
case gmproto.AlertType_BROWSER_INACTIVE_FROM_TIMEOUT:
|
case gmproto.AlertType_BROWSER_INACTIVE_FROM_TIMEOUT:
|
||||||
|
|
Loading…
Reference in a new issue