chore: Make the server rules display before the sign-up form scene
This commit is contained in:
parent
a659b35577
commit
77a0708e7d
|
@ -265,13 +265,25 @@ extension MastodonPickServerViewController {
|
||||||
}
|
}
|
||||||
} receiveValue: { [weak self] response in
|
} receiveValue: { [weak self] response in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
let mastodonRegisterViewModel = MastodonRegisterViewModel(
|
if let rules = response.instance.value.rules, !rules.isEmpty {
|
||||||
domain: server.domain,
|
// show server rules before register
|
||||||
authenticateInfo: response.authenticateInfo,
|
let mastodonServerRulesViewModel = MastodonServerRulesViewModel(
|
||||||
instance: response.instance.value,
|
domain: server.domain,
|
||||||
applicationToken: response.applicationToken.value
|
authenticateInfo: response.authenticateInfo,
|
||||||
)
|
rules: rules,
|
||||||
self.coordinator.present(scene: .mastodonRegister(viewModel: mastodonRegisterViewModel), from: nil, transition: .show)
|
instance: response.instance.value,
|
||||||
|
applicationToken: response.applicationToken.value
|
||||||
|
)
|
||||||
|
self.coordinator.present(scene: .mastodonServerRules(viewModel: mastodonServerRulesViewModel), from: self, transition: .show)
|
||||||
|
} else {
|
||||||
|
let mastodonRegisterViewModel = MastodonRegisterViewModel(
|
||||||
|
domain: server.domain,
|
||||||
|
authenticateInfo: response.authenticateInfo,
|
||||||
|
instance: response.instance.value,
|
||||||
|
applicationToken: response.applicationToken.value
|
||||||
|
)
|
||||||
|
self.coordinator.present(scene: .mastodonRegister(viewModel: mastodonRegisterViewModel), from: nil, transition: .show)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.store(in: &disposeBag)
|
.store(in: &disposeBag)
|
||||||
}
|
}
|
||||||
|
|
|
@ -576,45 +576,29 @@ extension MastodonRegisterViewController {
|
||||||
locale: "en" // TODO:
|
locale: "en" // TODO:
|
||||||
)
|
)
|
||||||
|
|
||||||
if let rules = viewModel.instance.rules, !rules.isEmpty {
|
// register without show server rules
|
||||||
// show server rules before register
|
context.apiService.accountRegister(
|
||||||
let mastodonServerRulesViewModel = MastodonServerRulesViewModel(
|
domain: viewModel.domain,
|
||||||
context: context,
|
query: query,
|
||||||
domain: viewModel.domain,
|
authorization: viewModel.applicationAuthorization
|
||||||
authenticateInfo: viewModel.authenticateInfo,
|
)
|
||||||
rules: rules,
|
.receive(on: DispatchQueue.main)
|
||||||
registerQuery: query,
|
.sink { [weak self] completion in
|
||||||
applicationAuthorization: viewModel.applicationAuthorization
|
guard let self = self else { return }
|
||||||
)
|
self.viewModel.isRegistering.value = false
|
||||||
|
switch completion {
|
||||||
viewModel.isRegistering.value = false
|
case .failure(let error):
|
||||||
view.endEditing(true)
|
self.viewModel.error.send(error)
|
||||||
coordinator.present(scene: .mastodonServerRules(viewModel: mastodonServerRulesViewModel), from: self, transition: .show)
|
case .finished:
|
||||||
return
|
break
|
||||||
} else {
|
|
||||||
// register without show server rules
|
|
||||||
context.apiService.accountRegister(
|
|
||||||
domain: viewModel.domain,
|
|
||||||
query: query,
|
|
||||||
authorization: viewModel.applicationAuthorization
|
|
||||||
)
|
|
||||||
.receive(on: DispatchQueue.main)
|
|
||||||
.sink { [weak self] completion in
|
|
||||||
guard let self = self else { return }
|
|
||||||
self.viewModel.isRegistering.value = false
|
|
||||||
switch completion {
|
|
||||||
case .failure(let error):
|
|
||||||
self.viewModel.error.send(error)
|
|
||||||
case .finished:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
} receiveValue: { [weak self] response in
|
|
||||||
guard let self = self else { return }
|
|
||||||
let userToken = response.value
|
|
||||||
let viewModel = MastodonConfirmEmailViewModel(context: self.context, email: email, authenticateInfo: self.viewModel.authenticateInfo, userToken: userToken)
|
|
||||||
self.coordinator.present(scene: .mastodonConfirmEmail(viewModel: viewModel), from: self, transition: .show)
|
|
||||||
}
|
}
|
||||||
.store(in: &disposeBag)
|
} receiveValue: { [weak self] response in
|
||||||
|
guard let self = self else { return }
|
||||||
|
let userToken = response.value
|
||||||
|
let viewModel = MastodonConfirmEmailViewModel(context: self.context, email: email, authenticateInfo: self.viewModel.authenticateInfo, userToken: userToken)
|
||||||
|
self.coordinator.present(scene: .mastodonConfirmEmail(viewModel: viewModel), from: self, transition: .show)
|
||||||
}
|
}
|
||||||
|
.store(in: &disposeBag)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
import os.log
|
import os.log
|
||||||
import UIKit
|
import UIKit
|
||||||
import Combine
|
import Combine
|
||||||
import MastodonSDK
|
|
||||||
|
|
||||||
final class MastodonServerRulesViewController: UIViewController, NeedsDependency {
|
final class MastodonServerRulesViewController: UIViewController, NeedsDependency {
|
||||||
|
|
||||||
|
@ -149,31 +148,6 @@ extension MastodonServerRulesViewController {
|
||||||
|
|
||||||
rulesLabel.attributedText = viewModel.rulesAttributedString
|
rulesLabel.attributedText = viewModel.rulesAttributedString
|
||||||
confirmButton.addTarget(self, action: #selector(MastodonServerRulesViewController.confirmButtonPressed(_:)), for: .touchUpInside)
|
confirmButton.addTarget(self, action: #selector(MastodonServerRulesViewController.confirmButtonPressed(_:)), for: .touchUpInside)
|
||||||
|
|
||||||
viewModel.isRegistering
|
|
||||||
.receive(on: DispatchQueue.main)
|
|
||||||
.sink { [weak self] isRegistering in
|
|
||||||
guard let self = self else { return }
|
|
||||||
isRegistering ? self.confirmButton.showLoading() : self.confirmButton.stopLoading()
|
|
||||||
}
|
|
||||||
.store(in: &disposeBag)
|
|
||||||
|
|
||||||
viewModel.error
|
|
||||||
.compactMap { $0 }
|
|
||||||
.receive(on: DispatchQueue.main)
|
|
||||||
.sink { [weak self] error in
|
|
||||||
guard let self = self else { return }
|
|
||||||
guard let error = error as? Mastodon.API.Error else { return }
|
|
||||||
let alertController = UIAlertController(for: error, title: "Sign Up Failure", preferredStyle: .alert)
|
|
||||||
let okAction = UIAlertAction(title: L10n.Common.Controls.Actions.ok, style: .default, handler: nil)
|
|
||||||
alertController.addAction(okAction)
|
|
||||||
self.coordinator.present(
|
|
||||||
scene: .alertController(alertController: alertController),
|
|
||||||
from: nil,
|
|
||||||
transition: .alertController(animated: true, completion: nil)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
.store(in: &disposeBag)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewDidLayoutSubviews() {
|
override func viewDidLayoutSubviews() {
|
||||||
|
@ -199,31 +173,9 @@ extension MastodonServerRulesViewController {
|
||||||
extension MastodonServerRulesViewController {
|
extension MastodonServerRulesViewController {
|
||||||
@objc private func confirmButtonPressed(_ sender: UIButton) {
|
@objc private func confirmButtonPressed(_ sender: UIButton) {
|
||||||
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)
|
||||||
|
|
||||||
let email = viewModel.registerQuery.email
|
let viewModel = MastodonRegisterViewModel(domain: self.viewModel.domain, authenticateInfo: self.viewModel.authenticateInfo, instance: self.viewModel.instance, applicationToken: self.viewModel.applicationToken)
|
||||||
|
self.coordinator.present(scene: .mastodonRegister(viewModel: viewModel), from: self, transition: .show)
|
||||||
context.apiService.accountRegister(
|
|
||||||
domain: viewModel.domain,
|
|
||||||
query: viewModel.registerQuery,
|
|
||||||
authorization: viewModel.applicationAuthorization
|
|
||||||
)
|
|
||||||
.receive(on: DispatchQueue.main)
|
|
||||||
.sink { [weak self] completion in
|
|
||||||
guard let self = self else { return }
|
|
||||||
self.viewModel.isRegistering.value = false
|
|
||||||
switch completion {
|
|
||||||
case .failure(let error):
|
|
||||||
self.viewModel.error.send(error)
|
|
||||||
case .finished:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
} receiveValue: { [weak self] response in
|
|
||||||
guard let self = self else { return }
|
|
||||||
let userToken = response.value
|
|
||||||
let viewModel = MastodonConfirmEmailViewModel(context: self.context, email: email, authenticateInfo: self.viewModel.authenticateInfo, userToken: userToken)
|
|
||||||
self.coordinator.present(scene: .mastodonConfirmEmail(viewModel: viewModel), from: self, transition: .show)
|
|
||||||
}
|
|
||||||
.store(in: &disposeBag)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,34 +10,27 @@ import Combine
|
||||||
import MastodonSDK
|
import MastodonSDK
|
||||||
|
|
||||||
final class MastodonServerRulesViewModel {
|
final class MastodonServerRulesViewModel {
|
||||||
|
|
||||||
// input
|
// input
|
||||||
let context: AppContext
|
|
||||||
let domain: String
|
let domain: String
|
||||||
let authenticateInfo: AuthenticationViewModel.AuthenticateInfo
|
let authenticateInfo: AuthenticationViewModel.AuthenticateInfo
|
||||||
let rules: [Mastodon.Entity.Instance.Rule]
|
let rules: [Mastodon.Entity.Instance.Rule]
|
||||||
let registerQuery: Mastodon.API.Account.RegisterQuery
|
let instance: Mastodon.Entity.Instance
|
||||||
let applicationAuthorization: Mastodon.API.OAuth.Authorization
|
let applicationToken: Mastodon.Entity.Token
|
||||||
|
|
||||||
// output
|
|
||||||
let isRegistering = CurrentValueSubject<Bool, Never>(false)
|
|
||||||
let error = CurrentValueSubject<Error?, Never>(nil)
|
|
||||||
|
|
||||||
|
|
||||||
init(
|
init(
|
||||||
context: AppContext,
|
|
||||||
domain: String,
|
domain: String,
|
||||||
authenticateInfo: AuthenticationViewModel.AuthenticateInfo,
|
authenticateInfo: AuthenticationViewModel.AuthenticateInfo,
|
||||||
rules: [Mastodon.Entity.Instance.Rule],
|
rules: [Mastodon.Entity.Instance.Rule],
|
||||||
registerQuery: Mastodon.API.Account.RegisterQuery,
|
instance: Mastodon.Entity.Instance,
|
||||||
applicationAuthorization: Mastodon.API.OAuth.Authorization
|
applicationToken: Mastodon.Entity.Token
|
||||||
) {
|
) {
|
||||||
self.context = context
|
|
||||||
self.domain = domain
|
self.domain = domain
|
||||||
self.authenticateInfo = authenticateInfo
|
self.authenticateInfo = authenticateInfo
|
||||||
self.rules = rules
|
self.rules = rules
|
||||||
self.registerQuery = registerQuery
|
self.instance = instance
|
||||||
self.applicationAuthorization = applicationAuthorization
|
self.applicationToken = applicationToken
|
||||||
}
|
}
|
||||||
|
|
||||||
var rulesAttributedString: NSAttributedString {
|
var rulesAttributedString: NSAttributedString {
|
||||||
|
|
Loading…
Reference in New Issue