From 51c68f4919e16ff303040d3e8c327df0baf235a2 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 4 Sep 2023 14:40:33 +0300 Subject: [PATCH] Send bad credentials state if default sms app flag is false --- bridgestate.go | 2 ++ database/user.go | 1 + user.go | 8 +++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bridgestate.go b/bridgestate.go index ca1d9af..b4f282d 100644 --- a/bridgestate.go +++ b/bridgestate.go @@ -32,6 +32,7 @@ const ( GMConnecting status.BridgeStateErrorCode = "gm-connecting" GMConnectionFailed status.BridgeStateErrorCode = "gm-connection-failed" GMPingFailed status.BridgeStateErrorCode = "gm-ping-failed" + GMNotDefaultSMSApp status.BridgeStateErrorCode = "gm-not-default-sms-app" GMBrowserInactive status.BridgeStateErrorCode = "gm-browser-inactive" GMBrowserInactiveTimeout status.BridgeStateErrorCode = "gm-browser-inactive-timeout" @@ -46,6 +47,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", + 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", GMBrowserInactiveInactivity: "Google Messages disconnected due to inactivity", diff --git a/database/user.go b/database/user.go index 4a27a44..913c095 100644 --- a/database/user.go +++ b/database/user.go @@ -63,6 +63,7 @@ func (uq *UserQuery) GetByMXID(ctx context.Context, userID id.UserID) (*User, er } type Settings struct { + SettingsReceived bool `json:"settings_received"` RCSEnabled bool `json:"rcs_enabled"` ReadReceipts bool `json:"read_receipts"` TypingNotifications bool `json:"typing_notifications"` diff --git a/user.go b/user.go index d82d5b6..31aaac7 100644 --- a/user.go +++ b/user.go @@ -773,8 +773,10 @@ func (user *User) handleSettings(settings *gmproto.Settings) { if user.Settings.RCSEnabled != newRCSSettings.GetIsEnabled() || user.Settings.ReadReceipts != newRCSSettings.GetSendReadReceipts() || user.Settings.TypingNotifications != newRCSSettings.GetShowTypingIndicators() || - user.Settings.IsDefaultSMSApp != newRCSSettings.GetIsDefaultSMSApp() { + user.Settings.IsDefaultSMSApp != newRCSSettings.GetIsDefaultSMSApp() || + !user.Settings.SettingsReceived { user.Settings = database.Settings{ + SettingsReceived: true, RCSEnabled: newRCSSettings.GetIsEnabled(), ReadReceipts: newRCSSettings.GetSendReadReceipts(), TypingNotifications: newRCSSettings.GetShowTypingIndicators(), @@ -801,6 +803,10 @@ func (user *User) FillBridgeState(state status.BridgeState) status.BridgeState { state.Info["battery_low"] = user.batteryLow state.Info["mobile_data"] = user.mobileData state.Info["browser_active"] = user.browserInactiveType == "" + if user.Settings.SettingsReceived && !user.Settings.IsDefaultSMSApp { + state.StateEvent = status.StateBadCredentials + state.Error = GMNotDefaultSMSApp + } if !user.ready { state.StateEvent = status.StateConnecting state.Error = GMConnecting