Organising contacts by most recent message

Hi guys,

I am trying to organise the conversation list on Android from alphabetical order, to last recent message (e.g like Facebook or Whatsapp). How do we go about doing this

Hello @flipspot,

Conversations are sorted by last message by default. You can read more about fetching conversations here.

Warm Regards,

CometChat Pro
Mayur Bhandari

Hi,

We are still trying to resolve this but unable to.

[
User{
uid=‘1188’,
name=‘Ab Test’,
avatar=‘https://www.flipspot.com/resources/uploads/users/small/null’,
link=‘null’,
role=‘default’,
metadata=null,
status=‘offline’,
statusMessage=‘null’,
lastActiveAt=1622627238,
hasBlockedMe=false,
blockedByMe=false
},
User{
uid=‘1194’,
name=‘AC’,
avatar=‘https://www.flipspot.com/resources/uploads/users/small/null’,
link=‘null’,
role=‘default’,
metadata=null,
status=‘offline’,
statusMessage=‘null’,
lastActiveAt=1619171947,
hasBlockedMe=false,
blockedByMe=false
},
User{
uid=‘1198’,
name=‘AF Test’,
avatar=‘https://www.flipspot.com/resources/uploads/users/small/null’,
link=‘null’,
role=‘default’,
metadata=null,
status=‘offline’,
statusMessage=‘null’,
lastActiveAt=1614574029,
hasBlockedMe=false,
blockedByMe=false
},
User{
uid=‘546’,
name=‘Amar’,
avatar=‘https://www.flipspot.com/resources/v5/images/profile.png’,
link=‘null’,
role=‘default’,
metadata=null,
status=‘offline’,
statusMessage=‘null’,
lastActiveAt=1606379295,
hasBlockedMe=false,
blockedByMe=false
},
User{
uid=‘543’,
name=‘Amarjit’,
avatar=‘https://lh3.googleusercontent.com/a-/AOh14GiptHgscU0PNnDX3wQmHZx5baPZ-cYBstpTVf93’,
link=‘null’,
role=‘default’,
metadata=null,
status=‘offline’,
statusMessage=‘null’,
lastActiveAt=1608264282,
hasBlockedMe=false,
blockedByMe=false
},
User{
uid=‘724’,
name=‘Amber’,
avatar=‘https://lh6.googleusercontent.com/-CmL3k_HMGiE/AAAAAAAAAAI/AAAAAAAAAAA/AMZuuckdo8K2nyr_Hnr0R65py6e-dZ3t7g/photo.jpg’,
link=‘null’,
role=‘default’,
metadata=null,
status=‘offline’,
statusMessage=‘null’,
lastActiveAt=1614078616,
hasBlockedMe=false,
blockedByMe=false
},
User{
uid=‘1372’,
name=‘AS Test’,
avatar=‘https://www.flipspot.com/resources/uploads/users/small/null’,
link=‘null’,
role=‘default’,
metadata=null,
status=‘offline’,
statusMessage=‘null’,
lastActiveAt=1608198243,
hasBlockedMe=false,
blockedByMe=false
},
User{
uid=‘1530’,
name=‘AX Test’,
avatar=‘https://www.flipspot.com/resources/uploads/users/small/null’,
link=‘null’,
role=‘default’,
metadata=null,
status=‘offline’,
statusMessage=‘null’,
lastActiveAt=1608178582,
hasBlockedMe=false,
blockedByMe=false
}
]

Onlinealways, 6:17 PM
these are the response you are getting in Android

OnqanetAndroid, 6:18 PM
yes

Onlinealways, 6:18 PM
ok

OnqanetAndroid, 6:18 PM
usersRequest = new UsersRequest.UsersRequestBuilder().setLimit(userListLimit).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("cometchat_userList", users1.toString());
                Logger.error("backend_userList", userIdList.toString());
                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;
                        }
                    }
                }*/

                for (int i = 0; i < users1.size(); i++) {
                    users.add(users1.get(i));
                    listArray.addAll(users);
                }


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

            }

            @Override
            public void onError(CometChatException e) {

            }
        });

— .fetchNext not give the resent message user list. The code gives the latest conversion (message of user), but we need are unable to find this. (user list according to latest conversation). Can u please review the above code and let me know @mayur.bhandari

The code above is not fetching any RECENT user list according to last message, how do we achieve this?

Hi @flipspot ,

As @mayur.bhandari has mentioned in previous reply you need to use ConversationRequestBuilder to fetch the conversations by last message. You can also filter conversationlist by users and group.

We will suggest you to use CometChatConversationList Component available in your UI Kit which will help you achieve it easily.

Please check below link for reference.

Hi @flipspot,

Hope this was helpful.

Please feel free to reach out to us at help@cometchat.com for more assistance or if you have any queries.

Regards,
Provesha