1st you would need is a flag on your user objects similar to isBlocked
or you could create a new table in Firebase
that holds a list of users (or Ids) that are blocked for a certain user. You could write a cloud function that filters out that information before returning to the device or just parse it on the device. Checking for your isBlocked
property and just does not show them in your list of conversations.
2nd yo need an entry point for actually adding the blocked flag to a user. You could do this many ways really depends on your design. You could add a button to the navigation bar that presented the user with options like this
(Make sure to add a call to this where appropriate I would suggest in the ViewDidLoad()
)
func prepareNavbarButton() {
let button = UIBarButtonItem(image: #imageLiteral(resourceName: "conversation_Options_Image"), style: .plain, target: self, action: #selector(uploadContact))
navigationItem.rightBarButtonItem = button
}
or on a message itself with this method
override func collectionView(collectionView: JSQMessagesCollectionView, didTapMessageBubbleAtIndexPath indexPath: NSIndexPath!) {
super.collectionView(collectionView, didTapMessageBubbleAtIndexPath: indexPath)
presentOptions()
}
func presentOptions() {
let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
actionSheet.addAction(UIAlertAction(title: "Block User", style: .default, handler: { _ in
blockUserAction()
}))
actionSheet.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
}
func blockUserAction() {
//CODE TO ADD USER ID TO BLOCKED USER IN FIREBASE
}
3rd I would provide a list of blocked users in a "Settings" like page that allows you to remove people from the list.
I would also suggest that you swap out JSQMessagesViewController
with MessageKit since JSQMessagesViewController
is deprecated and will not have future support. MessageKit is the replacement and has a slack channel that anyone can join. It is also written in Swift 4
so you will not need to have a bridging-header-file
to have it as a part of your project. It has most of the features of JSQMessagesViewController
already and more are to come.