feat: 接入消息未读数、全部已读与首页红点角标同步。

固定消息中心为首页入口,并在推送到达、已读后刷新桌面角标。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-21 18:02:43 +08:00
parent e7f1d777dd
commit caeeb9a1cf
18 changed files with 748 additions and 37 deletions

View File

@ -19,6 +19,12 @@ final class MessageCenterViewController: BaseViewController, UITableViewDelegate
private let loadingIndicator = UIActivityIndicatorView(style: .medium)
private let footerSpinner = UIActivityIndicatorView(style: .medium)
private let emptyLabel = UILabel()
private lazy var markAllReadButton = UIBarButtonItem(
title: "全部已读",
style: .plain,
target: self,
action: #selector(markAllReadTapped)
)
private var dataSource: UITableViewDiffableDataSource<Section, MessageItem>!
@ -46,6 +52,7 @@ final class MessageCenterViewController: BaseViewController, UITableViewDelegate
override func setupNavigationBar() {
title = "消息中心"
navigationItem.rightBarButtonItem = markAllReadButton
}
override func setupUI() {
@ -79,7 +86,8 @@ final class MessageCenterViewController: BaseViewController, UITableViewDelegate
override func setupConstraints() {
tableView.snp.makeConstraints { make in
make.edges.equalTo(view.safeAreaLayoutGuide)
make.top.equalTo(view.safeAreaLayoutGuide)
make.leading.trailing.bottom.equalToSuperview()
}
loadingIndicator.snp.makeConstraints { make in
make.center.equalToSuperview()
@ -103,6 +111,11 @@ final class MessageCenterViewController: BaseViewController, UITableViewDelegate
self?.openDetail(message)
}
}
viewModel.onUnreadMessageCountChange = { count in
Task { @MainActor in
await PushNotificationManager.shared.updateApplicationIconBadgeCount(count)
}
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
@ -125,6 +138,12 @@ final class MessageCenterViewController: BaseViewController, UITableViewDelegate
}
}
@objc private func markAllReadTapped() {
Task { @MainActor in
await viewModel.markAllAsRead(api: api)
}
}
private func configureDataSource() {
dataSource = UITableViewDiffableDataSource<Section, MessageItem>(tableView: tableView) { tableView, indexPath, item in
let cell = tableView.dequeueReusableCell(
@ -154,6 +173,7 @@ final class MessageCenterViewController: BaseViewController, UITableViewDelegate
}
tableView.tableFooterView = footerView()
markAllReadButton.isEnabled = !viewModel.isLoading && !viewModel.isMarkingAllAsRead
}
private func applySnapshot(animated: Bool) {