This commit is contained in:
Justin Mazzocchi 2020-08-08 16:08:47 -07:00
parent 998fa8d500
commit 581aa6d40a
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
10 changed files with 58 additions and 58 deletions

View file

@ -92,8 +92,8 @@ extension AppEnvironment {
webAuthSessionType: SuccessfulStubbingWebAuthSession.self)
}
extension IdentityRepository {
static let development = try! IdentityRepository(identityID: devIdentityID, appEnvironment: .development)
extension IdentityService {
static let development = try! IdentityService(identityID: devIdentityID, appEnvironment: .development)
}
extension RootViewModel {
@ -110,16 +110,16 @@ extension SecondaryNavigationViewModel {
}
extension IdentitiesViewModel {
static let development = IdentitiesViewModel(identityRepository: .development)
static let development = IdentitiesViewModel(identityService: .development)
}
#endif
extension PreferencesViewModel {
static let development = PreferencesViewModel(identityRepository: .development)
static let development = PreferencesViewModel(identityService: .development)
}
extension PostingReadingPreferencesViewModel {
static let development = PostingReadingPreferencesViewModel(identityRepository: .development)
static let development = PostingReadingPreferencesViewModel(identityService: .development)
}
// swiftlint:enable force_try

View file

@ -15,8 +15,8 @@
D0091B6F24DD68090040E8D2 /* PreferencesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0091B6D24DD68090040E8D2 /* PreferencesView.swift */; };
D0091B7124DD68220040E8D2 /* PreferencesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0091B7024DD68220040E8D2 /* PreferencesViewModel.swift */; };
D0091B7224DD68220040E8D2 /* PreferencesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0091B7024DD68220040E8D2 /* PreferencesViewModel.swift */; };
D0091B7424DDF4860040E8D2 /* IdentityRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0091B7324DDF4860040E8D2 /* IdentityRepository.swift */; };
D0091B7524DDF4860040E8D2 /* IdentityRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0091B7324DDF4860040E8D2 /* IdentityRepository.swift */; };
D0091B7424DDF4860040E8D2 /* IdentityService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0091B7324DDF4860040E8D2 /* IdentityService.swift */; };
D0091B7524DDF4860040E8D2 /* IdentityService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0091B7324DDF4860040E8D2 /* IdentityService.swift */; };
D0159F8624DE742F00E78478 /* TabNavigationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0159F8324DE742F00E78478 /* TabNavigationViewModel.swift */; };
D0159F8824DE742F00E78478 /* SecondaryNavigationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0159F8424DE742F00E78478 /* SecondaryNavigationViewModel.swift */; };
D0159F8A24DE742F00E78478 /* IdentitiesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0159F8524DE742F00E78478 /* IdentitiesViewModel.swift */; };
@ -174,7 +174,7 @@
D0091B6A24DC10CE0040E8D2 /* PostingReadingPreferencesViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostingReadingPreferencesViewModel.swift; sourceTree = "<group>"; };
D0091B6D24DD68090040E8D2 /* PreferencesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesView.swift; sourceTree = "<group>"; };
D0091B7024DD68220040E8D2 /* PreferencesViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesViewModel.swift; sourceTree = "<group>"; };
D0091B7324DDF4860040E8D2 /* IdentityRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdentityRepository.swift; sourceTree = "<group>"; };
D0091B7324DDF4860040E8D2 /* IdentityService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdentityService.swift; sourceTree = "<group>"; };
D0159F8324DE742F00E78478 /* TabNavigationViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabNavigationViewModel.swift; sourceTree = "<group>"; };
D0159F8424DE742F00E78478 /* SecondaryNavigationViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SecondaryNavigationViewModel.swift; sourceTree = "<group>"; };
D0159F8524DE742F00E78478 /* IdentitiesViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IdentitiesViewModel.swift; sourceTree = "<group>"; };
@ -407,7 +407,7 @@
D0666A5324C6C3E500F3F04B /* Emoji.swift */,
D0666A4A24C6C37700F3F04B /* Identity.swift */,
D0666A4124C6BB7B00F3F04B /* IdentityDatabase.swift */,
D0091B7324DDF4860040E8D2 /* IdentityRepository.swift */,
D0091B7324DDF4860040E8D2 /* IdentityService.swift */,
D0666A4D24C6C39600F3F04B /* Instance.swift */,
D0DC177324D0B58800A75C65 /* Keychain.swift */,
D0ED1BE224CFA84400B4899C /* MastodonError.swift */,
@ -735,7 +735,7 @@
D0BEC94724CA22C400E864C4 /* TimelineViewModel.swift in Sources */,
D0666A4E24C6C39600F3F04B /* Instance.swift in Sources */,
D0ED1BDA24CF963E00B4899C /* AppAuthorizationEndpoint.swift in Sources */,
D0091B7424DDF4860040E8D2 /* IdentityRepository.swift in Sources */,
D0091B7424DDF4860040E8D2 /* IdentityService.swift in Sources */,
D052BBCF24D750C000A80A7A /* Defaults.swift in Sources */,
D0ED1BE324CFA84400B4899C /* MastodonError.swift in Sources */,
D0666A6324C6DC6C00F3F04B /* AppAuthorization.swift in Sources */,
@ -814,7 +814,7 @@
D0159FA624DE98F600E78478 /* NSMutableAttributedString+Extensions.swift in Sources */,
D0666A4F24C6C39600F3F04B /* Instance.swift in Sources */,
D0ED1BDB24CF963E00B4899C /* AppAuthorizationEndpoint.swift in Sources */,
D0091B7524DDF4860040E8D2 /* IdentityRepository.swift in Sources */,
D0091B7524DDF4860040E8D2 /* IdentityService.swift in Sources */,
D052BBD024D750C000A80A7A /* Defaults.swift in Sources */,
D0ED1BE424CFA84400B4899C /* MastodonError.swift in Sources */,
D0666A6424C6DC6C00F3F04B /* AppAuthorization.swift in Sources */,

