I'm using MessageKit to create a chat interface for my app.
I'm currently using this code from their examples to not show a user's avatar if the multiple messages are from the same author:
func configureAvatarView(_ avatarView: AvatarView, for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) {
let sigil = Sigil(ship: Sigil.Ship(rawValue: message.sender.senderId)!, color: .black).image(with: CGSize(width: 24.0, height: 24.0))
let avatar = Avatar(image: sigil, initials: "")
avatarView.set(avatar: avatar)
avatarView.isHidden = isNextMessageSameSender(at: indexPath)
}
func isNextMessageSameSender(at indexPath: IndexPath) -> Bool {
guard indexPath.section + 1 < messages.count else { return false }
return messages[indexPath.section].sender.displayName == messages[indexPath.section + 1].sender.displayName
}
This is what it looks like in the MessageKit example app:
And this is the result of using the same code in my app:
EDIT
So it appears that the issue is somewhere here:
func isNextMessageSameSender(at indexPath: IndexPath) -> Bool {
guard indexPath.section + 1 < messages.count else { return false }
return messages[indexPath.section].sender.displayName == messages[indexPath.section + 1].sender.displayName
}
But I've not narrowed down exactly what it is yet
EDIT 2 I tried making it so that the check was using rows and not columns; still getting this sort of result: