public static IDisposable BindAuthentication( this MainWindowModel model, IAuthenticator authenticator) { var disposable = new CompositeDisposable(); var stateUpdates = authenticator .ObserveState() .SubscribeOn(RxApp.TaskpoolScheduler) .ObserveOn(RxApp.MainThreadScheduler); stateUpdates.OfType <TdApi.AuthorizationState.AuthorizationStateWaitTdlibParameters>() .SelectMany(_ => authenticator.SetupParameters()) .Accept() .DisposeWith(disposable); stateUpdates.OfType <TdApi.AuthorizationState.AuthorizationStateWaitEncryptionKey>() .SelectMany(_ => authenticator.CheckEncryptionKey()) .Accept() .DisposeWith(disposable); stateUpdates .Accept(state => HandleState(model, state)) .DisposeWith(disposable); return(disposable); }
private IDisposable BindAuthenticator(IAuthenticator authenticator) { return(authenticator .ObserveState() .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(state => { switch (state) { case TdApi.AuthorizationState.AuthorizationStateWaitTdlibParameters _: GoToStartupPage(); authenticator.SetupParameters() .Subscribe() .DisposeWith(this); break; case TdApi.AuthorizationState.AuthorizationStateWaitEncryptionKey _: GoToStartupPage(); authenticator.CheckEncryptionKey() .Subscribe() .DisposeWith(this); break; case TdApi.AuthorizationState.AuthorizationStateWaitPhoneNumber _: case TdApi.AuthorizationState.AuthorizationStateWaitCode _: case TdApi.AuthorizationState.AuthorizationStateWaitPassword _: GoToAuthenticationPage(); break; case TdApi.AuthorizationState.AuthorizationStateReady _: GoToWorkspacePage(); break; } })); }