chore: Make the server rules display before the sign-up form scene
This commit is contained in:
parent
a659b35577
commit
77a0708e7d
|
@ -265,6 +265,17 @@ extension MastodonPickServerViewController {
|
||||||
}
|
}
|
||||||
} receiveValue: { [weak self] response in
|
} receiveValue: { [weak self] response in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
|
if let rules = response.instance.value.rules, !rules.isEmpty {
|
||||||
|
// show server rules before register
|
||||||
|
let mastodonServerRulesViewModel = MastodonServerRulesViewModel(
|
||||||
|
domain: server.domain,
|
||||||
|
authenticateInfo: response.authenticateInfo,
|
||||||
|
rules: rules,
|
||||||
|
instance: response.instance.value,
|
||||||
|
applicationToken: response.applicationToken.value
|
||||||
|
)
|
||||||
|
self.coordinator.present(scene: .mastodonServerRules(viewModel: mastodonServerRulesViewModel), from: self, transition: .show)
|
||||||
|
} else {
|
||||||
let mastodonRegisterViewModel = MastodonRegisterViewModel(
|
let mastodonRegisterViewModel = MastodonRegisterViewModel(
|
||||||
domain: server.domain,
|
domain: server.domain,
|
||||||
authenticateInfo: response.authenticateInfo,
|
authenticateInfo: response.authenticateInfo,
|
||||||
|
@ -273,6 +284,7 @@ extension MastodonPickServerViewController {
|
||||||
)
|
)
|
||||||
self.coordinator.present(scene: .mastodonRegister(viewModel: mastodonRegisterViewModel), from: nil, transition: .show)
|
self.coordinator.present(scene: .mastodonRegister(viewModel: mastodonRegisterViewModel), from: nil, transition: .show)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
.store(in: &disposeBag)
|
.store(in: &disposeBag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -576,22 +576,6 @@ extension MastodonRegisterViewController {
|
||||||
locale: "en" // TODO:
|
locale: "en" // TODO:
|
||||||
)
|
)
|
||||||
|
|
||||||
if let rules = viewModel.instance.rules, !rules.isEmpty {
|
|
||||||
// show server rules before register
|
|
||||||
let mastodonServerRulesViewModel = MastodonServerRulesViewModel(
|
|
||||||
context: context,
|
|
||||||
domain: viewModel.domain,
|
|
||||||
authenticateInfo: viewModel.authenticateInfo,
|
|
||||||
rules: rules,
|
|
||||||
registerQuery: query,
|
|
||||||
applicationAuthorization: viewModel.applicationAuthorization
|
|
||||||
)
|
|
||||||
|
|
||||||
viewModel.isRegistering.value = false
|
|
||||||
view.endEditing(true)
|
|
||||||
coordinator.present(scene: .mastodonServerRules(viewModel: mastodonServerRulesViewModel), from: self, transition: .show)
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
// register without show server rules
|
// register without show server rules
|
||||||
context.apiService.accountRegister(
|
context.apiService.accountRegister(
|
||||||
domain: viewModel.domain,
|
domain: viewModel.domain,
|
||||||
|
@ -615,6 +599,6 @@ extension MastodonRegisterViewController {
|
||||||
self.coordinator.present(scene: .mastodonConfirmEmail(viewModel: viewModel), from: self, transition: .show)
|
self.coordinator.present(scene: .mastodonConfirmEmail(viewModel: viewModel), from: self, transition: .show)
|
||||||
}
|
}
|
||||||
.store(in: &disposeBag)
|
.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() {
|
||||||
|
@ -200,30 +174,8 @@ 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