77using System . Threading . Tasks ;
88using CodeHub . Core . Factories ;
99using Cirrious . CrossCore ;
10+ using CodeFramework . Core . Services ;
11+ using System . Linq ;
1012
1113namespace CodeHub . Core . ViewModels . Accounts
1214{
@@ -16,6 +18,7 @@ public class LoginViewModel : BaseViewModel
1618 public const string ClientSecret = "9253ab615f8c00738fff5d1c665ca81e581875cb" ;
1719 public static readonly string RedirectUri = "http://dillonbuchanan.com/" ;
1820 private readonly ILoginFactory _loginFactory ;
21+ private readonly IFeaturesService _featuresService ;
1922
2023 private bool _isLoggingIn ;
2124 public bool IsLoggingIn
@@ -57,9 +60,10 @@ public ICommand GoBackCommand
5760 get { return new MvxCommand ( ( ) => ChangePresentation ( new MvxClosePresentationHint ( this ) ) ) ; }
5861 }
5962
60- public LoginViewModel ( ILoginFactory loginFactory )
63+ public LoginViewModel ( ILoginFactory loginFactory , IFeaturesService featuresService )
6164 {
6265 _loginFactory = loginFactory ;
66+ _featuresService = featuresService ;
6367 }
6468
6569 public void Init ( NavObject navObject )
@@ -112,12 +116,25 @@ public async Task Login(string code)
112116 }
113117
114118 LoginData loginData = null ;
119+ bool shouldPromptPush = false ;
115120
116121 try
117122 {
118123 IsLoggingIn = true ;
119124 var account = AttemptedAccount ;
120125 loginData = await _loginFactory . LoginWithToken ( ClientId , ClientSecret , code , RedirectUri , WebDomain , apiUrl , account ) ;
126+
127+ if ( ! _featuresService . IsPushNotificationsActivated && ! IsEnterprise )
128+ {
129+ try
130+ {
131+ var ids = await _featuresService . GetAvailableFeatureIds ( ) ;
132+ shouldPromptPush = ids . Contains ( FeatureIds . PushNotifications ) ;
133+ }
134+ catch
135+ {
136+ }
137+ }
121138 }
122139 catch ( Exception e )
123140 {
@@ -131,16 +148,11 @@ public async Task Login(string code)
131148
132149 try
133150 {
134- if ( ! IsEnterprise )
135- {
136- var features = Mvx . Resolve < IFeaturesService > ( ) ;
137- if ( ! features . IsPushNotificationsActivated )
138- {
139- await Mvx . Resolve < IFeatureFactory > ( ) . PromptPushNotificationFeature ( ) ;
140- }
141- }
151+ // Only prompt if we're allowing that to be enabled.
152+ if ( shouldPromptPush )
153+ await Mvx . Resolve < IFeatureFactory > ( ) . PromptPushNotificationFeature ( ) ;
142154 }
143- catch
155+ catch
144156 {
145157 // Don't do anything...
146158 }
0 commit comments