简体   繁体   English

如何在Quickblox的群聊中禁用特定用户的聊天推送

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

我想禁用仍未接受该组请求的用户的推送通知。

Note 注意

This answer is valid as per my experience with quickblox framework 2.7 and below. 根据我使用quickblox框架2.7及以下版本的经验,这个答案是有效的。 As quickblox is releasing newer version's of framework very frequently you might find a better API for doing it in future. 由于quickblox经常发布更新版本的框架,因此您可能会在将来找到更好的API。 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. 我不认为您可以使用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. 当您向一个组发送消息( QBChat )时, QBChat中的每个人QBChatDialog收到消息,包括发送给他/她自己的人。

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. 1>使用特定自定义对象发送带有组ID,组类型,组名和所有其他必要数据的QBChat消息,这将使其与其他QBChat消息区分为组中的所有用户。

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??" 2>收到此特殊消息后,显示一个特定的UI来处理它,就像一个警告“你想加入小组吗?” 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. 3>在点击接受时,对您自己的服务器进行WS调用,并在您的服务器api中将用户添加到他已同意加入的特定组。 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. 因为您已经使用包含对话框信息的对象填充了QBChat消息,所以您应该能够轻松地通知服务器用户已加入的组。

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. 为了将占用者id添加到现有的QBChatDialog组,我们使用了Quickblox的其余api。 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 :) 当用户接受加入该组时,我们调用我们的rest api,后者又调用quickblox api并将当前用户ID添加到组:)

You can easily find api for that in API section of quickblox. 您可以在quickblox的API部分轻松找到api。 In case you din find it gimme time till Monday lemme ask my API developer and update u on the same 如果你发现它给我的时间到星期一,那么请问我的API开发人员并更新你的相同内容

There is CATACH with this approach. 这种方法有CATACH

QB docs clearly says only the owner of the group can add the members to the group. QB文档明确指出,只有该组的所有者才能将该成员添加到该组中。 That means just because you have a REST API you cant add the user to group. 这意味着仅仅因为你有一个REST API,你就无法将用户添加到组中。 You will need to have the valid session id of the group owner. 您需要拥有组所有者的有效会话ID。 You will get the session id when you login, I believe you are very much aware of it :) 登录时您将获得会话ID,我相信您非常了解它:)

Now how on earth will I get the group owner session id ?? 现在我将如何获得组所有者会话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 :) 当用户使用我们的应用程序注册时,我们将其用户名和密码保存在我们的服务器数据库中并生成随机用户名和密码,并使用该用户名和密码创建一个Quickblox帐户,我们保存此快速blox用户名,quickblox密码和quickblox用户该用户的ID :)

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. 但实际上,当用户使用他的用户名和密码在登录响应中登录app时,我们会获得服务器用于创建帐户的quickblox用户名和quickblox密码。 On receiving it app uses QB framework to login to quickblox account with that username and password :) 收到它后,应用程序使用QB框架使用该用户名和密码登录quickblox帐户:)

This way user is never aware of his quickblox username and password and userid :) Gives us lot of control as well :) 这样用户永远不会知道他的quickblox用户名和密码以及用户ID :)给我们很多控制权:)

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 :) 那就是说:)现在当用户创建一个组并发出一个包含自定义对象的特殊QBChat消息时,在该自定义对象中以及对话框的细节他也发送了他的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 :) 现在当收到特殊QBChat的用户接受请求时,我们提取对话框ID(他打算加入)group_owner_id(创建对话框并发出此特殊消息的用户的ID)并将其发送到我们的休息api以及他自己的身份:)

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. 一旦API收到组所有者ID,它就会从其数据库中记录QB用户名和密码,并使用该数据库登录并获取有效的会话ID,最后将用户添加到具有该会话ID的组。

Note : Quickblox allows user to login in multiple devices at a time that means it entertains multiple valid session id for user. 注意 :Quickblox允许用户一次登录多个设备,这意味着它可以为用户提供多个有效的会话ID。

Hope I made my point clear :) Happy coding. 希望我明白我的观点:)快乐的编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM