mastodon-ios/Mastodon/Scene/Onboarding/ServerRules/MastodonServerRulesViewMode...

58 lines
1.8 KiB
Swift
Raw Normal View History

2021-02-22 09:20:44 +01:00
//
// MastodonServerRulesViewModel.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-2-22.
//
import UIKit
2021-02-26 11:27:47 +01:00
import Combine
2021-02-22 09:20:44 +01:00
import MastodonSDK
final class MastodonServerRulesViewModel {
// input
let context: AppContext
let domain: String
2021-02-26 11:27:47 +01:00
let authenticateInfo: AuthenticationViewModel.AuthenticateInfo
2021-02-22 09:20:44 +01:00
let rules: [Mastodon.Entity.Instance.Rule]
2021-02-26 11:27:47 +01:00
let registerQuery: Mastodon.API.Account.RegisterQuery
let applicationAuthorization: Mastodon.API.OAuth.Authorization
// output
let isRegistering = CurrentValueSubject<Bool, Never>(false)
let error = CurrentValueSubject<Error?, Never>(nil)
2021-02-22 09:20:44 +01:00
2021-02-26 11:27:47 +01:00
init(
context: AppContext,
domain: String,
authenticateInfo: AuthenticationViewModel.AuthenticateInfo,
rules: [Mastodon.Entity.Instance.Rule],
registerQuery: Mastodon.API.Account.RegisterQuery,
applicationAuthorization: Mastodon.API.OAuth.Authorization
) {
2021-02-22 09:20:44 +01:00
self.context = context
self.domain = domain
2021-02-26 11:27:47 +01:00
self.authenticateInfo = authenticateInfo
2021-02-22 09:20:44 +01:00
self.rules = rules
2021-02-26 11:27:47 +01:00
self.registerQuery = registerQuery
self.applicationAuthorization = applicationAuthorization
2021-02-22 09:20:44 +01:00
}
var rulesAttributedString: NSAttributedString {
let attributedString = NSMutableAttributedString(string: "\n")
for (i, rule) in rules.enumerated() {
let index = String(i + 1)
let indexString = NSAttributedString(string: index + ". ", attributes: [
NSAttributedString.Key.foregroundColor: UIColor.secondaryLabel
])
let ruleString = NSAttributedString(string: rule.text + "\n\n")
attributedString.append(indexString)
attributedString.append(ruleString)
}
return attributedString
}
}