Adjust hacky GET_UPDATES behavior
This commit is contained in:
parent
7167eff883
commit
e2c8d92382
2 changed files with 23 additions and 19 deletions
|
@ -183,7 +183,7 @@ func (dp *dittoPinger) Ping(pingID uint64, timeout time.Duration, timeoutCount i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const DefaultBugleDefaultCheckInterval = 1*time.Hour + 55*time.Minute
|
const DefaultBugleDefaultCheckInterval = 2*time.Hour + 55*time.Minute
|
||||||
|
|
||||||
func (dp *dittoPinger) Loop() {
|
func (dp *dittoPinger) Loop() {
|
||||||
for {
|
for {
|
||||||
|
|
40
user.go
40
user.go
|
@ -78,7 +78,6 @@ type User struct {
|
||||||
phoneNotRespondingAlertSent bool
|
phoneNotRespondingAlertSent bool
|
||||||
didHackySetActive bool
|
didHackySetActive bool
|
||||||
noDataReceivedRecentlyStart time.Time
|
noDataReceivedRecentlyStart time.Time
|
||||||
lastNoDataResync time.Time
|
|
||||||
|
|
||||||
loginInProgress atomic.Bool
|
loginInProgress atomic.Bool
|
||||||
pairSuccessChan chan struct{}
|
pairSuccessChan chan struct{}
|
||||||
|
@ -875,7 +874,7 @@ func (user *User) aggressiveSetActive() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) fetchAndSyncConversations(noDataReceivedStart time.Time) {
|
func (user *User) fetchAndSyncConversations(noDataReceivedStart time.Time, minimalSync bool) {
|
||||||
user.zlog.Info().Msg("Fetching conversation list")
|
user.zlog.Info().Msg("Fetching conversation list")
|
||||||
resp, err := user.Client.ListConversations(user.bridge.Config.Bridge.InitialChatSyncCount, gmproto.ListConversationsRequest_INBOX)
|
resp, err := user.Client.ListConversations(user.bridge.Config.Bridge.InitialChatSyncCount, gmproto.ListConversationsRequest_INBOX)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -883,14 +882,25 @@ func (user *User) fetchAndSyncConversations(noDataReceivedStart time.Time) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
user.zlog.Info().Int("count", len(resp.GetConversations())).Msg("Syncing conversations")
|
user.zlog.Info().Int("count", len(resp.GetConversations())).Msg("Syncing conversations")
|
||||||
for _, conv := range resp.GetConversations() {
|
if !noDataReceivedStart.IsZero() {
|
||||||
lastMessageTS := time.UnixMicro(conv.GetLastMessageTimestamp())
|
for _, conv := range resp.GetConversations() {
|
||||||
if !noDataReceivedStart.IsZero() && lastMessageTS.After(noDataReceivedStart) {
|
lastMessageTS := time.UnixMicro(conv.GetLastMessageTimestamp())
|
||||||
user.zlog.Warn().
|
if lastMessageTS.After(noDataReceivedStart) {
|
||||||
Time("last_message_ts", lastMessageTS).
|
user.zlog.Warn().
|
||||||
Time("no_data_received_start", noDataReceivedStart).
|
Time("last_message_ts", lastMessageTS).
|
||||||
Msg("Conversation's last message is newer than no data received start time")
|
Time("no_data_received_start", noDataReceivedStart).
|
||||||
|
Msg("Conversation's last message is newer than no data received start time")
|
||||||
|
minimalSync = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else if minimalSync {
|
||||||
|
user.zlog.Warn().Msg("Minimal sync called without no data received start time")
|
||||||
|
}
|
||||||
|
if minimalSync {
|
||||||
|
user.zlog.Debug().Msg("Minimal sync with no recent messages, not syncing conversations")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, conv := range resp.GetConversations() {
|
||||||
user.syncConversation(conv, "sync")
|
user.syncConversation(conv, "sync")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -932,14 +942,8 @@ 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 hadNoDataReceived && time.Since(user.lastNoDataResync) < 5*time.Hour {
|
sessionIDChanged := user.sessionID != newSessionID
|
||||||
user.zlog.Warn().Time("last_resync", user.lastNoDataResync).Msg("Frequent no data received resyncs")
|
if sessionIDChanged || wasInactive || hadNoDataReceived {
|
||||||
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).
|
||||||
|
@ -948,7 +952,7 @@ func (user *User) handleUserAlert(v *gmproto.UserAlertEvent) {
|
||||||
Time("no_data_received_start", noDataReceivedStart).
|
Time("no_data_received_start", noDataReceivedStart).
|
||||||
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(noDataReceivedStart)
|
go user.fetchAndSyncConversations(noDataReceivedStart, !sessionIDChanged && !wasInactive)
|
||||||
go user.sendMarkdownBridgeAlert(ctx, false, "Connected to Google Messages")
|
go user.sendMarkdownBridgeAlert(ctx, false, "Connected to Google Messages")
|
||||||
} else {
|
} else {
|
||||||
user.zlog.Debug().
|
user.zlog.Debug().
|
||||||
|
|
Loading…
Reference in a new issue