Renaming
This commit is contained in:
parent
dd2f70a3f8
commit
ea6b1edd3d
|
@ -52,23 +52,23 @@ extension AppEnvironment {
|
|||
inMemoryContent: true)
|
||||
}
|
||||
|
||||
extension IdentitiesService {
|
||||
extension AllIdentitiesService {
|
||||
static func fresh(
|
||||
identityDatabase: IdentityDatabase = .fresh(),
|
||||
keychainService: KeychainService = MockKeychainService(),
|
||||
environment: AppEnvironment = .development) -> IdentitiesService {
|
||||
IdentitiesService(
|
||||
environment: AppEnvironment = .development) -> AllIdentitiesService {
|
||||
AllIdentitiesService(
|
||||
identityDatabase: identityDatabase,
|
||||
environment: environment)
|
||||
}
|
||||
|
||||
static let development = IdentitiesService(
|
||||
static let development = AllIdentitiesService(
|
||||
identityDatabase: .development,
|
||||
environment: .development)
|
||||
}
|
||||
|
||||
extension IdentityService {
|
||||
static let development = try! IdentitiesService.development.identityService(id: devIdentityID)
|
||||
static let development = try! AllIdentitiesService.development.identityService(id: devIdentityID)
|
||||
}
|
||||
|
||||
extension UserNotificationService {
|
||||
|
@ -78,7 +78,7 @@ extension UserNotificationService {
|
|||
extension RootViewModel {
|
||||
static let development = RootViewModel(
|
||||
appDelegate: AppDelegate(),
|
||||
identitiesService: .development,
|
||||
allIdentitiesService: .development,
|
||||
userNotificationService: .development)
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,8 @@ extension NotificationTypesPreferencesViewModel {
|
|||
}
|
||||
|
||||
extension StatusListViewModel {
|
||||
static let development = StatusListViewModel(statusListService: IdentityService.development.service(timeline: .home))
|
||||
static let development = StatusListViewModel(
|
||||
statusListService: IdentityService.development.service(timeline: .home))
|
||||
}
|
||||
|
||||
// swiftlint:enable force_try
|
||||
|
|
|
@ -213,8 +213,8 @@
|
|||
D0EC8DC624DF842700A08489 /* KeychainService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC8DC424DF842700A08489 /* KeychainService.swift */; };
|
||||
D0EC8DC824DF8B3C00A08489 /* SecretsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC8DC724DF8B3C00A08489 /* SecretsService.swift */; };
|
||||
D0EC8DC924DF8B3C00A08489 /* SecretsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC8DC724DF8B3C00A08489 /* SecretsService.swift */; };
|
||||
D0EC8DCB24DFA06700A08489 /* IdentitiesService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC8DCA24DFA06700A08489 /* IdentitiesService.swift */; };
|
||||
D0EC8DCC24DFA06700A08489 /* IdentitiesService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC8DCA24DFA06700A08489 /* IdentitiesService.swift */; };
|
||||
D0EC8DCB24DFA06700A08489 /* AllIdentitiesService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC8DCA24DFA06700A08489 /* AllIdentitiesService.swift */; };
|
||||
D0EC8DCC24DFA06700A08489 /* AllIdentitiesService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC8DCA24DFA06700A08489 /* AllIdentitiesService.swift */; };
|
||||
D0EC8DCE24DFB64200A08489 /* AuthenticationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC8DCD24DFB64200A08489 /* AuthenticationService.swift */; };
|
||||
D0EC8DCF24DFB64200A08489 /* AuthenticationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC8DCD24DFB64200A08489 /* AuthenticationService.swift */; };
|
||||
D0EC8DD424DFE38900A08489 /* AuthenticationServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC8DD324DFE38900A08489 /* AuthenticationServiceTests.swift */; };
|
||||
|
@ -394,7 +394,7 @@
|
|||
D0EC8DC124DF7D9C00A08489 /* IdentityService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IdentityService.swift; sourceTree = "<group>"; };
|
||||
D0EC8DC424DF842700A08489 /* KeychainService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainService.swift; sourceTree = "<group>"; };
|
||||
D0EC8DC724DF8B3C00A08489 /* SecretsService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SecretsService.swift; sourceTree = "<group>"; };
|
||||
D0EC8DCA24DFA06700A08489 /* IdentitiesService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdentitiesService.swift; sourceTree = "<group>"; };
|
||||
D0EC8DCA24DFA06700A08489 /* AllIdentitiesService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllIdentitiesService.swift; sourceTree = "<group>"; };
|
||||
D0EC8DCD24DFB64200A08489 /* AuthenticationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationService.swift; sourceTree = "<group>"; };
|
||||
D0EC8DD324DFE38900A08489 /* AuthenticationServiceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationServiceTests.swift; sourceTree = "<group>"; };
|
||||
D0EC8DD724E096C900A08489 /* UserNotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserNotificationService.swift; sourceTree = "<group>"; };
|
||||
|
@ -533,7 +533,7 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
D0EC8DCD24DFB64200A08489 /* AuthenticationService.swift */,
|
||||
D0EC8DCA24DFA06700A08489 /* IdentitiesService.swift */,
|
||||
D0EC8DCA24DFA06700A08489 /* AllIdentitiesService.swift */,
|
||||
D0EC8DC124DF7D9C00A08489 /* IdentityService.swift */,
|
||||
D0EC8DC424DF842700A08489 /* KeychainService.swift */,
|
||||
D0EC8DC724DF8B3C00A08489 /* SecretsService.swift */,
|
||||
|
@ -1122,7 +1122,7 @@
|
|||
D019E6F024DF7C2F00697C7D /* DatabaseError.swift in Sources */,
|
||||
D019E6D724DF728400697C7D /* MastodonEncoder.swift in Sources */,
|
||||
D0EC8DE524E0B44500A08489 /* UserNotificationService.swift in Sources */,
|
||||
D0EC8DCB24DFA06700A08489 /* IdentitiesService.swift in Sources */,
|
||||
D0EC8DCB24DFA06700A08489 /* AllIdentitiesService.swift in Sources */,
|
||||
D0091B7124DD68220040E8D2 /* PreferencesViewModel.swift in Sources */,
|
||||
D0A2453724EF346800B07068 /* StatusListViewController.swift in Sources */,
|
||||
D057426A24EA32AC00839EBA /* Timeline.swift in Sources */,
|
||||
|
@ -1192,7 +1192,7 @@
|
|||
D0ED1BC224CED48800B4899C /* HTTPClient.swift in Sources */,
|
||||
D0666A4C24C6C37700F3F04B /* Identity.swift in Sources */,
|
||||
D0EC8DE424E0B44400A08489 /* UserNotificationService.swift in Sources */,
|
||||
D0EC8DCC24DFA06700A08489 /* IdentitiesService.swift in Sources */,
|
||||
D0EC8DCC24DFA06700A08489 /* AllIdentitiesService.swift in Sources */,
|
||||
D0666A5524C6C3E500F3F04B /* Emoji.swift in Sources */,
|
||||
D019E6EE24DF7BF300697C7D /* IdentityDatabase.swift in Sources */,
|
||||
D0A652AE24DE3EB6002EA33F /* PreferencesEndpoint+Stubbing.swift in Sources */,
|
||||
|
|
|
@ -12,7 +12,7 @@ struct MetatextApp: App {
|
|||
#endif
|
||||
// swiftlint:enable weak_delegate
|
||||
|
||||
private let identitiesService: IdentitiesService = {
|
||||
private let allIdentitiesService: AllIdentitiesService = {
|
||||
let identityDatabase: IdentityDatabase
|
||||
|
||||
do {
|
||||
|
@ -21,14 +21,14 @@ struct MetatextApp: App {
|
|||
fatalError("Failed to initialize identity database")
|
||||
}
|
||||
|
||||
return IdentitiesService(identityDatabase: identityDatabase, environment: .live)
|
||||
return AllIdentitiesService(identityDatabase: identityDatabase, environment: .live)
|
||||
}()
|
||||
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
RootView(
|
||||
viewModel: RootViewModel(appDelegate: appDelegate,
|
||||
identitiesService: identitiesService,
|
||||
allIdentitiesService: allIdentitiesService,
|
||||
userNotificationService: UserNotificationService()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import Foundation
|
||||
import Combine
|
||||
|
||||
struct IdentitiesService {
|
||||
struct AllIdentitiesService {
|
||||
let mostRecentlyUsedIdentityID: AnyPublisher<UUID?, Never>
|
||||
|
||||
private let identityDatabase: IdentityDatabase
|
||||
|
@ -19,7 +19,7 @@ struct IdentitiesService {
|
|||
}
|
||||
}
|
||||
|
||||
extension IdentitiesService {
|
||||
extension AllIdentitiesService {
|
||||
func identityService(id: UUID) throws -> IdentityService {
|
||||
try IdentityService(identityID: id,
|
||||
identityDatabase: identityDatabase,
|
|
@ -9,12 +9,12 @@ class AddIdentityViewModel: ObservableObject {
|
|||
@Published private(set) var loading = false
|
||||
let addedIdentityID: AnyPublisher<UUID, Never>
|
||||
|
||||
private let identitiesService: IdentitiesService
|
||||
private let allIdentitiesService: AllIdentitiesService
|
||||
private let addedIdentityIDInput = PassthroughSubject<UUID, Never>()
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
init(identitiesService: IdentitiesService) {
|
||||
self.identitiesService = identitiesService
|
||||
init(allIdentitiesService: AllIdentitiesService) {
|
||||
self.allIdentitiesService = allIdentitiesService
|
||||
addedIdentityID = addedIdentityIDInput.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
|
@ -30,10 +30,10 @@ class AddIdentityViewModel: ObservableObject {
|
|||
return
|
||||
}
|
||||
|
||||
identitiesService.authorizeIdentity(id: identityID, instanceURL: instanceURL)
|
||||
allIdentitiesService.authorizeIdentity(id: identityID, instanceURL: instanceURL)
|
||||
.collect()
|
||||
.map { _ in (identityID, instanceURL) }
|
||||
.flatMap(identitiesService.createIdentity(id:instanceURL:))
|
||||
.flatMap(allIdentitiesService.createIdentity(id:instanceURL:))
|
||||
.assignErrorsToAlertItem(to: \.alertItem, on: self)
|
||||
.receive(on: RunLoop.main)
|
||||
.handleEvents(
|
||||
|
@ -60,7 +60,7 @@ class AddIdentityViewModel: ObservableObject {
|
|||
}
|
||||
|
||||
// TODO: Ensure instance has not disabled public preview
|
||||
identitiesService.createIdentity(id: identityID, instanceURL: instanceURL)
|
||||
allIdentitiesService.createIdentity(id: identityID, instanceURL: instanceURL)
|
||||
.assignErrorsToAlertItem(to: \.alertItem, on: self)
|
||||
.sink { [weak self] in
|
||||
guard let self = self, case .finished = $0 else { return }
|
||||
|
|
|
@ -10,18 +10,18 @@ class RootViewModel: ObservableObject {
|
|||
// swiftlint:disable weak_delegate
|
||||
private let appDelegate: AppDelegate
|
||||
// swiftlint:enable weak_delegate
|
||||
private let identitiesService: IdentitiesService
|
||||
private let allIdentitiesService: AllIdentitiesService
|
||||
private let userNotificationService: UserNotificationService
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
init(appDelegate: AppDelegate,
|
||||
identitiesService: IdentitiesService,
|
||||
allIdentitiesService: AllIdentitiesService,
|
||||
userNotificationService: UserNotificationService) {
|
||||
self.appDelegate = appDelegate
|
||||
self.identitiesService = identitiesService
|
||||
self.allIdentitiesService = allIdentitiesService
|
||||
self.userNotificationService = userNotificationService
|
||||
|
||||
identitiesService.mostRecentlyUsedIdentityID.assign(to: &$mostRecentlyUsedIdentityID)
|
||||
allIdentitiesService.mostRecentlyUsedIdentityID.assign(to: &$mostRecentlyUsedIdentityID)
|
||||
|
||||
newIdentitySelected(id: mostRecentlyUsedIdentityID)
|
||||
|
||||
|
@ -29,7 +29,7 @@ class RootViewModel: ObservableObject {
|
|||
.filter { $0 }
|
||||
.zip(appDelegate.registerForRemoteNotifications())
|
||||
.map { $1 }
|
||||
.flatMap(identitiesService.updatePushSubscriptions(deviceToken:))
|
||||
.flatMap(allIdentitiesService.updatePushSubscriptions(deviceToken:))
|
||||
.sink { _ in } receiveValue: { _ in }
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ extension RootViewModel {
|
|||
let identityService: IdentityService
|
||||
|
||||
do {
|
||||
identityService = try identitiesService.identityService(id: id)
|
||||
identityService = try allIdentitiesService.identityService(id: id)
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
|
@ -74,12 +74,12 @@ extension RootViewModel {
|
|||
}
|
||||
|
||||
func deleteIdentity(_ identity: Identity) {
|
||||
identitiesService.deleteIdentity(identity)
|
||||
allIdentitiesService.deleteIdentity(identity)
|
||||
.sink { _ in } receiveValue: { _ in }
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
func addIdentityViewModel() -> AddIdentityViewModel {
|
||||
AddIdentityViewModel(identitiesService: identitiesService)
|
||||
AddIdentityViewModel(allIdentitiesService: allIdentitiesService)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import CombineExpectations
|
|||
class AddIdentityViewModelTests: XCTestCase {
|
||||
func testAddIdentity() throws {
|
||||
let identityDatabase = IdentityDatabase.fresh()
|
||||
let sut = AddIdentityViewModel(identitiesService: .fresh(identityDatabase: identityDatabase))
|
||||
let sut = AddIdentityViewModel(allIdentitiesService: .fresh(identityDatabase: identityDatabase))
|
||||
let addedIDRecorder = sut.addedIdentityID.record()
|
||||
|
||||
sut.urlFieldText = "https://mastodon.social"
|
||||
|
@ -19,7 +19,7 @@ class AddIdentityViewModelTests: XCTestCase {
|
|||
|
||||
func testAddIdentityWithoutScheme() throws {
|
||||
let identityDatabase = IdentityDatabase.fresh()
|
||||
let sut = AddIdentityViewModel(identitiesService: .fresh(identityDatabase: identityDatabase))
|
||||
let sut = AddIdentityViewModel(allIdentitiesService: .fresh(identityDatabase: identityDatabase))
|
||||
let addedIDRecorder = sut.addedIdentityID.record()
|
||||
|
||||
sut.urlFieldText = "mastodon.social"
|
||||
|
@ -29,7 +29,7 @@ class AddIdentityViewModelTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testInvalidURL() throws {
|
||||
let sut = AddIdentityViewModel(identitiesService: .fresh())
|
||||
let sut = AddIdentityViewModel(allIdentitiesService: .fresh())
|
||||
let recorder = sut.$alertItem.record()
|
||||
|
||||
XCTAssertNil(try wait(for: recorder.next(), timeout: 1))
|
||||
|
@ -46,11 +46,13 @@ class AddIdentityViewModelTests: XCTestCase {
|
|||
let environment = AppEnvironment(
|
||||
session: Session(configuration: .stubbing),
|
||||
webAuthSessionType: CanceledLoginMockWebAuthSession.self,
|
||||
keychainServiceType: MockKeychainService.self)
|
||||
let identitiesService = IdentitiesService(
|
||||
keychainServiceType: MockKeychainService.self,
|
||||
userDefaults: MockUserDefaults(),
|
||||
inMemoryContent: true)
|
||||
let allIdentitiesService = AllIdentitiesService(
|
||||
identityDatabase: .fresh(),
|
||||
environment: environment)
|
||||
let sut = AddIdentityViewModel(identitiesService: identitiesService)
|
||||
let sut = AddIdentityViewModel(allIdentitiesService: allIdentitiesService)
|
||||
let recorder = sut.$alertItem.record()
|
||||
|
||||
XCTAssertNil(try wait(for: recorder.next(), timeout: 1))
|
||||
|
|
|
@ -10,7 +10,7 @@ class RootViewModelTests: XCTestCase {
|
|||
|
||||
func testAddIdentity() throws {
|
||||
let sut = RootViewModel(appDelegate: AppDelegate(),
|
||||
identitiesService: IdentitiesService(
|
||||
allIdentitiesService: AllIdentitiesService(
|
||||
identityDatabase: .fresh(),
|
||||
environment: .development),
|
||||
userNotificationService: UserNotificationService())
|
||||
|
|
Loading…
Reference in New Issue