Send bad credentials state if default sms app flag is false

This commit is contained in:
Tulir Asokan 2023-09-04 14:40:33 +03:00
parent a4bb7e69cf
commit 51c68f4919
3 changed files with 10 additions and 1 deletions

View file

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

View file

@ -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"`

View file

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