From 50f37a8ec62a0319a420e9487823f7537d16e713 Mon Sep 17 00:00:00 2001 From: CMK Date: Fri, 1 Jul 2022 14:08:46 +0800 Subject: [PATCH] chore: clean up --- .../HomeTimelineViewModel+Diffable.swift | 133 ------------------ .../Notification/NotificationViewModel.swift | 36 ----- 2 files changed, 169 deletions(-) diff --git a/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+Diffable.swift b/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+Diffable.swift index 756a4b608..35f44683a 100644 --- a/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+Diffable.swift +++ b/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+Diffable.swift @@ -180,136 +180,3 @@ extension HomeTimelineViewModel { } } - - - - -//// MARK: - NSFetchedResultsControllerDelegate -//extension HomeTimelineViewModel: NSFetchedResultsControllerDelegate { -// -// func controllerWillChangeContent(_ controller: NSFetchedResultsController) { -// os_log("%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function) -// } -// -// func controller(_ controller: NSFetchedResultsController, didChangeContentWith snapshot: NSDiffableDataSourceSnapshotReference) { -// os_log("%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function) -// -// guard let tableView = self.tableView else { return } -// guard let navigationBar = self.contentOffsetAdjustableTimelineViewControllerDelegate?.navigationBar() else { return } -// -// guard let diffableDataSource = self.diffableDataSource else { return } -// let oldSnapshot = diffableDataSource.snapshot() -// -// let predicate = fetchedResultsController.fetchRequest.predicate -// let parentManagedObjectContext = fetchedResultsController.managedObjectContext -// let managedObjectContext = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType) -// managedObjectContext.parent = parentManagedObjectContext -// -// managedObjectContext.perform { -// var shouldAddBottomLoader = false -// -// let timelineIndexes: [HomeTimelineIndex] = { -// let request = HomeTimelineIndex.sortedFetchRequest -// request.returnsObjectsAsFaults = false -// request.predicate = predicate -// do { -// return try managedObjectContext.fetch(request) -// } catch { -// assertionFailure(error.localizedDescription) -// return [] -// } -// }() -// -// // that's will be the most fastest fetch because of upstream just update and no modify needs consider -// -// var oldSnapshotAttributeDict: [NSManagedObjectID : Item.StatusAttribute] = [:] -// -// for item in oldSnapshot.itemIdentifiers { -// guard case let .homeTimelineIndex(objectID, attribute) = item else { continue } -// oldSnapshotAttributeDict[objectID] = attribute -// } -// -// var newTimelineItems: [Item] = [] -// -// for (i, timelineIndex) in timelineIndexes.enumerated() { -// let attribute = oldSnapshotAttributeDict[timelineIndex.objectID] ?? Item.StatusAttribute() -// attribute.isSeparatorLineHidden = false -// -// // append new item into snapshot -// newTimelineItems.append(.homeTimelineIndex(objectID: timelineIndex.objectID, attribute: attribute)) -// -// let isLast = i == timelineIndexes.count - 1 -// switch (isLast, timelineIndex.hasMore) { -// case (false, true): -// newTimelineItems.append(.homeMiddleLoader(upperTimelineIndexAnchorObjectID: timelineIndex.objectID)) -// attribute.isSeparatorLineHidden = true -// case (true, true): -// shouldAddBottomLoader = true -// default: -// break -// } -// } // end for -// -// var newSnapshot = NSDiffableDataSourceSnapshot() -// newSnapshot.appendSections([.main]) -// newSnapshot.appendItems(newTimelineItems, toSection: .main) -// -// let endSnapshot = CACurrentMediaTime() -// -// DispatchQueue.main.async { -// if shouldAddBottomLoader, !(self.loadLatestStateMachine.currentState is LoadOldestState.NoMore) { -// newSnapshot.appendItems([.bottomLoader], toSection: .main) -// } -// -// guard let difference = self.calculateReloadSnapshotDifference(navigationBar: navigationBar, tableView: tableView, oldSnapshot: oldSnapshot, newSnapshot: newSnapshot) else { -// diffableDataSource.apply(newSnapshot) -// self.isFetchingLatestTimeline.value = false -// return -// } -// -// diffableDataSource.reloadData(snapshot: newSnapshot) { -// tableView.scrollToRow(at: difference.targetIndexPath, at: .top, animated: false) -// tableView.contentOffset.y = tableView.contentOffset.y - difference.offset -// self.isFetchingLatestTimeline.value = false -// } -// -// let end = CACurrentMediaTime() -// os_log("%{public}s[%{public}ld], %{public}s: calculate home timeline layout cost %.2fs", ((#file as NSString).lastPathComponent), #line, #function, end - endSnapshot) -// } -// } // end perform -// } -// -// private struct Difference { -// let item: T -// let sourceIndexPath: IndexPath -// let targetIndexPath: IndexPath -// let offset: CGFloat -// } -// -// private func calculateReloadSnapshotDifference( -// navigationBar: UINavigationBar, -// tableView: UITableView, -// oldSnapshot: NSDiffableDataSourceSnapshot, -// newSnapshot: NSDiffableDataSourceSnapshot -// ) -> Difference? { -// guard oldSnapshot.numberOfItems != 0 else { return nil } -// -// // old snapshot not empty. set source index path to first item if not match -// let sourceIndexPath = UIViewController.topVisibleTableViewCellIndexPath(in: tableView, navigationBar: navigationBar) ?? IndexPath(row: 0, section: 0) -// -// guard sourceIndexPath.row < oldSnapshot.itemIdentifiers(inSection: .main).count else { return nil } -// -// let timelineItem = oldSnapshot.itemIdentifiers(inSection: .main)[sourceIndexPath.row] -// guard let itemIndex = newSnapshot.itemIdentifiers(inSection: .main).firstIndex(of: timelineItem) else { return nil } -// let targetIndexPath = IndexPath(row: itemIndex, section: 0) -// -// let offset = UIViewController.tableViewCellOriginOffsetToWindowTop(in: tableView, at: sourceIndexPath, navigationBar: navigationBar) -// return Difference( -// item: timelineItem, -// sourceIndexPath: sourceIndexPath, -// targetIndexPath: targetIndexPath, -// offset: offset -// ) -// } -// -//} diff --git a/Mastodon/Scene/Notification/NotificationViewModel.swift b/Mastodon/Scene/Notification/NotificationViewModel.swift index 3d4fa6042..60967c436 100644 --- a/Mastodon/Scene/Notification/NotificationViewModel.swift +++ b/Mastodon/Scene/Notification/NotificationViewModel.swift @@ -43,42 +43,6 @@ extension NotificationTimelineViewModel.Scope { } } -// func acceptFollowRequest(notification: MastodonNotification) { -// guard let activeMastodonAuthenticationBox = self.activeMastodonAuthenticationBox.value else { return } -// context.apiService.acceptFollowRequest(mastodonUserID: notification.account.id, mastodonAuthenticationBox: activeMastodonAuthenticationBox) -// .sink { [weak self] completion in -// switch completion { -// case .failure(let error): -// os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: accept FollowRequest fail: %s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription) -// case .finished: -// break -//// self?.loadLatestStateMachine.enter(NotificationViewModel.LoadLatestState.Loading.self) -// } -// } receiveValue: { _ in -// -// } -// .store(in: &disposeBag) -// } -// -// func rejectFollowRequest(notification: MastodonNotification) { -// guard let activeMastodonAuthenticationBox = self.activeMastodonAuthenticationBox.value else { return } -// context.apiService.rejectFollowRequest(mastodonUserID: notification.account.id, mastodonAuthenticationBox: activeMastodonAuthenticationBox) -// .sink { [weak self] completion in -// switch completion { -// case .failure(let error): -// os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: reject FollowRequest fail: %s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription) -// case .finished: -// break -//// self?.loadLatestStateMachine.enter(NotificationViewModel.LoadLatestState.Loading.self) -// } -// } receiveValue: { _ in -// -// } -// .store(in: &disposeBag) -// } -//} - - // MARK: - PageboyViewControllerDataSource extension NotificationViewModel: PageboyViewControllerDataSource {