feat: add notification gap fetcher
This commit is contained in:
parent
bdf7114fef
commit
8cd409de86
|
@ -49,8 +49,10 @@ extension NotificationSection {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return cell
|
return cell
|
||||||
case .feedLoader(let record):
|
case .feedLoader:
|
||||||
return UITableViewCell()
|
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as! TimelineBottomLoaderTableViewCell
|
||||||
|
cell.activityIndicatorView.startAnimating()
|
||||||
|
return cell
|
||||||
case .bottomLoader:
|
case .bottomLoader:
|
||||||
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as! TimelineBottomLoaderTableViewCell
|
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as! TimelineBottomLoaderTableViewCell
|
||||||
cell.activityIndicatorView.startAnimating()
|
cell.activityIndicatorView.startAnimating()
|
||||||
|
|
|
@ -135,6 +135,18 @@ extension NotificationTimelineViewController: UITableViewDelegate, AutoGenerateT
|
||||||
}
|
}
|
||||||
|
|
||||||
// sourcery:end
|
// sourcery:end
|
||||||
|
|
||||||
|
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
|
||||||
|
guard let item = viewModel.diffableDataSource?.itemIdentifier(for: indexPath) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// check item type inside `loadMore`
|
||||||
|
Task {
|
||||||
|
await viewModel.loadMore(item: item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - NotificationTableViewCellDelegate
|
// MARK: - NotificationTableViewCellDelegate
|
||||||
|
|
|
@ -156,4 +156,35 @@ extension NotificationTimelineViewModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load timeline gap
|
||||||
|
func loadMore(item: NotificationItem) async {
|
||||||
|
guard case let .feedLoader(record) = item else { return }
|
||||||
|
guard let authenticationBox = context.authenticationService.activeMastodonAuthenticationBox.value else { return }
|
||||||
|
|
||||||
|
let managedObjectContext = context.managedObjectContext
|
||||||
|
let key = "LoadMore@\(record.objectID)"
|
||||||
|
|
||||||
|
// return when already loading state
|
||||||
|
guard managedObjectContext.cache(froKey: key) == nil else { return }
|
||||||
|
|
||||||
|
guard let feed = record.object(in: managedObjectContext) else { return }
|
||||||
|
guard let maxID = feed.notification?.id else { return }
|
||||||
|
// keep transient property live
|
||||||
|
managedObjectContext.cache(feed, key: key)
|
||||||
|
defer {
|
||||||
|
managedObjectContext.cache(nil, key: key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetch data
|
||||||
|
do {
|
||||||
|
_ = try await context.apiService.notifications(
|
||||||
|
maxID: maxID,
|
||||||
|
scope: scope,
|
||||||
|
authenticationBox: authenticationBox
|
||||||
|
)
|
||||||
|
} catch {
|
||||||
|
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): fetch more failure: \(error.localizedDescription)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue