Reactions: notify coordinator for every reaction request steps

so that it can leave the view when it wants
This commit is contained in:
manuroe
2019-05-16 08:07:52 +02:00
parent 5a89ecc7b1
commit d0a071a408
4 changed files with 23 additions and 31 deletions
@@ -1,23 +0,0 @@
/*
Copyright 2019 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import Foundation
/// TemplateScreenViewController view actions exposed to view model
enum ReactionsMenuAction {
case react(String)
case unreact(String)
}
@@ -123,15 +123,32 @@ final class ReactionsMenuViewModel: ReactionsMenuViewModelType {
private func react(withReaction reaction: ReactionsMenuReaction, selected: Bool) {
if selected {
self.aggregations.sendReaction(reaction.rawValue, toEvent: self.eventId, inRoom: self.roomId, success: {_ in
self.aggregations.sendReaction(reaction.rawValue, toEvent: self.eventId, inRoom: self.roomId, success: {[weak self] _ in
}, failure: {(error) in
guard let sself = self else {
return
}
sself.coordinatorDelegate?.reactionsMenuViewModel(sself, didReactionComplete: reaction.rawValue, isAddReaction: true)
}, failure: {[weak self] (error) in
print("[ReactionsMenuViewModel] react: Error: \(error)")
guard let sself = self else {
return
}
sself.coordinatorDelegate?.reactionsMenuViewModel(sself, didReactionFailedWithError: error, reaction: reaction.rawValue, isAddReaction: true)
})
self.coordinatorDelegate?.reactionsMenuViewModel(self, didSendReaction: reaction.rawValue, isAddReaction: true)
} else {
// TODO
self.coordinatorDelegate?.reactionsMenuViewModel(self, didSendReaction: reaction.rawValue, isAddReaction: false)
}
// TODO: to remove
self.fakeToggleReaction(reaction: reaction)
}
@@ -139,7 +156,7 @@ final class ReactionsMenuViewModel: ReactionsMenuViewModelType {
private func fakeToggleReaction(reaction: ReactionsMenuReaction) {
switch reaction {
case .agree:
isAgreeButtonSelected = !isDislikeButtonSelected
isAgreeButtonSelected = !isAgreeButtonSelected
case .disagree:
isDisagreeButtonSelected = !isDisagreeButtonSelected
case .like:
@@ -21,7 +21,9 @@ protocol ReactionsMenuViewModelDelegate: class {
}
protocol ReactionsMenuViewModelCoordinatorDelegate: class {
func reactionsMenuViewModel(_ viewModel: ReactionsMenuViewModelType, doAction action: ReactionsMenuAction)
func reactionsMenuViewModel(_ viewModel: ReactionsMenuViewModelType, didSendReaction reaction: String, isAddReaction: Bool)
func reactionsMenuViewModel(_ viewModel: ReactionsMenuViewModelType, didReactionComplete reaction: String, isAddReaction: Bool)
func reactionsMenuViewModel(_ viewModel: ReactionsMenuViewModelType, didReactionFailedWithError error: Error, reaction: String, isAddReaction: Bool)
}