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"
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",

View file

@ -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().

View file

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

View file

@ -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())