From b1344538013d735a50ef9168208cb2cd60735f19 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 23 Feb 2024 20:25:31 +0200 Subject: [PATCH] Handle logout events in a hacky way --- bridgestate.go | 2 ++ libgm/event_handler.go | 7 +++++++ libgm/events/ready.go | 2 ++ user.go | 7 +++++++ 4 files changed, 18 insertions(+) diff --git a/bridgestate.go b/bridgestate.go index 3243221..c76a2f2 100644 --- a/bridgestate.go +++ b/bridgestate.go @@ -27,6 +27,7 @@ const ( GMListenError status.BridgeStateErrorCode = "gm-listen-error" GMFatalError status.BridgeStateErrorCode = "gm-listen-fatal-error" GMUnpaired status.BridgeStateErrorCode = "gm-unpaired" + GMUnpairedGaia status.BridgeStateErrorCode = "gm-unpaired-gaia" GMUnpaired404 status.BridgeStateErrorCode = "gm-unpaired-entity-not-found" GMNotConnected status.BridgeStateErrorCode = "gm-not-connected" GMConnecting status.BridgeStateErrorCode = "gm-connecting" @@ -49,6 +50,7 @@ func init() { GMFatalError: "Fatal error polling messages from Google Messages server, please re-link the bridge", GMUnpaired: "Unpaired from Google Messages, please re-link the connection to continue using SMS/RCS", GMUnpaired404: "Unpaired from Google Messages, please re-link the connection to continue using SMS/RCS", + GMUnpairedGaia: "Unpaired from Google Messages, please re-link the connection to continue using SMS/RCS", GMNotDefaultSMSApp: "Google Messages isn't set as the default SMS app. Please set the default SMS app on your Android phone to Google Messages to continue using SMS/RCS.", GMBrowserInactive: "Google Messages opened in another browser", GMBrowserInactiveTimeout: "Google Messages disconnected due to timeout", diff --git a/libgm/event_handler.go b/libgm/event_handler.go index 61711ea..714ae38 100644 --- a/libgm/event_handler.go +++ b/libgm/event_handler.go @@ -1,6 +1,7 @@ package libgm import ( + "bytes" "crypto/sha256" "encoding/base64" "fmt" @@ -203,9 +204,15 @@ type WrappedMessage struct { Data []byte } +var hackyLoggedOutBytes = []byte{0x72, 0x00} + func (c *Client) handleUpdatesEvent(msg *IncomingRPCMessage) { switch msg.Message.Action { case gmproto.ActionType_GET_UPDATES: + if msg.DecryptedData == nil && bytes.Equal(msg.Message.UnencryptedData, hackyLoggedOutBytes) { + c.triggerEvent(&events.GaiaLoggedOut{}) + return + } data, ok := msg.DecryptedMessage.(*gmproto.UpdateEvents) if !ok { c.Logger.Error(). diff --git a/libgm/events/ready.go b/libgm/events/ready.go index 67a1c7c..0f7cb77 100644 --- a/libgm/events/ready.go +++ b/libgm/events/ready.go @@ -15,6 +15,8 @@ type ClientReady struct { type AuthTokenRefreshed struct{} +type GaiaLoggedOut struct{} + type AccountChange struct { *gmproto.AccountChangeOrSomethingEvent IsFake bool diff --git a/user.go b/user.go index 5535ee7..728e595 100644 --- a/user.go +++ b/user.go @@ -711,6 +711,13 @@ func (user *User) syncHandleEvent(event any) { Error: GMUnpaired, }, false) go user.sendMarkdownBridgeAlert(true, "Unpaired from Google Messages. Log in again to continue using the bridge.") + case *events.GaiaLoggedOut: + user.zlog.Info().Msg("Got gaia logout event") + go user.Logout(status.BridgeState{ + StateEvent: status.StateBadCredentials, + Error: GMUnpaired, + }, false) + go user.sendMarkdownBridgeAlert(true, "Unpaired from Google Messages. Log in again to continue using the bridge.") case *events.AuthTokenRefreshed: go func() { err := user.Update(context.TODO())