Cleanup (IOS-241)

This commit is contained in:
Nathan Mattes 2024-07-24 12:34:50 +02:00
parent b3bfa5101b
commit 86aa92da0b
3 changed files with 35 additions and 40 deletions

View File

@ -37,7 +37,6 @@ class NotificationFilteringBannerTableViewCell: UITableViewCell {
subtitleLabel.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15, weight: .regular))
subtitleLabel.textColor = .secondaryLabel
labelStackView = UIStackView(arrangedSubviews: [titleLabel, subtitleLabel])
labelStackView.translatesAutoresizingMaskIntoConstraints = false
labelStackView.alignment = .leading

View File

@ -6,8 +6,8 @@ import MastodonSDK
import MastodonLocalization
protocol AccountNotificationTimelineViewControllerDelegate: AnyObject {
func acceptRequest(_ viewController: AccountNotificationTimelineViewController, request: Mastodon.Entity.NotificationRequest, completion: @escaping (() -> Void))
func dismissRequest(_ viewController: AccountNotificationTimelineViewController, request: Mastodon.Entity.NotificationRequest, completion: @escaping (() -> Void))
func acceptRequest(_ viewController: AccountNotificationTimelineViewController, request: Mastodon.Entity.NotificationRequest)
func dismissRequest(_ viewController: AccountNotificationTimelineViewController, request: Mastodon.Entity.NotificationRequest)
}
class AccountNotificationTimelineViewController: NotificationTimelineViewController {
@ -27,25 +27,20 @@ class AccountNotificationTimelineViewController: NotificationTimelineViewControl
// MARK: - Actions
//TODO: Localization
func menu() -> UIMenu {
let menu = UIMenu(children: [
UIAction(title: L10n.Scene.Notification.FilteredNotification.accept, image: UIImage(systemName: "checkmark")) { [weak self] _ in
guard let self else { return }
coordinator.showLoading()
self.delegate?.acceptRequest(self, request: request) {
self.navigationController?.popViewController(animated: true)
}
self.delegate?.acceptRequest(self, request: request)
coordinator.hideLoading()
},
UIAction(title: L10n.Scene.Notification.FilteredNotification.dismiss, image: UIImage(systemName: "speaker.slash")) { [weak self] _ in
guard let self else { return }
coordinator.showLoading()
self.delegate?.dismissRequest(self, request: request) {
self.navigationController?.popViewController(animated: true)
}
self.delegate?.dismissRequest(self, request: request)
coordinator.hideLoading()
}
])

View File

@ -124,30 +124,7 @@ extension NotificationRequestsTableViewController: NotificationRequestTableViewC
Task { [weak self] in
guard let self else { return }
do {
_ = try await context.apiService.acceptNotificationRequests(authenticationBox: authContext.mastodonAuthenticationBox,
id: notificationRequest.id)
let requests = try await context.apiService.notificationRequests(authenticationBox: authContext.mastodonAuthenticationBox).value
NotificationCenter.default.post(name: .notificationFilteringChanged, object: nil)
if requests.count > 0 {
await MainActor.run { [weak self] in
guard let self else { return }
self.viewModel.requests = requests
var snapshot = NSDiffableDataSourceSnapshot<NotificationRequestsSection, NotificationRequestItem>()
snapshot.appendSections([.main])
snapshot.appendItems(self.viewModel.requests.compactMap { NotificationRequestItem.item($0) } )
self.dataSource?.apply(snapshot)
}
} else {
await MainActor.run { [weak self] in
_ = self?.navigationController?.popViewController(animated: true)
}
}
try await acceptNotificationRequest(notificationRequest)
} catch {
cell.acceptNotificationRequestActivityIndicatorView.stopAnimating()
cell.acceptNotificationRequestButton.tintColor = .white
@ -157,7 +134,33 @@ extension NotificationRequestsTableViewController: NotificationRequestTableViewC
}
}
}
private func acceptNotificationRequest(_ notificationRequest: MastodonSDK.Mastodon.Entity.NotificationRequest) async throws {
_ = try await context.apiService.acceptNotificationRequests(authenticationBox: authContext.mastodonAuthenticationBox,
id: notificationRequest.id)
let requests = try await context.apiService.notificationRequests(authenticationBox: authContext.mastodonAuthenticationBox).value
NotificationCenter.default.post(name: .notificationFilteringChanged, object: nil)
if requests.count > 0 {
await MainActor.run { [weak self] in
guard let self else { return }
self.viewModel.requests = requests
var snapshot = NSDiffableDataSourceSnapshot<NotificationRequestsSection, NotificationRequestItem>()
snapshot.appendSections([.main])
snapshot.appendItems(self.viewModel.requests.compactMap { NotificationRequestItem.item($0) } )
self.dataSource?.apply(snapshot)
}
} else {
await MainActor.run { [weak self] in
_ = self?.navigationController?.popViewController(animated: true)
}
}
}
func rejectNotificationRequest(_ cell: NotificationRequestTableViewCell, notificationRequest: MastodonSDK.Mastodon.Entity.NotificationRequest) {
cell.rejectNotificationRequestActivityIndicatorView.isHidden = false
@ -209,17 +212,15 @@ extension NotificationRequestsTableViewController: NotificationRequestTableViewC
}
extension NotificationRequestsTableViewController: AccountNotificationTimelineViewControllerDelegate {
func acceptRequest(_ viewController: AccountNotificationTimelineViewController, request: MastodonSDK.Mastodon.Entity.NotificationRequest, completion: @escaping (() -> Void)) {
func acceptRequest(_ viewController: AccountNotificationTimelineViewController, request: MastodonSDK.Mastodon.Entity.NotificationRequest) {
Task {
try? await rejectNotificationRequest(request)
completion()
try? await acceptNotificationRequest(request)
}
}
func dismissRequest(_ viewController: AccountNotificationTimelineViewController, request: MastodonSDK.Mastodon.Entity.NotificationRequest, completion: @escaping (() -> Void)) {
func dismissRequest(_ viewController: AccountNotificationTimelineViewController, request: MastodonSDK.Mastodon.Entity.NotificationRequest) {
Task {
try? await rejectNotificationRequest(request)
completion()
}
}
}