diff --git a/DB/Sources/DB/Content/ContentDatabase.swift b/DB/Sources/DB/Content/ContentDatabase.swift index cc8810e..0bc4495 100644 --- a/DB/Sources/DB/Content/ContentDatabase.swift +++ b/DB/Sources/DB/Content/ContentDatabase.swift @@ -215,7 +215,7 @@ public extension ContentDatabase { .eraseToAnyPublisher() } - func observation(timeline: Timeline) -> AnyPublisher<[[CollectionItem]], Error> { + func timelinePublisher(_ timeline: Timeline) -> AnyPublisher<[[CollectionItem]], Error> { ValueObservation.tracking( TimelineItemsInfo.request(TimelineRecord.filter(TimelineRecord.Columns.id == timeline.id)).fetchOne) .removeDuplicates() @@ -225,7 +225,7 @@ public extension ContentDatabase { .eraseToAnyPublisher() } - func contextObservation(id: Status.Id) -> AnyPublisher<[[CollectionItem]], Error> { + func contextPublisher(id: Status.Id) -> AnyPublisher<[[CollectionItem]], Error> { ValueObservation.tracking( ContextItemsInfo.request(StatusRecord.filter(StatusRecord.Columns.id == id)).fetchOne) .removeDuplicates() @@ -235,7 +235,7 @@ public extension ContentDatabase { .eraseToAnyPublisher() } - func listsObservation() -> AnyPublisher<[Timeline], Error> { + func listsPublisher() -> AnyPublisher<[Timeline], Error> { ValueObservation.tracking(TimelineRecord.filter(TimelineRecord.Columns.listId != nil) .order(TimelineRecord.Columns.listTitle.asc) .fetchAll) @@ -245,14 +245,14 @@ public extension ContentDatabase { .eraseToAnyPublisher() } - func expiredFiltersObservation() -> AnyPublisher<[Filter], Error> { + func expiredFiltersPublisher() -> AnyPublisher<[Filter], Error> { ValueObservation.tracking { try Filter.filter(Filter.Columns.expiresAt < Date()).fetchAll($0) } .removeDuplicates() .publisher(in: databaseWriter) .eraseToAnyPublisher() } - func accountObservation(id: Account.Id) -> AnyPublisher { + func accountPublisher(id: Account.Id) -> AnyPublisher { ValueObservation.tracking(AccountInfo.request(AccountRecord.filter(AccountRecord.Columns.id == id)).fetchOne) .removeDuplicates() .publisher(in: databaseWriter) @@ -261,7 +261,7 @@ public extension ContentDatabase { .eraseToAnyPublisher() } - func accountListObservation(_ list: AccountList) -> AnyPublisher<[Account], Error> { + func accountListPublisher(_ list: AccountList) -> AnyPublisher<[Account], Error> { ValueObservation.tracking(list.accounts.fetchAll) .removeDuplicates() .map { $0.map(Account.init(info:)) } diff --git a/DB/Sources/DB/Identity/IdentityDatabase.swift b/DB/Sources/DB/Identity/IdentityDatabase.swift index 15cd4b9..7e3a99b 100644 --- a/DB/Sources/DB/Identity/IdentityDatabase.swift +++ b/DB/Sources/DB/Identity/IdentityDatabase.swift @@ -152,7 +152,7 @@ public extension IdentityDatabase { .eraseToAnyPublisher() } - func identityObservation(id: Identity.Id, immediate: Bool) -> AnyPublisher { + func identityPublisher(id: Identity.Id, immediate: Bool) -> AnyPublisher { ValueObservation.tracking( IdentityInfo.request(IdentityRecord.filter(IdentityRecord.Columns.id == id)).fetchOne) .removeDuplicates() @@ -165,7 +165,7 @@ public extension IdentityDatabase { .eraseToAnyPublisher() } - func identitiesObservation() -> AnyPublisher<[Identity], Error> { + func identitiesPublisher() -> AnyPublisher<[Identity], Error> { ValueObservation.tracking( IdentityInfo.request(IdentityRecord.order(IdentityRecord.Columns.lastUsedAt.desc)).fetchAll) .removeDuplicates() @@ -174,7 +174,7 @@ public extension IdentityDatabase { .eraseToAnyPublisher() } - func recentIdentitiesObservation(excluding: Identity.Id) -> AnyPublisher<[Identity], Error> { + func recentIdentitiesPublisher(excluding: Identity.Id) -> AnyPublisher<[Identity], Error> { ValueObservation.tracking( IdentityInfo.request(IdentityRecord.order(IdentityRecord.Columns.lastUsedAt.desc)) .filter(IdentityRecord.Columns.id != excluding) @@ -186,7 +186,7 @@ public extension IdentityDatabase { .eraseToAnyPublisher() } - func immediateMostRecentlyUsedIdentityIdObservation() -> AnyPublisher { + func immediateMostRecentlyUsedIdentityIdPublisher() -> AnyPublisher { ValueObservation.tracking( IdentityRecord.select(IdentityRecord.Columns.id) .order(IdentityRecord.Columns.lastUsedAt.desc).fetchOne) @@ -195,7 +195,7 @@ public extension IdentityDatabase { .eraseToAnyPublisher() } - func identitiesWithOutdatedDeviceTokens(deviceToken: Data) -> AnyPublisher<[Identity], Error> { + func fetchIdentitiesWithOutdatedDeviceTokens(deviceToken: Data) -> AnyPublisher<[Identity], Error> { databaseWriter.readPublisher( value: IdentityInfo.request(IdentityRecord.order(IdentityRecord.Columns.lastUsedAt.desc)) .filter(IdentityRecord.Columns.lastRegisteredDeviceToken != deviceToken) diff --git a/ServiceLayer/Sources/ServiceLayer/Services/AccountListService.swift b/ServiceLayer/Sources/ServiceLayer/Services/AccountListService.swift index 2d020f8..56f6471 100644 --- a/ServiceLayer/Sources/ServiceLayer/Services/AccountListService.swift +++ b/ServiceLayer/Sources/ServiceLayer/Services/AccountListService.swift @@ -22,7 +22,7 @@ public struct AccountListService { self.endpoint = endpoint self.mastodonAPIClient = mastodonAPIClient self.contentDatabase = contentDatabase - sections = contentDatabase.accountListObservation(list) + sections = contentDatabase.accountListPublisher(list) .map { [$0.map(CollectionItem.account)] } .eraseToAnyPublisher() nextPageMaxId = nextPageMaxIdSubject.eraseToAnyPublisher() diff --git a/ServiceLayer/Sources/ServiceLayer/Services/AllIdentitiesService.swift b/ServiceLayer/Sources/ServiceLayer/Services/AllIdentitiesService.swift index 59c82b8..5a6acdc 100644 --- a/ServiceLayer/Sources/ServiceLayer/Services/AllIdentitiesService.swift +++ b/ServiceLayer/Sources/ServiceLayer/Services/AllIdentitiesService.swift @@ -34,8 +34,8 @@ public extension AllIdentitiesService { try IdentityService(id: id, database: database, environment: environment) } - func immediateMostRecentlyUsedIdentityIdObservation() -> AnyPublisher { - database.immediateMostRecentlyUsedIdentityIdObservation() + func immediateMostRecentlyUsedIdentityIdPublisher() -> AnyPublisher { + database.immediateMostRecentlyUsedIdentityIdPublisher() } func createIdentity(url: URL, kind: IdentityCreation) -> AnyPublisher { @@ -113,7 +113,7 @@ public extension AllIdentitiesService { } func updatePushSubscriptions(deviceToken: Data) -> AnyPublisher { - database.identitiesWithOutdatedDeviceTokens(deviceToken: deviceToken) + database.fetchIdentitiesWithOutdatedDeviceTokens(deviceToken: deviceToken) .tryMap { identities -> [AnyPublisher] in try identities.map { try IdentityService(id: $0.id, database: database, environment: environment) diff --git a/ServiceLayer/Sources/ServiceLayer/Services/ContextService.swift b/ServiceLayer/Sources/ServiceLayer/Services/ContextService.swift index eed2697..e568882 100644 --- a/ServiceLayer/Sources/ServiceLayer/Services/ContextService.swift +++ b/ServiceLayer/Sources/ServiceLayer/Services/ContextService.swift @@ -18,7 +18,7 @@ public struct ContextService { self.id = id self.mastodonAPIClient = mastodonAPIClient self.contentDatabase = contentDatabase - sections = contentDatabase.contextObservation(id: id) + sections = contentDatabase.contextPublisher(id: id) navigationService = NavigationService(mastodonAPIClient: mastodonAPIClient, contentDatabase: contentDatabase) } } diff --git a/ServiceLayer/Sources/ServiceLayer/Services/IdentityService.swift b/ServiceLayer/Sources/ServiceLayer/Services/IdentityService.swift index 5e6514f..bea9a92 100644 --- a/ServiceLayer/Sources/ServiceLayer/Services/IdentityService.swift +++ b/ServiceLayer/Sources/ServiceLayer/Services/IdentityService.swift @@ -60,12 +60,12 @@ public extension IdentityService { identityDatabase.confirmIdentity(id: id) } - func identitiesObservation() -> AnyPublisher<[Identity], Error> { - identityDatabase.identitiesObservation() + func identitiesPublisher() -> AnyPublisher<[Identity], Error> { + identityDatabase.identitiesPublisher() } - func recentIdentitiesObservation() -> AnyPublisher<[Identity], Error> { - identityDatabase.recentIdentitiesObservation(excluding: id) + func recentIdentitiesPublisher() -> AnyPublisher<[Identity], Error> { + identityDatabase.recentIdentitiesPublisher(excluding: id) } func refreshLists() -> AnyPublisher { @@ -87,12 +87,12 @@ public extension IdentityService { .eraseToAnyPublisher() } - func observation(immediate: Bool) -> AnyPublisher { - identityDatabase.identityObservation(id: id, immediate: immediate) + func identityPublisher(immediate: Bool) -> AnyPublisher { + identityDatabase.identityPublisher(id: id, immediate: immediate) } - func listsObservation() -> AnyPublisher<[Timeline], Error> { - contentDatabase.listsObservation() + func listsPublisher() -> AnyPublisher<[Timeline], Error> { + contentDatabase.listsPublisher() } func refreshFilters() -> AnyPublisher { @@ -128,12 +128,12 @@ public extension IdentityService { .eraseToAnyPublisher() } - func activeFiltersObservation() -> AnyPublisher<[Filter], Error> { + func activeFiltersPublisher() -> AnyPublisher<[Filter], Error> { contentDatabase.activeFiltersPublisher } - func expiredFiltersObservation() -> AnyPublisher<[Filter], Error> { - contentDatabase.expiredFiltersObservation() + func expiredFiltersPublisher() -> AnyPublisher<[Filter], Error> { + contentDatabase.expiredFiltersPublisher() } func updatePreferences(_ preferences: Identity.Preferences) -> AnyPublisher { diff --git a/ServiceLayer/Sources/ServiceLayer/Services/ProfileService.swift b/ServiceLayer/Sources/ServiceLayer/Services/ProfileService.swift index 0b290df..41ce6ff 100644 --- a/ServiceLayer/Sources/ServiceLayer/Services/ProfileService.swift +++ b/ServiceLayer/Sources/ServiceLayer/Services/ProfileService.swift @@ -34,7 +34,7 @@ public struct ProfileService { self.mastodonAPIClient = mastodonAPIClient self.contentDatabase = contentDatabase - var accountPublisher = contentDatabase.accountObservation(id: id) + var accountPublisher = contentDatabase.accountPublisher(id: id) if let account = account { accountPublisher = accountPublisher diff --git a/ServiceLayer/Sources/ServiceLayer/Services/TimelineService.swift b/ServiceLayer/Sources/ServiceLayer/Services/TimelineService.swift index 092485f..e1cc3bb 100644 --- a/ServiceLayer/Sources/ServiceLayer/Services/TimelineService.swift +++ b/ServiceLayer/Sources/ServiceLayer/Services/TimelineService.swift @@ -21,7 +21,7 @@ public struct TimelineService { self.timeline = timeline self.mastodonAPIClient = mastodonAPIClient self.contentDatabase = contentDatabase - sections = contentDatabase.observation(timeline: timeline) + sections = contentDatabase.timelinePublisher(timeline) navigationService = NavigationService(mastodonAPIClient: mastodonAPIClient, contentDatabase: contentDatabase) nextPageMaxId = nextPageMaxIdSubject.eraseToAnyPublisher() diff --git a/ViewModels/Sources/ViewModels/Entities/Identification.swift b/ViewModels/Sources/ViewModels/Entities/Identification.swift index f8a6c39..13e333c 100644 --- a/ViewModels/Sources/ViewModels/Entities/Identification.swift +++ b/ViewModels/Sources/ViewModels/Entities/Identification.swift @@ -8,12 +8,12 @@ public final class Identification: ObservableObject { @Published private(set) public var identity: Identity let service: IdentityService - init(identity: Identity, observation: AnyPublisher, service: IdentityService) { + init(identity: Identity, publisher: AnyPublisher, service: IdentityService) { self.identity = identity self.service = service DispatchQueue.main.async { - observation.dropFirst().assign(to: &self.$identity) + publisher.dropFirst().assign(to: &self.$identity) } } } diff --git a/ViewModels/Sources/ViewModels/FiltersViewModel.swift b/ViewModels/Sources/ViewModels/FiltersViewModel.swift index be6d01c..d2743c6 100644 --- a/ViewModels/Sources/ViewModels/FiltersViewModel.swift +++ b/ViewModels/Sources/ViewModels/FiltersViewModel.swift @@ -16,11 +16,11 @@ public final class FiltersViewModel: ObservableObject { public init(identification: Identification) { self.identification = identification - identification.service.activeFiltersObservation() + identification.service.activeFiltersPublisher() .assignErrorsToAlertItem(to: \.alertItem, on: self) .assign(to: &$activeFilters) - identification.service.expiredFiltersObservation() + identification.service.expiredFiltersPublisher() .assignErrorsToAlertItem(to: \.alertItem, on: self) .assign(to: &$expiredFilters) } diff --git a/ViewModels/Sources/ViewModels/IdentitiesViewModel.swift b/ViewModels/Sources/ViewModels/IdentitiesViewModel.swift index 566d983..f389142 100644 --- a/ViewModels/Sources/ViewModels/IdentitiesViewModel.swift +++ b/ViewModels/Sources/ViewModels/IdentitiesViewModel.swift @@ -18,15 +18,15 @@ public final class IdentitiesViewModel: ObservableObject { self.identification = identification currentIdentityId = identification.identity.id - let observation = identification.service.identitiesObservation() + let identitiesPublisher = identification.service.identitiesPublisher() .assignErrorsToAlertItem(to: \.alertItem, on: self) .share() - observation.map { $0.filter { $0.authenticated && !$0.pending } } + identitiesPublisher.map { $0.filter { $0.authenticated && !$0.pending } } .assign(to: &$authenticated) - observation.map { $0.filter { !$0.authenticated && !$0.pending } } + identitiesPublisher.map { $0.filter { !$0.authenticated && !$0.pending } } .assign(to: &$unauthenticated) - observation.map { $0.filter { $0.pending } } + identitiesPublisher.map { $0.filter { $0.pending } } .assign(to: &$pending) } } diff --git a/ViewModels/Sources/ViewModels/ListsViewModel.swift b/ViewModels/Sources/ViewModels/ListsViewModel.swift index e3d5291..c100762 100644 --- a/ViewModels/Sources/ViewModels/ListsViewModel.swift +++ b/ViewModels/Sources/ViewModels/ListsViewModel.swift @@ -16,7 +16,7 @@ public final class ListsViewModel: ObservableObject { public init(identification: Identification) { self.identification = identification - identification.service.listsObservation() + identification.service.listsPublisher() .map { $0.compactMap { guard case let .list(list) = $0 else { return nil } diff --git a/ViewModels/Sources/ViewModels/NavigationViewModel.swift b/ViewModels/Sources/ViewModels/NavigationViewModel.swift index 9998db1..6b656b4 100644 --- a/ViewModels/Sources/ViewModels/NavigationViewModel.swift +++ b/ViewModels/Sources/ViewModels/NavigationViewModel.swift @@ -27,12 +27,12 @@ public final class NavigationViewModel: ObservableObject { .sink { [weak self] _ in self?.objectWillChange.send() } .store(in: &cancellables) - identification.service.recentIdentitiesObservation() + identification.service.recentIdentitiesPublisher() .assignErrorsToAlertItem(to: \.alertItem, on: self) .assign(to: &$recentIdentities) if identification.identity.authenticated { - identification.service.listsObservation() + identification.service.listsPublisher() .map { Timeline.authenticatedDefaults + $0 } .assignErrorsToAlertItem(to: \.alertItem, on: self) .assign(to: &$timelinesAndLists) diff --git a/ViewModels/Sources/ViewModels/RootViewModel.swift b/ViewModels/Sources/ViewModels/RootViewModel.swift index a927b9f..22e44ae 100644 --- a/ViewModels/Sources/ViewModels/RootViewModel.swift +++ b/ViewModels/Sources/ViewModels/RootViewModel.swift @@ -21,7 +21,7 @@ public final class RootViewModel: ObservableObject { userNotificationService = UserNotificationService(environment: environment) self.registerForRemoteNotifications = registerForRemoteNotifications - allIdentitiesService.immediateMostRecentlyUsedIdentityIdObservation() + allIdentitiesService.immediateMostRecentlyUsedIdentityIdPublisher() .replaceError(with: nil) .assign(to: &$mostRecentlyUsedIdentityId) @@ -71,7 +71,7 @@ private extension RootViewModel { return } - let observation = identityService.observation(immediate: immediate) + let identityPublisher = identityService.identityPublisher(immediate: immediate) .catch { [weak self] _ -> Empty in DispatchQueue.main.async { self?.identitySelected(id: self?.mostRecentlyUsedIdentityId, immediate: false) @@ -81,12 +81,12 @@ private extension RootViewModel { } .share() - observation + identityPublisher .filter { [weak self] in $0.id != self?.navigationViewModel?.identification.identity.id } .map { [weak self] in let identification = Identification( identity: $0, - observation: observation.eraseToAnyPublisher(), + publisher: identityPublisher.eraseToAnyPublisher(), service: identityService) if let self = self {