Jas_meet
Jas_meet

Reputation: 366

How to disable chat push for specific user in Group chat of Quickblox

I want to disable push notifications to user who has still not accepted the request for the group.

Upvotes: 1

Views: 698

Answers (1)

Sandeep Bhandari
Sandeep Bhandari

Reputation: 20379

Note

This answer is valid as per my experience with quickblox framework 2.7 and below. As quickblox is releasing newer version's of framework very frequently you might find a better API for doing it in future. Till then you can make use of this approach.

Answer

I dont think you can disable push notification for a specific user in group using Quickblox api.

When you send a message (QBChat) to a group everyone in the QBChatDialog gets the message including the person who is sending it out him/her self.

There is a Privacy List to prevent the user from receiving message from specific users, but that requires a initiation from user's end. So I dont think that will help you much here. This feature can be used to block a person/group from sending message to user.

Solution

Your best bet would be, not to add the user to group until the user accepts the group request. Implement your own logic to send out the request to each user in group and keep adding the user when he/she accepts the request.

1> Send out QBChat message with a specific custom object with data like group id, group type, group name and all other necessary data, which will differentiate it from other QBChat messages to all the user in group.

2> On receiving this special message, show a UI specific to deal with it, like an alert with "would you like to join the group??" and button accept or deny

3> On tapping accept, make a WS call to your own server and in your server api add the user to specific group for which he has agreed to join. Because you have already populated QBChat message with object which contains the info about the dialog, you should be able to inform your server easily for which group user has joined.

Once user joined to group he will continue to recieve all the messages in group

EDIT

Here is a detailed answer to your question in comment :)

I was pretty much sure you will ask this question :)

In order to add the occupant id to an existing QBChatDialog group we used the rest api of Quickblox. Remember I told you dont add all the participants to group initially, add them one by one after they accept to join group ?? When user accepts to join the group we call our rest api which in turn invokes the quickblox api and adds the current user id to group :)

You can easily find api for that in API section of quickblox. In case you din find it gimme time till Monday lemme ask my API developer and update u on the same

There is CATACH with this approach.

QB docs clearly says only the owner of the group can add the members to the group. That means just because you have a REST API you cant add the user to group. You will need to have the valid session id of the group owner. You will get the session id when you login, I believe you are very much aware of it :)

Now how on earth will I get the group owner session id ??

Here is the approach we followed. We had foreseen such issues might arise long way before we started the project :)

When user sign up using our app we save his username and password in our server db and generate a random username and password and create a Quickblox account with that usrname and password for the user and we save this quick blox username, quickblox password and quickblox user id for that user :)

So though sign up actually deals with two servers user will always feel like he is dealing with one server and he continue to think he is using his username and password to login to chat.

But in reality when user uses his username and password to login to app in login response we get the quickblox username and quickblox password that server had used to create the account. On receiving it app uses QB framework to login to quickblox account with that username and password :)

This way user is never aware of his quickblox username and password and userid :) Gives us lot of control as well :)

That being said :) now when a user creates a group and sends out a special QBChat message containing custom object, in that custom object along with details of dialog he also sends his quickbloxuserid :)

Now when user who recieves the special QBChat accepts the request, we extract the dialog id (to which he is intending to join) group_owner_id (id of user who created dialog and sent out this special message) and sends it to our rest api along with his own id :)

Once API recieves the group owner id, it fecthes the QB username and password from its db and log's in with that and gets a valid session id and finally adds the user to group with that session id.

Note : Quickblox allows user to login in multiple devices at a time that means it entertains multiple valid session id for user.

Hope I made my point clear :) Happy coding.

Upvotes: 3

Related Questions