Using JSQMessageView I don't have the image urls for all my avatars at initial load time so I have an async call that goes and fetches urls - then images for avatars.
How can I update the placeholder avatar images once I have the avatars from the async process?
I saw some notes about JSQMessageAvatarImageDataSource, but the docs show protocol methods that return just single images with no parameters for things like key or index - so not sure how to implement this protocol.
Any examples of how to implement this use-case?
My implementation thus far
override func collectionView(collectionView: JSQMessagesCollectionView!, avatarImageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageAvatarImageDataSource! {
let message = messages[indexPath.item]
let diameter = UInt(collectionView.collectionViewLayout.incomingAvatarViewSize.width)
if let avatar = avatars[message.senderDisplayName] {
return avatar
} else {
// how do I update the avatars when i come back form the async call here
// APIClient.instance.getUserThumbnail(Int(message.senderId)!, completion: { (url, error) -> () in
// self.setupAvatarImage(message.senderDisplayName, imageUrl: url, diameter: 30)
// })
//default placeholder while the async call is happening
return setupAvatarColor(message.senderDisplayName, diameter: diameter)
}
}