Move some code around (#540)

and remove an obsolete property
This commit is contained in:
Nathan Mattes 2022-11-11 18:44:01 +01:00
parent 38317d8fa6
commit 08302cf2fa
4 changed files with 50 additions and 67 deletions

View File

@ -56,6 +56,52 @@ class MastodonLoginViewController: UIViewController {
@objc func nextButtonPressed(_ sender: Any) {
delegate?.nextButtonPressed(self)
}
@objc func login(_ sender: Any) {
// guard let server = viewModel.selectedServer.value else { return }
// authenticationViewModel.isAuthenticating.send(true)
// context.apiService.createApplication(domain: server.domain)
// .tryMap { response -> AuthenticationViewModel.AuthenticateInfo in
// let application = response.value
// guard let info = AuthenticationViewModel.AuthenticateInfo(
// domain: server.domain,
// application: application,
// redirectURI: response.value.redirectURI ?? APIService.oauthCallbackURL
// ) else {
// throw APIService.APIError.explicit(.badResponse)
// }
// return info
// }
// .receive(on: DispatchQueue.main)
// .sink { [weak self] completion in
// guard let self = self else { return }
// self.authenticationViewModel.isAuthenticating.send(false)
//
// switch completion {
// case .failure(let error):
// os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: sign in fail: %s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription)
// self.viewModel.error.send(error)
// case .finished:
// break
// }
// } receiveValue: { [weak self] info in
// guard let self = self else { return }
// let authenticationController = MastodonAuthenticationController(
// context: self.context,
// authenticateURL: info.authorizeURL
// )
//
// self.mastodonAuthenticationController = authenticationController
// authenticationController.authenticationSession?.presentationContextProvider = self
// authenticationController.authenticationSession?.start()
//
// self.authenticationViewModel.authenticate(
// info: info,
// pinCodePublisher: authenticationController.pinCodePublisher
// )
// }
// .store(in: &disposeBag)
}
}
// MARK: - OnboardingViewControllerAppearance

View File

@ -270,60 +270,6 @@ extension MastodonPickServerViewController {
}
@objc private func nextButtonDidPressed(_ sender: UIButton) {
switch viewModel.mode {
case .signIn: doSignIn()
case .signUp: doSignUp()
}
}
//TODO: @zeitschlag Move to MastodonLoginViewController
private func doSignIn() {
guard let server = viewModel.selectedServer.value else { return }
authenticationViewModel.isAuthenticating.send(true)
context.apiService.createApplication(domain: server.domain)
.tryMap { response -> AuthenticationViewModel.AuthenticateInfo in
let application = response.value
guard let info = AuthenticationViewModel.AuthenticateInfo(
domain: server.domain,
application: application,
redirectURI: response.value.redirectURI ?? APIService.oauthCallbackURL
) else {
throw APIService.APIError.explicit(.badResponse)
}
return info
}
.receive(on: DispatchQueue.main)
.sink { [weak self] completion in
guard let self = self else { return }
self.authenticationViewModel.isAuthenticating.send(false)
switch completion {
case .failure(let error):
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: sign in fail: %s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription)
self.viewModel.error.send(error)
case .finished:
break
}
} receiveValue: { [weak self] info in
guard let self = self else { return }
let authenticationController = MastodonAuthenticationController(
context: self.context,
authenticateURL: info.authorizeURL
)
self.mastodonAuthenticationController = authenticationController
authenticationController.authenticationSession?.presentationContextProvider = self
authenticationController.authenticationSession?.start()
self.authenticationViewModel.authenticate(
info: info,
pinCodePublisher: authenticationController.pinCodePublisher
)
}
.store(in: &disposeBag)
}
private func doSignUp() {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
guard let server = viewModel.selectedServer.value else { return }
authenticationViewModel.isAuthenticating.send(true)

View File

@ -17,12 +17,7 @@ import MastodonCore
import MastodonUI
class MastodonPickServerViewModel: NSObject {
enum PickServerMode {
case signUp
case signIn
}
enum EmptyStateViewState {
case none
case loading
@ -34,7 +29,6 @@ class MastodonPickServerViewModel: NSObject {
let serverSectionHeaderView = PickServerServerSectionTableHeaderView()
// input
let mode: PickServerMode
let context: AppContext
var categoryPickerItems: [CategoryPickerItem] = {
var items: [CategoryPickerItem] = []
@ -72,9 +66,8 @@ class MastodonPickServerViewModel: NSObject {
let loadingIndexedServersError = CurrentValueSubject<Error?, Never>(nil)
let emptyStateViewState = CurrentValueSubject<EmptyStateViewState, Never>(.none)
init(context: AppContext, mode: PickServerMode) {
init(context: AppContext) {
self.context = context
self.mode = mode
super.init()
configure()
@ -115,9 +108,7 @@ extension MastodonPickServerViewModel {
.map { indexedServers, selectCategoryItem, searchText -> [Mastodon.Entity.Server] in
// ignore approval required servers when sign-up
var indexedServers = indexedServers
if self.mode == .signUp {
indexedServers = indexedServers.filter { !$0.approvalRequired }
}
indexedServers = indexedServers.filter { !$0.approvalRequired }
// Note:
// sort by calculate last week users count
// and make medium size (~800) server to top

View File

@ -317,7 +317,7 @@ extension WelcomeViewController {
extension WelcomeViewController {
@objc
private func signUpButtonDidClicked(_ sender: UIButton) {
_ = coordinator.present(scene: .mastodonPickServer(viewMode: MastodonPickServerViewModel(context: context, mode: .signUp)), from: self, transition: .show)
_ = coordinator.present(scene: .mastodonPickServer(viewMode: MastodonPickServerViewModel(context: context)), from: self, transition: .show)
}
@objc