Messagekit: How to know the id in didTapAvatar ?

Created on 16 Jun 2018  路  2Comments  路  Source: MessageKit/MessageKit

Hello Guys,

I would like to know how to get the sender of the avatar i tapped on ?
Like in the below example:

extension MessagesListVC: MessageCellDelegate {
    func didTapAvatar(in cell: MessageCollectionViewCell) {
        print("Avatar tapped") // I would like to see the id of the sender with this avatar
    }

    func didTapMessage(in cell: MessageCollectionViewCell) {
        print("Message tapped") // Same here
    }
}

Thanks :)

question

Most helpful comment

Hey @gorbat-o,

I would do something like this:

    func didTapAvatar(in cell: MessageCollectionViewCell) {
        guard let indexPath = messagesCollectionView.indexPath(for: cell) else { return }
        guard let messagesDataSource = messagesCollectionView.messagesDataSource else { return }
        let message = messagesDataSource.messageForItem(at: indexPath, in: messagesCollectionView)
        // here you can get the sender
        let sender = message.sender
    }

All 2 comments

Hey @gorbat-o,

I would do something like this:

    func didTapAvatar(in cell: MessageCollectionViewCell) {
        guard let indexPath = messagesCollectionView.indexPath(for: cell) else { return }
        guard let messagesDataSource = messagesCollectionView.messagesDataSource else { return }
        let message = messagesDataSource.messageForItem(at: indexPath, in: messagesCollectionView)
        // here you can get the sender
        let sender = message.sender
    }

Oh, good job, I didn't think that way.
Thanks :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adri4silva picture adri4silva  路  4Comments

emmanuelay picture emmanuelay  路  3Comments

JulienLevallois picture JulienLevallois  路  4Comments

TheDarkCode picture TheDarkCode  路  3Comments

nitrag picture nitrag  路  3Comments