Skip to content

Commit

Permalink
CompoundMessagePresenter.Model conforms to ContentEquatableChatItemPr…
Browse files Browse the repository at this point in the history
…otocol by default
  • Loading branch information
MikhailGasanov committed Aug 8, 2019
1 parent 4bd7502 commit 8d6e119
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Chatto
open class CompoundMessagePresenter<ViewModelBuilderT, InteractionHandlerT>
: BaseMessagePresenter<CompoundBubbleView, ViewModelBuilderT, InteractionHandlerT>, MessageContentPresenterDelegate where
ViewModelBuilderT: ViewModelBuilderProtocol,
ViewModelBuilderT.ModelT: Equatable,
ViewModelBuilderT.ModelT: Equatable & ContentEquatableChatItemProtocol,
InteractionHandlerT: BaseMessageInteractionHandlerProtocol,
InteractionHandlerT.ViewModelT == ViewModelBuilderT.ViewModelT {

Expand Down Expand Up @@ -81,10 +81,12 @@ open class CompoundMessagePresenter<ViewModelBuilderT, InteractionHandlerT>
}

open override func update(with chatItem: ChatItemProtocol) {
guard let oldChatItem = self.messageModel as? ContentEquatableChatItemProtocol else { assertionFailure("Unexpected type of the message: \(type(of: self.messageModel))."); return }
guard let newChatItem = chatItem as? ContentEquatableChatItemProtocol, let newMessageModel = chatItem as? ModelT else { assertionFailure("Unexpected type of the message: \(type(of: chatItem))."); return }
guard let newMessageModel = chatItem as? ModelT else {
assertionFailure("Unexpected type of the message: \(type(of: chatItem)).")
return
}

let isUpdateNeeded = !oldChatItem.hasSameContent(as: newChatItem)
let isUpdateNeeded = !self.messageModel.hasSameContent(as: newMessageModel)
self.messageModel = newMessageModel
if isUpdateNeeded { self.updateContent() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Chatto
@available(iOS 11, *)
public final class CompoundMessagePresenterBuilder<ViewModelBuilderT, InteractionHandlerT>: ChatItemPresenterBuilderProtocol where
ViewModelBuilderT: ViewModelBuilderProtocol,
ViewModelBuilderT.ModelT: Equatable,
ViewModelBuilderT.ModelT: Equatable & ContentEquatableChatItemProtocol,
InteractionHandlerT: BaseMessageInteractionHandlerProtocol,
InteractionHandlerT.ViewModelT == ViewModelBuilderT.ViewModelT {
public typealias ModelT = ViewModelBuilderT.ModelT
Expand Down

0 comments on commit 8d6e119

Please sign in to comment.