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();
}
});
The first part is correct:
But, after that you were not using
dialogIds
. And also, instead ofgetDialogMessages ()
you need to usegetTotalUnreadMessagesCount()
as following: