fix: add followrequest cell action

This commit is contained in:
sunxiaojian 2021-04-27 16:54:23 +08:00
parent 381bf37926
commit d03346c0de
4 changed files with 56 additions and 3 deletions

View File

@ -91,6 +91,18 @@ extension NotificationSection {
cell.actionLabel.text = actionText + " · " + timeText cell.actionLabel.text = actionText + " · " + timeText
} }
.store(in: &cell.disposeBag) .store(in: &cell.disposeBag)
cell.acceptButton.publisher(for: .touchUpInside)
.sink { [weak cell] _ in
guard let cell = cell else { return }
cell.delegate?.notificationTableViewCell(cell, notification: notification, acceptButtonDidPressed: cell.acceptButton)
}
.store(in: &cell.disposeBag)
cell.rejectButton.publisher(for: .touchUpInside)
.sink { [weak cell] _ in
guard let cell = cell else { return }
cell.delegate?.notificationTableViewCell(cell, notification: notification, rejectButtonDidPressed: cell.acceptButton)
}
.store(in: &cell.disposeBag)
cell.actionImageBackground.backgroundColor = color cell.actionImageBackground.backgroundColor = color
cell.actionLabel.text = actionText + " · " + timeText cell.actionLabel.text = actionText + " · " + timeText
cell.nameLabel.text = notification.account.displayName.isEmpty ? notification.account.username : notification.account.displayName cell.nameLabel.text = notification.account.displayName.isEmpty ? notification.account.username : notification.account.displayName

View File

@ -205,6 +205,14 @@ extension NotificationViewController: ContentOffsetAdjustableTimelineViewControl
// MARK: - NotificationTableViewCellDelegate // MARK: - NotificationTableViewCellDelegate
extension NotificationViewController: NotificationTableViewCellDelegate { extension NotificationViewController: NotificationTableViewCellDelegate {
func notificationTableViewCell(_ cell: NotificationTableViewCell, notification: MastodonNotification, acceptButtonDidPressed button: UIButton) {
viewModel.acceptFollowRequest(notification: notification)
}
func notificationTableViewCell(_ cell: NotificationTableViewCell, notification: MastodonNotification, rejectButtonDidPressed button: UIButton) {
viewModel.rejectFollowRequest(notification: notification)
}
func userAvatarDidPressed(notification: MastodonNotification) { func userAvatarDidPressed(notification: MastodonNotification) {
let viewModel = ProfileViewModel(context: context, optionalMastodonUser: notification.account) let viewModel = ProfileViewModel(context: context, optionalMastodonUser: notification.account)
DispatchQueue.main.async { DispatchQueue.main.async {

View File

@ -12,6 +12,7 @@ import Foundation
import GameplayKit import GameplayKit
import MastodonSDK import MastodonSDK
import UIKit import UIKit
import OSLog
final class NotificationViewModel: NSObject { final class NotificationViewModel: NSObject {
var disposeBag = Set<AnyCancellable>() var disposeBag = Set<AnyCancellable>()
@ -120,6 +121,38 @@ final class NotificationViewModel: NSObject {
} }
.store(in: &disposeBag) .store(in: &disposeBag)
} }
func acceptFollowRequest(notification: MastodonNotification) {
guard let activeMastodonAuthenticationBox = self.activeMastodonAuthenticationBox.value else { return }
context.apiService.acceptFollowRequest(mastodonUserID: notification.account.id, mastodonAuthenticationBox: activeMastodonAuthenticationBox)
.sink { [weak self] completion in
switch completion {
case .failure(let error):
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: accept FollowRequest fail: %s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription)
case .finished:
self?.loadLatestStateMachine.enter(NotificationViewModel.LoadLatestState.Loading.self)
}
} receiveValue: { _ in
}
.store(in: &disposeBag)
}
func rejectFollowRequest(notification: MastodonNotification) {
guard let activeMastodonAuthenticationBox = self.activeMastodonAuthenticationBox.value else { return }
context.apiService.acceptFollowRequest(mastodonUserID: notification.account.id, mastodonAuthenticationBox: activeMastodonAuthenticationBox)
.sink { [weak self] completion in
switch completion {
case .failure(let error):
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: reject FollowRequest fail: %s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription)
case .finished:
self?.loadLatestStateMachine.enter(NotificationViewModel.LoadLatestState.Loading.self)
}
} receiveValue: { _ in
}
.store(in: &disposeBag)
}
} }
extension NotificationViewModel { extension NotificationViewModel {

View File

@ -21,9 +21,9 @@ protocol NotificationTableViewCellDelegate: AnyObject {
func notificationStatusTableViewCell(_ cell: NotificationStatusTableViewCell, statusView: StatusView, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView) func notificationStatusTableViewCell(_ cell: NotificationStatusTableViewCell, statusView: StatusView, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView)
func notificationStatusTableViewCell(_ cell: NotificationStatusTableViewCell, statusView: StatusView, playerContainerView: PlayerContainerView, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView) func notificationStatusTableViewCell(_ cell: NotificationStatusTableViewCell, statusView: StatusView, playerContainerView: PlayerContainerView, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView)
// func notificationStatusTableViewCell(_ cell: NotificationStatusTableViewCell, notification: MastodonNotification, acceptButtonDidPressed button: UIButton) func notificationTableViewCell(_ cell: NotificationTableViewCell, notification: MastodonNotification, acceptButtonDidPressed button: UIButton)
//
// func notificationStatusTableViewCell(_ cell: NotificationStatusTableViewCell, notification: MastodonNotification, denyButtonDidPressed button: UIButton) func notificationTableViewCell(_ cell: NotificationTableViewCell, notification: MastodonNotification, rejectButtonDidPressed button: UIButton)
} }