diff --git a/Mastodon/Protocol/StatusProvider/StatusProviderFacade.swift b/Mastodon/Protocol/StatusProvider/StatusProviderFacade.swift index e115151ea..4c34c6749 100644 --- a/Mastodon/Protocol/StatusProvider/StatusProviderFacade.swift +++ b/Mastodon/Protocol/StatusProvider/StatusProviderFacade.swift @@ -260,7 +260,7 @@ extension StatusProviderFacade { // haptic feedback generator let generator = UIImpactFeedbackGenerator(style: .light) - let responseFeedbackGenerator = UIImpactFeedbackGenerator(style: .medium) + let responseFeedbackGenerator = UINotificationFeedbackGenerator() status .compactMap { status -> (NSManagedObjectID, Mastodon.API.Favorites.FavoriteKind)? in @@ -284,13 +284,13 @@ extension StatusProviderFacade { .eraseToAnyPublisher() .switchToLatest() .receive(on: DispatchQueue.main) - .handleEvents { _ in + .handleEvents(receiveSubscription: { _ in generator.prepare() - responseFeedbackGenerator.prepare() - } receiveOutput: { _, favoriteKind in + }, receiveOutput: { _, favoriteKind in generator.impactOccurred() os_log("%{public}s[%{public}ld], %{public}s: [Like] update local status like status to: %s", ((#file as NSString).lastPathComponent), #line, #function, favoriteKind == .create ? "like" : "unlike") - } receiveCompletion: { completion in + }, receiveCompletion: { completion in + responseFeedbackGenerator.prepare() switch completion { case .failure: // TODO: handle error @@ -298,7 +298,7 @@ extension StatusProviderFacade { case .finished: break } - } + }) .map { statusID, favoriteKind in return context.apiService.favorite( statusID: statusID, @@ -309,14 +309,13 @@ extension StatusProviderFacade { .switchToLatest() .receive(on: DispatchQueue.main) .sink { [weak provider] completion in - guard let provider = provider else { return } - if provider.view.window != nil { - responseFeedbackGenerator.impactOccurred() - } + guard let _ = provider else { return } switch completion { case .failure(let error): + responseFeedbackGenerator.notificationOccurred(.error) os_log("%{public}s[%{public}ld], %{public}s: [Like] remote like request fail: %{public}s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription) case .finished: + responseFeedbackGenerator.notificationOccurred(.success) os_log("%{public}s[%{public}ld], %{public}s: [Like] remote like request success", ((#file as NSString).lastPathComponent), #line, #function) } } receiveValue: { response in @@ -370,7 +369,7 @@ extension StatusProviderFacade { // haptic feedback generator let generator = UIImpactFeedbackGenerator(style: .light) - let responseFeedbackGenerator = UIImpactFeedbackGenerator(style: .medium) + let responseFeedbackGenerator = UINotificationFeedbackGenerator() status .compactMap { status -> (NSManagedObjectID, Mastodon.API.Reblog.ReblogKind)? in @@ -394,10 +393,9 @@ extension StatusProviderFacade { .eraseToAnyPublisher() .switchToLatest() .receive(on: DispatchQueue.main) - .handleEvents { _ in + .handleEvents(receiveSubscription: { _ in generator.prepare() - responseFeedbackGenerator.prepare() - } receiveOutput: { _, reblogKind in + }, receiveOutput: { _, reblogKind in generator.impactOccurred() switch reblogKind { case .reblog: @@ -405,7 +403,8 @@ extension StatusProviderFacade { case .undoReblog: os_log("%{public}s[%{public}ld], %{public}s: [Reblog] update local status reblog status to: %s", ((#file as NSString).lastPathComponent), #line, #function, "unreblog") } - } receiveCompletion: { completion in + }, receiveCompletion: { completion in + responseFeedbackGenerator.prepare() switch completion { case .failure: // TODO: handle error @@ -413,7 +412,7 @@ extension StatusProviderFacade { case .finished: break } - } + }) .map { statusID, reblogKind in return context.apiService.reblog( statusID: statusID, @@ -424,14 +423,13 @@ extension StatusProviderFacade { .switchToLatest() .receive(on: DispatchQueue.main) .sink { [weak provider] completion in - guard let provider = provider else { return } - if provider.view.window != nil { - responseFeedbackGenerator.impactOccurred() - } + guard let _ = provider else { return } switch completion { case .failure(let error): + responseFeedbackGenerator.notificationOccurred(.error) os_log("%{public}s[%{public}ld], %{public}s: [Reblog] remote reblog request fail: %{public}s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription) case .finished: + responseFeedbackGenerator.notificationOccurred(.success) os_log("%{public}s[%{public}ld], %{public}s: [Reblog] remote reblog request success", ((#file as NSString).lastPathComponent), #line, #function) } } receiveValue: { response in