Don't resync if session ID doesn't change
This commit is contained in:
parent
20599e93f3
commit
b958401b73
2 changed files with 20 additions and 3 deletions
|
@ -93,6 +93,10 @@ func NewClient(authData *AuthData, logger zerolog.Logger) *Client {
|
||||||
return cli
|
return cli
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) CurrentSessionID() string {
|
||||||
|
return c.sessionHandler.sessionID
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) SetEventHandler(eventHandler EventHandler) {
|
func (c *Client) SetEventHandler(eventHandler EventHandler) {
|
||||||
c.evHandler = eventHandler
|
c.evHandler = eventHandler
|
||||||
}
|
}
|
||||||
|
|
15
user.go
15
user.go
|
@ -74,6 +74,7 @@ type User struct {
|
||||||
mobileData bool
|
mobileData bool
|
||||||
phoneResponding bool
|
phoneResponding bool
|
||||||
ready bool
|
ready bool
|
||||||
|
sessionID string
|
||||||
batteryLowAlertSent time.Time
|
batteryLowAlertSent time.Time
|
||||||
pollErrorAlertSent bool
|
pollErrorAlertSent bool
|
||||||
|
|
||||||
|
@ -704,12 +705,24 @@ func (user *User) handleUserAlert(v *gmproto.UserAlertEvent) {
|
||||||
user.browserInactiveType = GMBrowserInactive
|
user.browserInactiveType = GMBrowserInactive
|
||||||
becameInactive = true
|
becameInactive = true
|
||||||
case gmproto.AlertType_BROWSER_ACTIVE:
|
case gmproto.AlertType_BROWSER_ACTIVE:
|
||||||
// TODO check if session ID changed?
|
wasInactive := user.browserInactiveType != "" || !user.ready
|
||||||
user.pollErrorAlertSent = false
|
user.pollErrorAlertSent = false
|
||||||
user.browserInactiveType = ""
|
user.browserInactiveType = ""
|
||||||
user.ready = true
|
user.ready = true
|
||||||
|
newSessionID := user.Client.CurrentSessionID()
|
||||||
|
if user.sessionID != newSessionID || wasInactive {
|
||||||
|
user.zlog.Debug().
|
||||||
|
Str("old_session_id", user.sessionID).
|
||||||
|
Str("new_session_id", newSessionID).
|
||||||
|
Msg("Session ID changed for browser active event, resyncing")
|
||||||
|
user.sessionID = newSessionID
|
||||||
go user.fetchAndSyncConversations()
|
go user.fetchAndSyncConversations()
|
||||||
user.sendMarkdownBridgeAlert(false, "Connected to Google Messages")
|
user.sendMarkdownBridgeAlert(false, "Connected to Google Messages")
|
||||||
|
} else {
|
||||||
|
user.zlog.Debug().
|
||||||
|
Str("session_id", user.sessionID).
|
||||||
|
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:
|
||||||
user.browserInactiveType = GMBrowserInactiveTimeout
|
user.browserInactiveType = GMBrowserInactiveTimeout
|
||||||
becameInactive = true
|
becameInactive = true
|
||||||
|
|
Loading…
Reference in a new issue