diff --git a/Mastodon/Scene/HomeTimeline/HomeTimelineViewController+DebugAction.swift b/Mastodon/Scene/HomeTimeline/HomeTimelineViewController+DebugAction.swift index eb3e6fc04..bbeebb72f 100644 --- a/Mastodon/Scene/HomeTimeline/HomeTimelineViewController+DebugAction.swift +++ b/Mastodon/Scene/HomeTimeline/HomeTimelineViewController+DebugAction.swift @@ -113,19 +113,6 @@ extension HomeTimelineViewController { self.showEmptyView() } }, - UIAction( - title: "Notification badge +1", - image: UIImage(systemName: "1.circle.fill"), - identifier: nil, - attributes: [], - state: .off, - handler: { [weak self] _ in - guard let self = self else { return } - guard let accessToken = self.context.authenticationService.activeMastodonAuthentication.value?.userAccessToken else { return } - UserDefaults.shared.increaseNotificationCount(accessToken: accessToken) - self.context.notificationService.applicationIconBadgeNeedsUpdate.send() - } - ), UIAction( title: "Enable account switcher wizard", image: UIImage(systemName: "square.stack.3d.down.forward.fill"), @@ -147,6 +134,12 @@ extension HomeTimelineViewController { identifier: nil, options: [], children: [ + UIAction(title: "Badge +1", image: UIImage(systemName: "app.badge.fill"), attributes: []) { [weak self] action in + guard let self = self else { return } + guard let accessToken = self.context.authenticationService.activeMastodonAuthentication.value?.userAccessToken else { return } + UserDefaults.shared.increaseNotificationCount(accessToken: accessToken) + self.context.notificationService.applicationIconBadgeNeedsUpdate.send() + }, UIAction(title: "Profile", image: UIImage(systemName: "person.badge.plus"), attributes: []) { [weak self] action in guard let self = self else { return } self.showNotification(action, notificationType: .follow) @@ -264,147 +257,6 @@ extension HomeTimelineViewController { FLEXManager.shared.showExplorer() } -// @objc private func moveToTopGapAction(_ sender: UIAction) { -// guard let diffableDataSource = viewModel.diffableDataSource else { return } -// let snapshotTransitioning = diffableDataSource.snapshot() -// let item = snapshotTransitioning.itemIdentifiers.first(where: { item in -// switch item { -// case .feedLoader: return true -// default: return false -// } -// }) -// if let targetItem = item, let index = snapshotTransitioning.indexOfItem(targetItem) { -// tableView.scrollToRow(at: IndexPath(row: index, section: 0), at: .middle, animated: true) -// } -// } -// -// @objc private func moveToFirstReblogStatus(_ sender: UIAction) { -// guard let diffableDataSource = viewModel.diffableDataSource else { return } -// let snapshotTransitioning = diffableDataSource.snapshot() -// let item = snapshotTransitioning.itemIdentifiers.first(where: { item in -// switch item { -//// case .homeTimelineIndex(let objectID, _): -//// let homeTimelineIndex = viewModel.fetchedResultsController.managedObjectContext.object(with: objectID) as! HomeTimelineIndex -//// return homeTimelineIndex.status.reblog != nil -// default: -// return false -// } -// }) -// if let targetItem = item, let index = snapshotTransitioning.indexOfItem(targetItem) { -// tableView.scrollToRow(at: IndexPath(row: index, section: 0), at: .middle, animated: true) -// tableView.blinkRow(at: IndexPath(row: index, section: 0)) -// } else { -// print("Not found reblog status") -// } -// } -// -// @objc private func moveToFirstPollStatus(_ sender: UIAction) { -// guard let diffableDataSource = viewModel.diffableDataSource else { return } -// let snapshotTransitioning = diffableDataSource.snapshot() -// let item = snapshotTransitioning.itemIdentifiers.first(where: { item in -// switch item { -// case .feed(let record): -// guard let feed = record.object(in: context.managedObjectContext) else { return false } -// guard let status = feed.status?.reblog ?? feed.status else { return false } -// return status.poll != nil -// default: -// return false -// } -// }) -// if let targetItem = item, let index = snapshotTransitioning.indexOfItem(targetItem) { -// tableView.scrollToRow(at: IndexPath(row: index, section: 0), at: .middle, animated: true) -// tableView.blinkRow(at: IndexPath(row: index, section: 0)) -// } else { -// print("Not found poll status") -// } -// } -// -// @objc private func moveToFirstRepliedStatus(_ sender: UIAction) { -// guard let diffableDataSource = viewModel.diffableDataSource else { return } -// let snapshotTransitioning = diffableDataSource.snapshot() -// let item = snapshotTransitioning.itemIdentifiers.first(where: { item in -// switch item { -//// case .homeTimelineIndex(let objectID, _): -//// let homeTimelineIndex = viewModel.fetchedResultsController.managedObjectContext.object(with: objectID) as! HomeTimelineIndex -//// guard homeTimelineIndex.status.inReplyToID != nil else { -//// return false -//// } -//// return true -// default: -// return false -// } -// }) -// if let targetItem = item, let index = snapshotTransitioning.indexOfItem(targetItem) { -// tableView.scrollToRow(at: IndexPath(row: index, section: 0), at: .middle, animated: true) -// tableView.blinkRow(at: IndexPath(row: index, section: 0)) -// } else { -// print("Not found replied status") -// } -// } -// -// @objc private func moveToFirstAudioStatus(_ sender: UIAction) { -// guard let diffableDataSource = viewModel.diffableDataSource else { return } -// let snapshotTransitioning = diffableDataSource.snapshot() -// let item = snapshotTransitioning.itemIdentifiers.first(where: { item in -// switch item { -//// case .homeTimelineIndex(let objectID, _): -//// let homeTimelineIndex = viewModel.fetchedResultsController.managedObjectContext.object(with: objectID) as! HomeTimelineIndex -//// let status = homeTimelineIndex.status.reblog ?? homeTimelineIndex.status -//// return status.mediaAttachments?.contains(where: { $0.type == .audio }) ?? false -// default: -// return false -// } -// }) -// if let targetItem = item, let index = snapshotTransitioning.indexOfItem(targetItem) { -// tableView.scrollToRow(at: IndexPath(row: index, section: 0), at: .middle, animated: true) -// tableView.blinkRow(at: IndexPath(row: index, section: 0)) -// } else { -// print("Not found audio status") -// } -// } -// -// @objc private func moveToFirstVideoStatus(_ sender: UIAction) { -// guard let diffableDataSource = viewModel.diffableDataSource else { return } -// let snapshotTransitioning = diffableDataSource.snapshot() -// let item = snapshotTransitioning.itemIdentifiers.first(where: { item in -// switch item { -//// case .homeTimelineIndex(let objectID, _): -//// let homeTimelineIndex = viewModel.fetchedResultsController.managedObjectContext.object(with: objectID) as! HomeTimelineIndex -//// let status = homeTimelineIndex.status.reblog ?? homeTimelineIndex.status -//// return status.mediaAttachments?.contains(where: { $0.type == .video }) ?? false -// default: -// return false -// } -// }) -// if let targetItem = item, let index = snapshotTransitioning.indexOfItem(targetItem) { -// tableView.scrollToRow(at: IndexPath(row: index, section: 0), at: .middle, animated: true) -// tableView.blinkRow(at: IndexPath(row: index, section: 0)) -// } else { -// print("Not found video status") -// } -// } -// -// @objc private func moveToFirstGIFStatus(_ sender: UIAction) { -// guard let diffableDataSource = viewModel.diffableDataSource else { return } -// let snapshotTransitioning = diffableDataSource.snapshot() -// let item = snapshotTransitioning.itemIdentifiers.first(where: { item in -// switch item { -//// case .homeTimelineIndex(let objectID, _): -//// let homeTimelineIndex = viewModel.fetchedResultsController.managedObjectContext.object(with: objectID) as! HomeTimelineIndex -//// let status = homeTimelineIndex.status.reblog ?? homeTimelineIndex.status -//// return status.mediaAttachments?.contains(where: { $0.type == .gifv }) ?? false -// default: -// return false -// } -// }) -// if let targetItem = item, let index = snapshotTransitioning.indexOfItem(targetItem) { -// tableView.scrollToRow(at: IndexPath(row: index, section: 0), at: .middle, animated: true) -// tableView.blinkRow(at: IndexPath(row: index, section: 0)) -// } else { -// print("Not found GIF status") -// } -// } - @objc private func dropRecentStatusAction(_ sender: UIAction, count: Int) { guard let diffableDataSource = viewModel.diffableDataSource else { return } let snapshot = diffableDataSource.snapshot() diff --git a/Mastodon/Scene/Notification/NotificationViewController.swift b/Mastodon/Scene/Notification/NotificationViewController.swift index 85e534cb6..aa49680a3 100644 --- a/Mastodon/Scene/Notification/NotificationViewController.swift +++ b/Mastodon/Scene/Notification/NotificationViewController.swift @@ -210,15 +210,15 @@ extension NotificationViewController { // } // } // -// // reset notification count -// context.notificationService.clearNotificationCountForActiveUser() + // reset notification count + context.notificationService.clearNotificationCountForActiveUser() } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) -// // reset notification count -// context.notificationService.clearNotificationCountForActiveUser() + // reset notification count + context.notificationService.clearNotificationCountForActiveUser() } override func viewDidDisappear(_ animated: Bool) { @@ -265,42 +265,6 @@ extension NotificationViewController { } } - -//// MARK: - TableViewCellHeightCacheableContainer -//extension NotificationViewController: TableViewCellHeightCacheableContainer { -// var cellFrameCache: NSCache { return viewModel.cellFrameCache } -// -// func cacheTableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) { -// guard let diffableDataSource = viewModel.diffableDataSource else { return } -// guard let item = diffableDataSource.itemIdentifier(for: indexPath) else { return } -// switch item { -// case .notification(let objectID, _), -// .notificationStatus(let objectID, _): -// guard let object = try? viewModel.fetchedResultsController.managedObjectContext.existingObject(with: objectID) as? MastodonNotification else { return } -// let key = object.objectID.hashValue -// let frame = cell.frame -// viewModel.cellFrameCache.setObject(NSValue(cgRect: frame), forKey: NSNumber(value: key)) -// case .bottomLoader: -// break -// } -// } -// -// func handleTableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { -// guard let diffableDataSource = viewModel.diffableDataSource else { return UITableView.automaticDimension } -// guard let item = diffableDataSource.itemIdentifier(for: indexPath) else { return UITableView.automaticDimension } -// switch item { -// case .notification(let objectID, _), -// .notificationStatus(let objectID, _): -// guard let object = try? viewModel.fetchedResultsController.managedObjectContext.existingObject(with: objectID) as? MastodonNotification else { return UITableView.automaticDimension } -// let key = object.objectID.hashValue -// guard let frame = viewModel.cellFrameCache.object(forKey: NSNumber(value: key))?.cgRectValue else { return UITableView.automaticDimension } -// return frame.height -// case .bottomLoader: -// return TimelineLoaderTableViewCell.cellHeight -// } -// } -//} - // MARK: - UITableViewDelegate extension NotificationViewController: UITableViewDelegate {