Chat not fetching on APK

you can see after 3-4 times of clicking Jason it finally loads, until then it’s not fetching.

How are you fetching the list of Conversations…?
Are you using the ConversationnsRequest class for the same…?
Also, Can you please leave the chat page for Jason to load for a little longer and provide me with the error obtained in the onError block while fetching messages. Knowing the error obtained will help us get to the root cause of the issue
Awaiting Reply

My developer said there is no error log.

We are using the logic used when we upgraded to V2 and actually this issue has been happening since last year. Sometimes we click on the chat and even after 2-3minutes it doesn’t fetch. We need to give the chats page 10-15 seconds page to load, then we can click on chat.

But to the customer, they are clicking on the chat before this period and it’s hence stuck, so we are getting complaints that chats are not fetching.

We are fetching as per the v2 pro doc

Can you share the logic to fetch chats with us so that we can have a look…?

We followed exactly the document as V2 fetch messages, but i will get a snippet to show you

when i am fetching the value from cometchat server some time response not getting so that it not continouslly loading

Is this fetching issue coming from cometchat servers end, as theres few second delay that is not coming from our side, and if user clicks on a chat during this period, the chat will not load as it’s nto fully fetched.

my developer said this is cometchats issue end.

any solution for this one

Hello @flipspot
Can you pleas share the code snippet used to fetch the chats (list of conversations) so that we can have a look.?

@Override
public void fetchPreviousMessage(String contactUid, int limit) {

    List<BaseMessage> list = new ArrayList<>();
    if (messagesRequest == null) {
        messagesRequest = new MessagesRequest.MessagesRequestBuilder().setUID(contactUid).setLimit(limit).build();
        messagesRequest.fetchPrevious(new CometChat.CallbackListener<List<BaseMessage>>() {
            @Override
            public void onSuccess(List<BaseMessage> baseMessages) {

                if (isViewAttached()) {
                    for (BaseMessage baseMessage : baseMessages) {
                        Log.d(TAG, "onSuccess: delete " + baseMessage.getDeletedAt());
                        if (!baseMessage.getCategory().equals(CometChatConstants.CATEGORY_ACTION) && baseMessage.getDeletedAt() == 0) {
                            list.add(baseMessage);
                        }
                    }
                    getBaseView().setAdapter(list);
                }
            }

            @Override
            public void onError(CometChatException e) {
                Log.d(TAG, " onError: " + e.getMessage());
                loadSettings();
            }

        });
    } else {

        messagesRequest.fetchPrevious(new CometChat.CallbackListener<List<BaseMessage>>() {
            @Override
            public void onSuccess(List<BaseMessage> baseMessages) {
                Logger.error("old message request obj");

                Log.e("oldMessage", String.valueOf(baseMessages));

                if (baseMessages.size() != 0) {
                    if (isViewAttached()) {
                        for (BaseMessage baseMessage : baseMessages) {
                            if (!baseMessage.getCategory().equals(CometChatConstants.CATEGORY_ACTION) && baseMessage.getDeletedAt() == 0) {
                                list.add(baseMessage);
                            }
                        }

                        getBaseView().setAdapter(list);
                    }
                }
            }

            @Override
            public void onError(CometChatException e) {
                Log.e("onError: ",e.getMessage() );
            }

        });
    }
}

I’ve sent the code, it’s fine, i thiink fetch delay coming from cometchat end, and while user clicks before it loads, it will not load the 1 to 1 chat.

any update team? looking to resolve this by EOD

any luck guys? @aditya.gokula

Hello @flipspot,
Can you share the code to fetch the list of chats and not the list to fetch messages.

Call list of chat:

new Thread(new Runnable() {
@Override
public void run() {
oneToOnePresenter.fetchPreviousMessage(contactUid, LIMIT);
}
}).start();

This is how we handle comet chat server response:

