Search code examples
androidquickblox

getDialogsUsers returns no elements


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: enter image description here, so ChatService.getInstance().getDialogsUsers().get(opponentID).getLogin() gives exception. Any explanations of this I have not found in documentation: enter image description here Why I have got 0 elements at ChatService.getInstance().getDialogsUsers()? Dialog is successfully created.


Solution

  • The 'getDialogsUsers' is not an SDK method, it's from code sample

    You can just look into it, what does it do

    https://github.com/QuickBlox/quickblox-android-sdk/blob/master/sample-chat/src/com/quickblox/sample/chat/core/ChatService.java#L195

    It returns a map of users, set in L172

    https://github.com/QuickBlox/quickblox-android-sdk/blob/master/sample-chat/src/com/quickblox/sample/chat/core/ChatService.java#L172

    Try to follow this file and move all needed logic to your app