列出聊天消息QuickBlox历史消息

时间:2015-02-16 09:53:33

标签: android quickblox

可以根据自定义参数加载所有历史消息。 目前我们根据setPageLimit设置了一个。但我想使用自定义参数。 enter image description here。自定义参数是sh_id,sh_r_id,customer_id,date

private void loadHistory(String dialogId){
    QBDialog qbDialog = new QBDialog(dialogId);
    QBRequestGetBuilder customObjectRequestBuilder = new QBRequestGetBuilder();
    customObjectRequestBuilder.setPagesLimit(150); 

    QBChatService.getDialogMessages(qbDialog, customObjectRequestBuilder, new QBEntityCallbackImpl<ArrayList<QBChatHistoryMessage>>() {
        @Override
        public void onSuccess(ArrayList<QBChatHistoryMessage> messages, Bundle args) {

            try {
                qbShopAdpt = new QBShopkeeperChatAdapter(mContext, new ArrayList<QBMessage>(),customer_id,sh_r_id1);
                qbchatlv.setAdapter(qbShopAdpt);
                for(QBMessage msg : messages) {
                    if(customer_id.equals(msg.getProperty("customer_id")) && sh_r_id1.equals(msg.getProperty("sh_r_id")) && SessionManager.getSignIn(mContext).getId()==Integer.valueOf(msg.getProperty("sh_id"))){
                        showMessage(msg);
                    }
                }
            } catch (NullPointerException e) {
                Log.e(Tag, e.toString());
            }catch (NumberFormatException e) {
                Log.e(Tag, e.toString());
            }catch (Exception e) {
                Log.e(Tag, e.toString());
            }
            hideProgress();
        }

        @Override
        public void onError(List<String> errors) {
            AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
            dialog.setMessage("load chat history errors: " + errors).create().show();
        }
    });
}

1 个答案:

答案 0 :(得分:0)

尝试使用此代码保存聊天可能是我不确定

QBChatMessage chatMessage = new QBChatMessage();
chatMessage.setProperty("save_to_history", "1");

通过此

聊天
QBDialog qbDialog = new QBDialog("53cfc593efa3573ebd000017");
QBRequestGetBuilder requestBuilder = new QBRequestGetBuilder();
requestBuilder.setPagesLimit(100);
QBChatService.getDialogMessages(qbDialog, customObjectRequestBuilder, new
QBEntityCallbackImpl<ArrayList<QBChatMessage>>() {
@Override
public void onSuccess(ArrayList<QBChatMessage> messages, Bundle args) {
 }
 @Override
public void onError(List<String> errors) {

}
});

尝试通过此代码,您可以尝试通过此链接。 Here is Link