jessesquires / JSQMessagesViewController

An elegant messages UI library for iOS

Home Page:https://www.jessesquires.com/blog/officially-deprecating-jsqmessagesviewcontroller/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handle single Avatar for continuous multiple messages.

dsrijan opened this issue · comments

New issue checklist

General information

  • JSQMessagesViewController version:
  • iOS version: 10.0
  • Devices/Simulators: Device
  • Reproducible in the demo project? (Yes/No): Yes
  • Any related issues:No

What happened?

I have a feature related query. Right now when we are sending multiple message at once, then for each message single avatar is showing. It means, if I am sending 3 messages continuously then 3 avatar also shows with bubble, but I want only one avatar for continuous message.The same case applies to recived messages also. If I am recieving regular more than 1 message, but I want bubbles for all messages but only one avatar. Is it possible to handle or not using JSQ. Let me know urgently asap

This should work:

override func collectionView(_ collectionView: JSQMessagesCollectionView, avatarImageDataForItemAt indexPath: IndexPath) -> JSQMessageAvatarImageDataSource? {
    let index = indexPath.item
    let previous = index == 0 ? "" : messages[index - 1].senderId
    let current = messages[index].senderId
    return previous == current ? nil : getAvatar(current)
}

thanks, @acjh. 💯