Handle logout events in a hacky way

This commit is contained in:
Tulir Asokan 2024-02-23 20:25:31 +02:00
parent f99201f8e6
commit b134453801
4 changed files with 18 additions and 0 deletions

View file

@ -27,6 +27,7 @@ const (
GMListenError status.BridgeStateErrorCode = "gm-listen-error" GMListenError status.BridgeStateErrorCode = "gm-listen-error"
GMFatalError status.BridgeStateErrorCode = "gm-listen-fatal-error" GMFatalError status.BridgeStateErrorCode = "gm-listen-fatal-error"
GMUnpaired status.BridgeStateErrorCode = "gm-unpaired" GMUnpaired status.BridgeStateErrorCode = "gm-unpaired"
GMUnpairedGaia status.BridgeStateErrorCode = "gm-unpaired-gaia"
GMUnpaired404 status.BridgeStateErrorCode = "gm-unpaired-entity-not-found" GMUnpaired404 status.BridgeStateErrorCode = "gm-unpaired-entity-not-found"
GMNotConnected status.BridgeStateErrorCode = "gm-not-connected" GMNotConnected status.BridgeStateErrorCode = "gm-not-connected"
GMConnecting status.BridgeStateErrorCode = "gm-connecting" 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", 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", 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", 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.", 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", GMBrowserInactive: "Google Messages opened in another browser",
GMBrowserInactiveTimeout: "Google Messages disconnected due to timeout", GMBrowserInactiveTimeout: "Google Messages disconnected due to timeout",

View file

@ -1,6 +1,7 @@
package libgm package libgm
import ( import (
"bytes"
"crypto/sha256" "crypto/sha256"
"encoding/base64" "encoding/base64"
"fmt" "fmt"
@ -203,9 +204,15 @@ type WrappedMessage struct {
Data []byte Data []byte
} }
var hackyLoggedOutBytes = []byte{0x72, 0x00}
func (c *Client) handleUpdatesEvent(msg *IncomingRPCMessage) { func (c *Client) handleUpdatesEvent(msg *IncomingRPCMessage) {
switch msg.Message.Action { switch msg.Message.Action {
case gmproto.ActionType_GET_UPDATES: 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) data, ok := msg.DecryptedMessage.(*gmproto.UpdateEvents)
if !ok { if !ok {
c.Logger.Error(). c.Logger.Error().

View file

@ -15,6 +15,8 @@ type ClientReady struct {
type AuthTokenRefreshed struct{} type AuthTokenRefreshed struct{}
type GaiaLoggedOut struct{}
type AccountChange struct { type AccountChange struct {
*gmproto.AccountChangeOrSomethingEvent *gmproto.AccountChangeOrSomethingEvent
IsFake bool IsFake bool

View file

@ -711,6 +711,13 @@ func (user *User) syncHandleEvent(event any) {
Error: GMUnpaired, Error: GMUnpaired,
}, false) }, false)
go user.sendMarkdownBridgeAlert(true, "Unpaired from Google Messages. Log in again to continue using the bridge.") 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: case *events.AuthTokenRefreshed:
go func() { go func() {
err := user.Update(context.TODO()) err := user.Update(context.TODO())