@Override
public void fetchPreviousMessage(String contactUid, int limit) {

    List<BaseMessage> list = new ArrayList<>();
    if (messagesRequest == null) {
        messagesRequest = new MessagesRequest.MessagesRequestBuilder().setUID(contactUid).setLimit(limit).build();
        messagesRequest.fetchPrevious(new CometChat.CallbackListener<List<BaseMessage>>() {
            @Override
            public void onSuccess(List<BaseMessage> baseMessages) {

                if (isViewAttached()) {
                    for (BaseMessage baseMessage : baseMessages) {
                        Log.d(TAG, "onSuccess: delete " + baseMessage.getDeletedAt());
                        if (!baseMessage.getCategory().equals(CometChatConstants.CATEGORY_ACTION) && baseMessage.getDeletedAt() == 0) {
                            list.add(baseMessage);
                        }
                    }
                    getBaseView().setAdapter(list);
                }
            }

            @Override
            public void onError(CometChatException e) {
                Log.d(TAG, " onError: " + e.getMessage());
                loadSettings();
            }

        });
    } else {

        messagesRequest.fetchPrevious(new CometChat.CallbackListener<List<BaseMessage>>() {
            @Override
            public void onSuccess(List<BaseMessage> baseMessages) {
                Logger.error("old message request obj");

                Log.e("oldMessage", String.valueOf(baseMessages));

                if (baseMessages.size() != 0) {
                    if (isViewAttached()) {
                        for (BaseMessage baseMessage : baseMessages) {
                            if (!baseMessage.getCategory().equals(CometChatConstants.CATEGORY_ACTION) && baseMessage.getDeletedAt() == 0) {
                                list.add(baseMessage);
                            }
                        }

                        getBaseView().setAdapter(list);
                    }
                }
            }

            @Override
            public void onError(CometChatException e) {
                Log.e("onError: ",e.getMessage() );
            }

        });
    }
}

And here is scroll message:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
setScrollListener();
} else {
messageRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {

                if (linearLayoutManager.findFirstVisibleItemPosition() == 0) {
                    Logger.error("slow scroll");
                    oneToOnePresenter.fetchPreviousMessage(contactUid, LIMIT);
                }

                toolbar.setSelected(messageRecyclerView.canScrollVertically(-1));
            }
        });
    }

@aditya.gokula any luck?

Hello @flipspot
I would like the code snippet for fetching the list of chats and not fetching the list of messages for a particular user. I believe the problem lies in the logic to fetch the list of chats and not while fetching messages.
Awaiting reply

Fetching userlist (@aditya.gokula)

@Override
public void fecthUsers(ArrayList userIdList) {

    if (usersRequest == null) {
        usersRequest = new UsersRequest.UsersRequestBuilder().setLimit(100).build();

        Log.e(TAG, "userListSize" + String.valueOf(userIdList));
        usersRequest.fetchNext(new CometChat.CallbackListener<List<User>>() {
            @Override
            public void onSuccess(List<User> users1) {
                Log.d(TAG, "onSuccess: ");

                Logger.error(TAG, "userListSize users1 " + users1);
                List<User> users = new ArrayList<>();

                for (int i = 0; i < users1.size(); i++) {
                    for (int j = 0; j < userIdList.size(); j++) {
                        Logger.error(TAG, "matching_user " + users1.get(i).getUid() + "  ==  " + userIdList.get(j));
                        if (users1.get(i).getUid().equals(userIdList.get(j))) {
                            users.add(users1.get(i));
                            listArray.addAll(users);
                            Log.e(TAG, "fetchsetusersList" + String.valueOf(users.size() + " " + users1.get(i).getUid()));
                            break;
                        }
                    }
                }


                if (users.size() > 0) {
                    count = 0;
                    lastmessage = new ArrayList<>();
                    limit = 1;
                    UserConversation(users.get(count).getUid(), users);
                }

            }

            @Override
            public void onError(CometChatException e) {

            }
        });

    } else {
        usersRequest.fetchNext(new CometChat.CallbackListener<List<User>>() {
            @Override
            public void onSuccess(List<User> users1) {
                if (users1 != null && users1.size() != 0) {
                    Logger.error("old user list resquest obj");
                    Logger.error("userList", " " + users1.size());

                    List<User> users = new ArrayList<>();
                    for (int i = 0; i < users1.size(); i++) {
                        for (int j = 0; j < userIdList.size(); j++) {
                            if (users1.get(i).getUid().equals(userIdList.get(j))) {
                                users.add(users1.get(i));
                                listArray.addAll(users);
                                Log.e(TAG, "fetchsetusersListNext" + String.valueOf(users.size() + " " + users1.get(i).getUid()));

                            }
                        }
                    }

                    if (users.size() > 0) {
                        count = 0;
                        lastmessage = new ArrayList<>();
                        limit = 1;
                        UserConversation(users.get(count).getUid(), users);
                    }
                }
            }

            @Override
            public void onError(CometChatException e) {
                Log.d(TAG, "onError: ");
                e.getMessage();
            }

        });

    }
}

any update on this one guys?