fix: add notification count clear logic back

This commit is contained in:
CMK 2022-02-10 16:43:07 +08:00
parent ca4406e941
commit e7816f365f
2 changed files with 10 additions and 194 deletions

View File

@ -113,19 +113,6 @@ extension HomeTimelineViewController {
self.showEmptyView() 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( UIAction(
title: "Enable account switcher wizard", title: "Enable account switcher wizard",
image: UIImage(systemName: "square.stack.3d.down.forward.fill"), image: UIImage(systemName: "square.stack.3d.down.forward.fill"),
@ -147,6 +134,12 @@ extension HomeTimelineViewController {
identifier: nil, identifier: nil,
options: [], options: [],
children: [ 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 UIAction(title: "Profile", image: UIImage(systemName: "person.badge.plus"), attributes: []) { [weak self] action in
guard let self = self else { return } guard let self = self else { return }
self.showNotification(action, notificationType: .follow) self.showNotification(action, notificationType: .follow)
@ -264,147 +257,6 @@ extension HomeTimelineViewController {
FLEXManager.shared.showExplorer() 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) { @objc private func dropRecentStatusAction(_ sender: UIAction, count: Int) {
guard let diffableDataSource = viewModel.diffableDataSource else { return } guard let diffableDataSource = viewModel.diffableDataSource else { return }
let snapshot = diffableDataSource.snapshot() let snapshot = diffableDataSource.snapshot()

View File

@ -210,15 +210,15 @@ extension NotificationViewController {
// } // }
// } // }
// //
// // reset notification count // reset notification count
// context.notificationService.clearNotificationCountForActiveUser() context.notificationService.clearNotificationCountForActiveUser()
} }
override func viewWillDisappear(_ animated: Bool) { override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated) super.viewWillDisappear(animated)
// // reset notification count // reset notification count
// context.notificationService.clearNotificationCountForActiveUser() context.notificationService.clearNotificationCountForActiveUser()
} }
override func viewDidDisappear(_ animated: Bool) { override func viewDidDisappear(_ animated: Bool) {
@ -265,42 +265,6 @@ extension NotificationViewController {
} }
} }
//// MARK: - TableViewCellHeightCacheableContainer
//extension NotificationViewController: TableViewCellHeightCacheableContainer {
// var cellFrameCache: NSCache<NSNumber, NSValue> { 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 // MARK: - UITableViewDelegate
extension NotificationViewController: UITableViewDelegate { extension NotificationViewController: UITableViewDelegate {