Use messageKit with Firebase When I delete any message in the chat using long press, it gets deleted in front of me, but when I leave the chat and come back, it is not actually deleted.
override func collectionView(_ collectionView: UICollectionView, canPerformAction action: Selector, forItemAt indexPath: IndexPath, withSender sender: Any?) -> Bool {
if action == NSSelectorFromString("delete:") {
return true
} else {
return super.collectionView(collectionView, canPerformAction: action, forItemAt: indexPath, withSender: sender)
}
}
override func collectionView(_ collectionView: UICollectionView, performAction action: Selector, forItemAt indexPath: IndexPath, withSender sender: Any?) {
if action == NSSelectorFromString("delete:") {
// 1.) Remove from datasource
// insert your code here
self.mkMessages.remove(at: indexPath.section) // Here it is deleted
// 2.) Delete sections
collectionView.deleteSections([indexPath.section])
} else {
super.collectionView(collectionView, performAction: action, forItemAt: indexPath, withSender: sender)
}
}
extension MSGViewController: MessagesDataSource {
func currentSender() -> SenderType {
return currenUser
}
func messageForItem(at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> MessageType {
return mkMessages[indexPath.section]
}
func numberOfSections(in messagesCollectionView: MessagesCollectionView) -> Int {
return mkMessages.count
}