我成功配置了quickblox,创建了会话和登录用户完美的工作。 但是当我们创建聊天对话框时,它什么都不做。
final QBChatDialog dialogToCreate = new QBChatDialog();
dialogToCreate.setName("xxx xxx ");
dialogToCreate.setType(QBDialogType.PUBLIC_GROUP);
dialogToCreate.setUserId(xxx1);
ArrayList<Integer> occupantsIds = new ArrayList<Integer>();
occupantsIds.add(xxx1);
occupantsIds.add(xxx2);
dialogToCreate.setOccupantsIds(occupantsIds);
QBRestChatService.createChatDialog(dialogToCreate).performAsync(new QBEntityCallback<QBChatDialog>() {
@Override
public void onSuccess(QBChatDialog qbChatDialog, Bundle bundle) {
qbChatDialog.initForChat(qbChatDialog.getDialogId(), QBDialogType.PUBLIC_GROUP, QBChatService.getInstance());
}
@Override
public void onError(QBResponseException e) {
}
});
我在这个应用程序中找到的最后一个日志如下:
'{"session":{"application_id":69154,"created_at":"2018-04-06T10:51:59Z","id":670583149,"nonce":-590011862,"token":"91d65e64a26f33f20dc7d06ec9fb41f111010e22","ts":1523011917,"updated_at":"2018-04-06T10:51:59Z","user_id":44771703,"_id":"670583149"}}'
请建议如何打开聊天对话框?
答案 0 :(得分:0)
首先,确保在清单文件中添加了以下服务和元数据:
<service
android:name="com.quickblox.messages.services.gcm.QBGcmPushInstanceIDService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
<meta-data
android:name="com.quickblox.messages.TYPE"
android:value="GCM" />
<meta-data
android:name="com.quickblox.messages.SENDER_ID"
android:value="@string/sender_id" />
<meta-data
android:name="com.quickblox.messages.QB_ENVIRONMENT"
android:value="DEVELOPMENT" />
然后,在创建对话框之前必须创建对手的列表之后:
ArrayList<QBUser> qbUserList = new ArrayList<QBUser>();
QBUser qbUser = new QBUser();
qbUser.setId(524618);
qbUser.setFullName("test");
qbUserList.add(qbUser);
qbUserList.add(QBChatService.getInstance().getUser());
然后你必须调用这个方法:
QBRestChatService.createChatDialog(QbDialogUtils.createDialog(users)).performAsync(
new QbEntityCallbackWrapper<QBChatDialog>(callback) {
@Override
public void onSuccess(QBChatDialog dialog, Bundle args) {
initForChat(dialog); // here i created one method that init chat from dialog
super.onSuccess(dialog, args);
}
});
在此之前确保您在创建QBChatService的创建类:
chatService = QBChatService.getInstance();
初始化聊天的方法:
private void initForChat(QBChatDialog dialog){
dialog.initForChat(chatService);
//make sure you defined private ConnectionListener chatConnectionListener;
chatConnectionListener = new VerboseQbChatConnectionListener(getSnackbarAnchorView()) {
@Override
public void reconnectionSuccessful() {
super.reconnectionSuccessful();
switch (qbChatDialog.getType()) {
case GROUP:
chatAdapter = null;
// Join active room if we're in Group Chat
runOnUiThread(new Runnable() {
@Override
public void run() {
joinGroupChat();
}
});
break;
}
}
};
}
群聊方式:
private void joinGroupChat() {
ChatHelper.getInstance().join(qbChatDialog, new QBEntityCallback<Void>() {
@Override
public void onSuccess(Void result, Bundle b) {
loadDialogUsers();
}
@Override
public void onError(QBResponseException e) {
}
});
}
然后加载对话框用户:
private void loadDialogUsers() {
ChatHelper.getInstance().getUsersFromDialog(qbChatDialog, new QBEntityCallback<ArrayList<QBUser>>() {
@Override
public void onSuccess(ArrayList<QBUser> users, Bundle bundle) {
}
@Override
public void onError(QBResponseException e) {
}
});
}