parent
38317d8fa6
commit
08302cf2fa
|
@ -56,6 +56,52 @@ class MastodonLoginViewController: UIViewController {
|
||||||
@objc func nextButtonPressed(_ sender: Any) {
|
@objc func nextButtonPressed(_ sender: Any) {
|
||||||
delegate?.nextButtonPressed(self)
|
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
|
// MARK: - OnboardingViewControllerAppearance
|
||||||
|
|
|
@ -270,60 +270,6 @@ extension MastodonPickServerViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func nextButtonDidPressed(_ sender: UIButton) {
|
@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)
|
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 }
|
guard let server = viewModel.selectedServer.value else { return }
|
||||||
authenticationViewModel.isAuthenticating.send(true)
|
authenticationViewModel.isAuthenticating.send(true)
|
||||||
|
|
|
@ -17,12 +17,7 @@ import MastodonCore
|
||||||
import MastodonUI
|
import MastodonUI
|
||||||
|
|
||||||
class MastodonPickServerViewModel: NSObject {
|
class MastodonPickServerViewModel: NSObject {
|
||||||
|
|
||||||
enum PickServerMode {
|
|
||||||
case signUp
|
|
||||||
case signIn
|
|
||||||
}
|
|
||||||
|
|
||||||
enum EmptyStateViewState {
|
enum EmptyStateViewState {
|
||||||
case none
|
case none
|
||||||
case loading
|
case loading
|
||||||
|
@ -34,7 +29,6 @@ class MastodonPickServerViewModel: NSObject {
|
||||||
let serverSectionHeaderView = PickServerServerSectionTableHeaderView()
|
let serverSectionHeaderView = PickServerServerSectionTableHeaderView()
|
||||||
|
|
||||||
// input
|
// input
|
||||||
let mode: PickServerMode
|
|
||||||
let context: AppContext
|
let context: AppContext
|
||||||
var categoryPickerItems: [CategoryPickerItem] = {
|
var categoryPickerItems: [CategoryPickerItem] = {
|
||||||
var items: [CategoryPickerItem] = []
|
var items: [CategoryPickerItem] = []
|
||||||
|
@ -72,9 +66,8 @@ class MastodonPickServerViewModel: NSObject {
|
||||||
let loadingIndexedServersError = CurrentValueSubject<Error?, Never>(nil)
|
let loadingIndexedServersError = CurrentValueSubject<Error?, Never>(nil)
|
||||||
let emptyStateViewState = CurrentValueSubject<EmptyStateViewState, Never>(.none)
|
let emptyStateViewState = CurrentValueSubject<EmptyStateViewState, Never>(.none)
|
||||||
|
|
||||||
init(context: AppContext, mode: PickServerMode) {
|
init(context: AppContext) {
|
||||||
self.context = context
|
self.context = context
|
||||||
self.mode = mode
|
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
configure()
|
configure()
|
||||||
|
@ -115,9 +108,7 @@ extension MastodonPickServerViewModel {
|
||||||
.map { indexedServers, selectCategoryItem, searchText -> [Mastodon.Entity.Server] in
|
.map { indexedServers, selectCategoryItem, searchText -> [Mastodon.Entity.Server] in
|
||||||
// ignore approval required servers when sign-up
|
// ignore approval required servers when sign-up
|
||||||
var indexedServers = indexedServers
|
var indexedServers = indexedServers
|
||||||
if self.mode == .signUp {
|
indexedServers = indexedServers.filter { !$0.approvalRequired }
|
||||||
indexedServers = indexedServers.filter { !$0.approvalRequired }
|
|
||||||
}
|
|
||||||
// Note:
|
// Note:
|
||||||
// sort by calculate last week users count
|
// sort by calculate last week users count
|
||||||
// and make medium size (~800) server to top
|
// and make medium size (~800) server to top
|
||||||
|
|
|
@ -317,7 +317,7 @@ extension WelcomeViewController {
|
||||||
extension WelcomeViewController {
|
extension WelcomeViewController {
|
||||||
@objc
|
@objc
|
||||||
private func signUpButtonDidClicked(_ sender: UIButton) {
|
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
|
@objc
|
||||||
|
|
Loading…
Reference in New Issue