View file

@ -3,7 +3,7 @@
import Foundation
import Combine
class IdentityRepository {
class IdentityService {
@Published var identity: Identity
let observationErrors: AnyPublisher<Error, Never>
@ -41,7 +41,7 @@ class IdentityRepository {
}
}
extension IdentityRepository {
extension IdentityService {
var isAuthorized: Bool { networkClient.accessToken != nil }
func verifyCredentials() -> AnyPublisher<Void, Error> {

View file

@ -8,15 +8,15 @@ class PostingReadingPreferencesViewModel: ObservableObject {
@Published var alertItem: AlertItem?
let handle: String
private let identityRepository: IdentityRepository
private let identityService: IdentityService
private var cancellables = Set<AnyCancellable>()
init(identityRepository: IdentityRepository) {
self.identityRepository = identityRepository
preferences = identityRepository.identity.preferences
handle = identityRepository.identity.handle
init(identityService: IdentityService) {
self.identityService = identityService
preferences = identityService.identity.preferences
handle = identityService.identity.handle
identityRepository.$identity.map(\.preferences)
identityService.$identity.map(\.preferences)
.dropFirst()
.removeDuplicates()
.handleEvents(receiveOutput: { [weak self] in
@ -27,7 +27,7 @@ class PostingReadingPreferencesViewModel: ObservableObject {
.assign(to: &$preferences)
$preferences.dropFirst()
.flatMap(identityRepository.updatePreferences)
.flatMap(identityService.updatePreferences)
.assignErrorsToAlertItem(to: \.alertItem, on: self)
.sink(receiveValue: {})
.store(in: &cancellables)
@ -36,7 +36,7 @@ class PostingReadingPreferencesViewModel: ObservableObject {
extension PostingReadingPreferencesViewModel {
private func refreshServerPreferences() {
identityRepository.refreshServerPreferences()
identityService.refreshServerPreferences()
.assignErrorsToAlertItem(to: \.alertItem, on: self)
.sink(receiveValue: {})
.store(in: &cancellables)

View file

@ -5,16 +5,16 @@ import Foundation
class PreferencesViewModel: ObservableObject {
let handle: String
private let identityRepository: IdentityRepository
private let identityService: IdentityService
init(identityRepository: IdentityRepository) {
self.identityRepository = identityRepository
handle = identityRepository.identity.handle
init(identityService: IdentityService) {
self.identityService = identityService
handle = identityService.identity.handle
}
}
extension PreferencesViewModel {
func postingReadingPreferencesViewModel() -> PostingReadingPreferencesViewModel {
PostingReadingPreferencesViewModel(identityRepository: identityRepository)
PostingReadingPreferencesViewModel(identityService: identityService)
}
}

View file

@ -35,19 +35,19 @@ extension RootViewModel {
}
func mainNavigationViewModel(identityID: UUID) -> MainNavigationViewModel? {
let identityRepository: IdentityRepository
let identityService: IdentityService
do {
identityRepository = try IdentityRepository(identityID: identityID, appEnvironment: environment)
identityService = try IdentityService(identityID: identityID, appEnvironment: environment)
} catch {
return nil
}
identityRepository.observationErrors
identityService.observationErrors
.receive(on: RunLoop.main)
.map { [weak self] _ in self?.environment.identityDatabase.mostRecentlyUsedIdentityID }
.assign(to: &$identityID)
return MainNavigationViewModel(identityRepository: identityRepository)
return MainNavigationViewModel(identityService: identityService)
}
}

View file

@ -8,14 +8,14 @@ class IdentitiesViewModel: ObservableObject {
@Published var identities = [Identity]()
@Published var alertItem: AlertItem?
private let identityRepository: IdentityRepository
private let identityService: IdentityService
private var cancellables = Set<AnyCancellable>()
init(identityRepository: IdentityRepository) {
self.identityRepository = identityRepository
identity = identityRepository.identity
init(identityService: IdentityService) {
self.identityService = identityService
identity = identityService.identity
identityRepository.identitiesObservation()
identityService.identitiesObservation()
.assignErrorsToAlertItem(to: \.alertItem, on: self)
.assign(to: &$identities)
}

View file

@ -4,21 +4,21 @@ import Foundation
class SecondaryNavigationViewModel: ObservableObject {
@Published private(set) var identity: Identity
private let identityRepository: IdentityRepository
private let identityService: IdentityService
init(identityRepository: IdentityRepository) {
self.identityRepository = identityRepository
identity = identityRepository.identity
identityRepository.$identity.dropFirst().assign(to: &$identity)
init(identityService: IdentityService) {
self.identityService = identityService
identity = identityService.identity
identityService.$identity.dropFirst().assign(to: &$identity)
}
}
extension SecondaryNavigationViewModel {
func identitiesViewModel() -> IdentitiesViewModel {
IdentitiesViewModel(identityRepository: identityRepository)
IdentitiesViewModel(identityService: identityService)
}
func preferencesViewModel() -> PreferencesViewModel {
PreferencesViewModel(identityRepository: identityRepository)
PreferencesViewModel(identityService: identityService)
}
}

View file

@ -10,15 +10,15 @@ class TabNavigationViewModel: ObservableObject {
@Published var alertItem: AlertItem?
var selectedTab: Tab? = .timelines
private let identityRepository: IdentityRepository
private let identityService: IdentityService
private var cancellables = Set<AnyCancellable>()
init(identityRepository: IdentityRepository) {
self.identityRepository = identityRepository
identity = identityRepository.identity
identityRepository.$identity.dropFirst().assign(to: &$identity)
init(identityService: IdentityService) {
self.identityService = identityService
identity = identityService.identity
identityService.$identity.dropFirst().assign(to: &$identity)
identityRepository.recentIdentitiesObservation()
identityService.recentIdentitiesObservation()
.assignErrorsToAlertItem(to: \.alertItem, on: self)
.assign(to: &$recentIdentities)
}
@ -26,28 +26,28 @@ class TabNavigationViewModel: ObservableObject {
extension TabNavigationViewModel {
func refreshIdentity() {
if identityRepository.isAuthorized {
identityRepository.verifyCredentials()
if identityService.isAuthorized {
identityService.verifyCredentials()
.assignErrorsToAlertItem(to: \.alertItem, on: self)
.sink(receiveValue: {})
.store(in: &cancellables)
if identity.preferences.useServerPostingReadingPreferences {
identityRepository.refreshServerPreferences()
identityService.refreshServerPreferences()
.assignErrorsToAlertItem(to: \.alertItem, on: self)
.sink(receiveValue: {})
.store(in: &cancellables)
}
}
identityRepository.refreshInstance()
identityService.refreshInstance()
.assignErrorsToAlertItem(to: \.alertItem, on: self)
.sink(receiveValue: {})
.store(in: &cancellables)
}
func secondaryNavigationViewModel() -> SecondaryNavigationViewModel {
SecondaryNavigationViewModel(identityRepository: identityRepository)
SecondaryNavigationViewModel(identityService: identityService)
}
}

View file

@ -8,13 +8,13 @@ class SidebarNavigationViewModel: ObservableObject {
@Published var alertItem: AlertItem?
var selectedTab: Tab? = .timelines
private let identityRepository: IdentityRepository
private let identityService: IdentityService
private var cancellables = Set<AnyCancellable>()
init(identityRepository: IdentityRepository) {
self.identityRepository = identityRepository
identity = identityRepository.identity
identityRepository.$identity.dropFirst().assign(to: &$identity)
init(identityService: IdentityService) {
self.identityService = identityService
identity = identityService.identity
identityService.$identity.dropFirst().assign(to: &$identity)
}
}