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
|
2021-03-01 11:06:37 +01:00
|
|
|
|
2021-02-22 09:20:44 +01:00
|
|
|
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-03-01 11:06:37 +01:00
|
|
|
let instance: Mastodon.Entity.Instance
|
|
|
|
let applicationToken: Mastodon.Entity.Token
|
2021-02-26 11:27:47 +01:00
|
|
|
|
2021-02-22 09:20:44 +01:00
|
|
|
|
2021-02-26 11:27:47 +01:00
|
|
|
init(
|
|
|
|
domain: String,
|
|
|
|
authenticateInfo: AuthenticationViewModel.AuthenticateInfo,
|
|
|
|
rules: [Mastodon.Entity.Instance.Rule],
|
2021-03-01 11:06:37 +01:00
|
|
|
instance: Mastodon.Entity.Instance,
|
|
|
|
applicationToken: Mastodon.Entity.Token
|
2021-02-26 11:27:47 +01:00
|
|
|
) {
|
2021-02-22 09:20:44 +01:00
|
|
|
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-03-01 11:06:37 +01:00
|
|
|
self.instance = instance
|
|
|
|
self.applicationToken = applicationToken
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|