I am trying to create chat in app using sampe-chat codes.
I authorized user, got opponend id, after that successfully created dialog:
ChatService.initIfNeed(this);
QBUsers.getUserByLogin(login, new QBEntityCallbackImpl<QBUser>() {
@Override
public void onSuccess(QBUser qbUser, Bundle args) {
QBPrivateChatManager privateChatManager = QBChatService.getInstance().getPrivateChatManager();
privateChatManager.createDialog(qbUser.getId(), new QBEntityCallbackImpl<QBDialog>() {
@Override
public void onSuccess(QBDialog dialog, Bundle args) {
ChatActivity.this.dialog = dialog;
setContentView(R.layout.activity_chat);
initViews();
if (isSessionActive()) {
initChat();
}
ChatService.getInstance().addConnectionListener(chatConnectionListener);
}
@Override
public void onError(List<String> errors) {
Log.e("chat", errors.toString());
}
});
}
@Override
public void onError(List errors) {
Log.e("chat", errors.toString());
}
});
But at initViews() I've got error at
else if (dialog.getType() == QBDialogType.PRIVATE) {
Integer opponentID = ChatService.getInstance().getOpponentIDForPrivateDialog(dialog);
companionLabel.setText(ChatService.getInstance().getDialogsUsers().get(opponentID).getLogin());
}
The error is because ChatService.getInstance().getDialogsUsers() returns 0 elements: , so ChatService.getInstance().getDialogsUsers().get(opponentID).getLogin() gives exception. Any explanations of this I have not found in documentation: Why I have got 0 elements at ChatService.getInstance().getDialogsUsers()? Dialog is successfully created.
The 'getDialogsUsers' is not an SDK method, it's from code sample
You can just look into it, what does it do
It returns a map of users, set in L172
Try to follow this file and move all needed logic to your app