Not receiving unread messages count in quickblox

521 views Asked by At

I am using quickblox android sdk for a groupchat application and it is working perfectly well except for the fact that i am unable to receive push notification if a message is sent when i was offline. So i decided to query for unread messages count but am getting 0 from the server. I don't know what i have to do to get groupchat dialog for a user to be able to receive notification when the user was not online.

This is the code I used for querying for unread messages:

Set<String> dialogIds = new HashSet<String>();
String groupChatId = groupChat.getDialogId();
System.out.println("GroupChat Id: "+groupChatId);
dialogIds.add(groupChatId);  
QBChatDialog chatDialog = new QBChatDialog(groupChatId);
QBMessageGetBuilder messageGetBuilder = new QBMessageGetBuilder();
messageGetBuilder.setLimit(500);
messageGetBuilder.sortDesc("date_sent");
QBRestChatService.getTotalUnreadMessagesCount(dialogsIds).performAsync(new QBEntityCallback<Integer>() {
@Override
public void onSuccess(Integer total, Bundle params) {
    Log.i(TAG, "total unread messages: " + total);
    // if you have more then one dialog you can get each value with params.getInt(dialog_id)
}

@Override
public void onError(QBResponseException e) { 
    e.printStackTrace();
}
});
1

There are 1 answers

6
GVillani82 On

The first part is correct:

Set<String> dialogIds = new HashSet<String>();
String groupChatId = groupChat.getDialogId();
dialogsIds.add(groupChatId);

But, after that you were not using dialogIds. And also, instead of getDialogMessages () you need to use getTotalUnreadMessagesCount() as following:

QBRestChatService.getTotalUnreadMessagesCount(dialogIds).performAsync(new QBEntityCallback<Integer>() {
    @Override
    public void onSuccess(Integer total, Bundle params) {
        Log.i(TAG, "totat messages: " + total);
        // if you have more then one dialog you can get each value with params.getInt(dialog_id)
    }

    @Override
    public void onError(QBResponseException e) { }
});