Skip to content

Commit

Permalink
Merge pull request #570 from badoo/Fixing-of-message-blinking-on-upda…
Browse files Browse the repository at this point in the history
…te-from-server

Fixing of a message blinking on the first update from server
  • Loading branch information
AntonPalich authored Jun 25, 2019
2 parents a762340 + a566c8a commit cebe964
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions Chatto/Source/ChatController/BaseChatViewController+Changes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ import Foundation
private struct HashableItem: Hashable {
private let uid: String
private let type: String
init(chatItem: ChatItemProtocol) {
self.uid = chatItem.uid
self.type = chatItem.type

init(_ decoratedChatItem: DecoratedChatItem) {
self.uid = decoratedChatItem.uid
self.type = decoratedChatItem.chatItem.type
}

init(_ chatItemCompanion: ChatItemCompanion) {
self.uid = chatItemCompanion.uid
self.type = chatItemCompanion.chatItem.type
}
}

Expand Down Expand Up @@ -282,8 +288,8 @@ extension BaseChatViewController {

private func createModelUpdates(newItems: [ChatItemProtocol], oldItems: ChatItemCompanionCollection, collectionViewWidth: CGFloat) -> (changes: CollectionChanges, updateModelClosure: () -> Void) {
let newDecoratedItems = self.chatItemsDecorator?.decorateItems(newItems) ?? newItems.map { DecoratedChatItem(chatItem: $0, decorationAttributes: nil) }
let changes = Chatto.generateChanges(oldCollection: oldItems.map { HashableItem(chatItem: $0.chatItem) },
newCollection: newDecoratedItems.map { HashableItem(chatItem: $0.chatItem) })
let changes = Chatto.generateChanges(oldCollection: oldItems.map(HashableItem.init),
newCollection: newDecoratedItems.map(HashableItem.init))
let itemCompanionCollection = self.createCompanionCollection(fromChatItems: newDecoratedItems, previousCompanionCollection: oldItems)
let layoutModel = self.createLayoutModel(itemCompanionCollection, collectionViewWidth: collectionViewWidth)
let updateModelClosure : () -> Void = { [weak self] in
Expand Down

0 comments on commit cebe964

Please sign in to comment.