This commit is contained in:
Justin Mazzocchi 2020-10-06 13:44:22 -07:00
parent 538cbe42c3
commit a124c44eb1
No known key found for this signature in database
GPG Key ID: E223E6937AAFB01C
14 changed files with 44 additions and 44 deletions

View File

@ -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<Account, Error> {
func accountPublisher(id: Account.Id) -> AnyPublisher<Account, Error> {
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:)) }

View File

@ -152,7 +152,7 @@ public extension IdentityDatabase {
.eraseToAnyPublisher()
}
func identityObservation(id: Identity.Id, immediate: Bool) -> AnyPublisher<Identity, Error> {
func identityPublisher(id: Identity.Id, immediate: Bool) -> AnyPublisher<Identity, Error> {
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<Identity.Id?, Error> {
func immediateMostRecentlyUsedIdentityIdPublisher() -> AnyPublisher<Identity.Id?, Error> {
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)

View File

@ -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()

View File

@ -34,8 +34,8 @@ public extension AllIdentitiesService {
try IdentityService(id: id, database: database, environment: environment)
}
func immediateMostRecentlyUsedIdentityIdObservation() -> AnyPublisher<Identity.Id?, Error> {
database.immediateMostRecentlyUsedIdentityIdObservation()
func immediateMostRecentlyUsedIdentityIdPublisher() -> AnyPublisher<Identity.Id?, Error> {
database.immediateMostRecentlyUsedIdentityIdPublisher()
}
func createIdentity(url: URL, kind: IdentityCreation) -> AnyPublisher<Never, Error> {
@ -113,7 +113,7 @@ public extension AllIdentitiesService {
}
func updatePushSubscriptions(deviceToken: Data) -> AnyPublisher<Never, Error> {
database.identitiesWithOutdatedDeviceTokens(deviceToken: deviceToken)
database.fetchIdentitiesWithOutdatedDeviceTokens(deviceToken: deviceToken)
.tryMap { identities -> [AnyPublisher<Never, Never>] in
try identities.map {
try IdentityService(id: $0.id, database: database, environment: environment)

View File

@ -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)
}
}

View File

@ -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<Never, Error> {
@ -87,12 +87,12 @@ public extension IdentityService {
.eraseToAnyPublisher()
}
func observation(immediate: Bool) -> AnyPublisher<Identity, Error> {
identityDatabase.identityObservation(id: id, immediate: immediate)
func identityPublisher(immediate: Bool) -> AnyPublisher<Identity, Error> {
identityDatabase.identityPublisher(id: id, immediate: immediate)
}
func listsObservation() -> AnyPublisher<[Timeline], Error> {
contentDatabase.listsObservation()
func listsPublisher() -> AnyPublisher<[Timeline], Error> {
contentDatabase.listsPublisher()
}
func refreshFilters() -> AnyPublisher<Never, Error> {
@ -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<Never, Error> {

View File

@ -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

View File

@ -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()

View File

@ -8,12 +8,12 @@ public final class Identification: ObservableObject {
@Published private(set) public var identity: Identity
let service: IdentityService
init(identity: Identity, observation: AnyPublisher<Identity, Never>, service: IdentityService) {
init(identity: Identity, publisher: AnyPublisher<Identity, Never>, service: IdentityService) {
self.identity = identity
self.service = service
DispatchQueue.main.async {
observation.dropFirst().assign(to: &self.$identity)
publisher.dropFirst().assign(to: &self.$identity)
}
}
}

View File

@ -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)
}

View File

@ -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)
}
}

View File

@ -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 }

View File

@ -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)

View File

@ -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<Identity, Never> 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 {