2

I am building a chat app with quickblox SDK, and want to clear the unread message count in the chat dialogs(list items in group chat) when the user clicks and views the messages inside the group.For this I found this piece of code,

  public void updateStatusMessageReadServer(String dialogId, MessageCache messageCache,
                                          boolean fromPrivate) throws Exception {
    StringifyArrayList<String> messagesIdsList = new StringifyArrayList<String>();
    messagesIdsList.add(messageCache.getId());
    QBChatService.markMessagesAsRead(dialogId, messagesIdsList);

    if (fromPrivate) {
        QBPrivateChat privateChat = createPrivateChatIfNotExist(messageCache.getSenderId());
        privateChat.readMessage(messageCache.getId());
    }
}

Here messagecache is a bean class containing all the details about a message(I have to set this manually.Marking a message as read requires MessageId as per markMessageAsRead function.However, I don't know from where to get this message_id(messageCache.getId()), from each dialog(group) I get last message sent (text) and sender Id but not messageId and also there seems to be a rest API to mark all the messages inside a group as read, wherein I need to pass only dialog Id.Kindly suggest how to get the message id (is it mandatory to add it to the messagesId list?) or should I use rest API instead(not part of SDK)?

4

1 回答 1

1

I suggest you to use this method:

   QBChatService.markMessagesAsRead("YOUR_DIALOG_ID", null, new QBEntityCallback<Void>() {

        @Override
        public void onSuccess(Void aVoid, Bundle bundle) {

            QBRequestGetBuilder requestBuilder = new QBRequestGetBuilder();
            requestBuilder.eq("_id", Team.getCurrent().getChatId());

            QBChatService.getChatDialogs(null, requestBuilder, new QBEntityCallback<ArrayList<QBDialog>>() {
                @Override
                public void onSuccess(ArrayList<QBDialog> qbDialogs, Bundle bundle) {
                    if (qbDialogs != null && qbDialogs.size() > 0) {
                        QBDialog dialog = qbDialogs.get(0);//here you get your dialog with unreadMessageCount = 0
                    }
                }

                @Override
                public void onError(QBResponseException e) {

                }
            });
        }

        @Override
        public void onError(QBResponseException e) {

        }
    });

When null is sent as a parameter for messageIds, all messages are marked as read.

于 2016-02-26T10:53:37.140 回答