From 9be8b95aeaecc4fb0b68b59a03ab2fc86763d07f Mon Sep 17 00:00:00 2001 From: ihugo Date: Sat, 17 Apr 2021 14:01:57 +0800 Subject: [PATCH] fix: use right privacyURL - remove some redundancy code --- CoreDataStack/Entity/SubscriptionAlerts.swift | 1 - Mastodon/Extension/UIButton.swift | 20 ++++--------------- .../Settings/SettingsViewController.swift | 7 +++---- .../Scene/Settings/SettingsViewModel.swift | 8 ++++++++ .../MastodonSDK/API/Mastodon+API+Push.swift | 6 +++--- 5 files changed, 18 insertions(+), 24 deletions(-) diff --git a/CoreDataStack/Entity/SubscriptionAlerts.swift b/CoreDataStack/Entity/SubscriptionAlerts.swift index c240a02a5..d1169104a 100644 --- a/CoreDataStack/Entity/SubscriptionAlerts.swift +++ b/CoreDataStack/Entity/SubscriptionAlerts.swift @@ -9,7 +9,6 @@ import Foundation import CoreData -@objc(SubscriptionAlerts) public final class SubscriptionAlerts: NSManagedObject { @NSManaged public var follow: NSNumber? @NSManaged public var favourite: NSNumber? diff --git a/Mastodon/Extension/UIButton.swift b/Mastodon/Extension/UIButton.swift index d4334baad..31043157a 100644 --- a/Mastodon/Extension/UIButton.swift +++ b/Mastodon/Extension/UIButton.swift @@ -44,22 +44,10 @@ extension UIButton { } extension UIButton { - // https://stackoverflow.com/questions/14523348/how-to-change-the-background-color-of-a-uibutton-while-its-highlighted - private func image(withColor color: UIColor) -> UIImage? { - let rect = CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0) - UIGraphicsBeginImageContext(rect.size) - let context = UIGraphicsGetCurrentContext() - - context?.setFillColor(color.cgColor) - context?.fill(rect) - - let image = UIGraphicsGetImageFromCurrentImageContext() - UIGraphicsEndImageContext() - - return image - } - func setBackgroundColor(_ color: UIColor, for state: UIControl.State) { - self.setBackgroundImage(image(withColor: color), for: state) + self.setBackgroundImage( + UIImage.placeholder(color: color), + for: state + ) } } diff --git a/Mastodon/Scene/Settings/SettingsViewController.swift b/Mastodon/Scene/Settings/SettingsViewController.swift index 4bdc115b2..a9b1f0b82 100644 --- a/Mastodon/Scene/Settings/SettingsViewController.swift +++ b/Mastodon/Scene/Settings/SettingsViewController.swift @@ -311,8 +311,9 @@ extension SettingsViewController: UITableViewDelegate { switch item { case .boringZone: + guard let url = viewModel.privacyURL else { break } coordinator.present( - scene: .safari(url: URL(string: "https://mastodon.online/terms")!), + scene: .safari(url: url), from: self, transition: .safariPresent(animated: true, completion: nil) ) @@ -345,11 +346,9 @@ extension SettingsViewController { func updateTrigger(by who: String) { guard let setting = self.viewModel.setting.value else { return } - context.managedObjectContext.performChanges { + _ = context.managedObjectContext.performChanges { setting.update(triggerBy: who) } - .sink { (_) in - }.store(in: &disposeBag) } func updateAlert(title: String?, isOn: Bool) { diff --git a/Mastodon/Scene/Settings/SettingsViewModel.swift b/Mastodon/Scene/Settings/SettingsViewModel.swift index 9ffec7f8d..b61334f4a 100644 --- a/Mastodon/Scene/Settings/SettingsViewModel.swift +++ b/Mastodon/Scene/Settings/SettingsViewModel.swift @@ -70,6 +70,14 @@ class SettingsViewModel: NSObject, NeedsDependency { noOne: noOneSwitchItems] }() + lazy var privacyURL: URL? = { + guard let box = AppContext.shared.authenticationService.activeMastodonAuthenticationBox.value else { + return nil + } + + return Mastodon.API.privacyURL(domain: box.domain) + }() + struct Input { } diff --git a/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Push.swift b/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Push.swift index 062b45ac2..df9168499 100644 --- a/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Push.swift +++ b/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Push.swift @@ -28,7 +28,7 @@ extension Mastodon.API.Subscriptions { /// - session: `URLSession` /// - domain: Mastodon instance domain. e.g. "example.com" /// - authorization: User token. Could be nil if status is public - /// - Returns: `AnyPublisher` contains `Poll` nested in the response + /// - Returns: `AnyPublisher` contains `Subscription` nested in the response public static func subscription( session: URLSession, domain: String, @@ -61,7 +61,7 @@ extension Mastodon.API.Subscriptions { /// - session: `URLSession` /// - domain: Mastodon instance domain. e.g. "example.com" /// - authorization: User token. Could be nil if status is public - /// - Returns: `AnyPublisher` contains `Poll` nested in the response + /// - Returns: `AnyPublisher` contains `Subscription` nested in the response public static func createSubscription( session: URLSession, domain: String, @@ -95,7 +95,7 @@ extension Mastodon.API.Subscriptions { /// - session: `URLSession` /// - domain: Mastodon instance domain. e.g. "example.com" /// - authorization: User token. Could be nil if status is public - /// - Returns: `AnyPublisher` contains `Poll` nested in the response + /// - Returns: `AnyPublisher` contains `Subscription` nested in the response public static func updateSubscription( session: URLSession, domain: String,