1

I have implemented one-to-one chat using "Firebase" with the help of "JSQMessagesViewController" in swift 4 and I have submitted my app to Appstore. But, app gets rejected and asking for "A mechanism for users to block abusive users".

So, how I can achieve this mechanism in swift 4. I am not able to implement it, any code/suggestions will more appreciate.

Thank you in advance.

KENdi
  • 7,576
  • 2
  • 16
  • 31
Sagar Sukode
  • 1,361
  • 12
  • 23

3 Answers3

2

Ok there may be many solutions for this.But i am providing the procedure which i have used to achieve the block functionality.

1.You have create a key for user's each message(for example "status")

2.When user's are chatting send "0" in status

3.When user blocks other user send a message or blank message with status "1"

4.Here status "0" means user not blocked and status "1" means user blocked

5.When user is receiving message check if status is "1" do not load that message

Hope you got an idea.

Vikky
  • 914
  • 1
  • 6
  • 16
2

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.

Dan Leonard
  • 3,325
  • 1
  • 20
  • 32
1

For JSQMessage you can make use of provided delegate method

override func collectionView(collectionView: JSQMessagesCollectionView, didTapMessageBubbleAtIndexPath indexPath: NSIndexPath!) {
    super.collectionView(collectionView, didTapMessageBubbleAtIndexPath: indexPath)
    print("Present option to block here.")
}

using this you can get message index and perform any suitable Action

  • Present a Screen or any Action
  • You need to get USERID to whom you will block
Dan Leonard
  • 3,325
  • 1
  • 20
  • 32
iOS Geek
  • 4,825
  • 1
  • 9
  • 30