历史记录

本地历史记录

获取本地历史记录

参数说明

nim.getLocalMsgs({
  sessionId: 'p2p-account',//表示单聊场景(p2p),对方账号为account。
  limit: 100,
  done: getLocalMsgsDone
})
function getLocalMsgsDone(error, obj) {
  console.log('获取本地消息' + (!error?'成功':'失败'), error, obj)
}

获取 idClient 对应的本地消息

nim.getLocalMsgByIdClient({
    idClient: 'd7a1b2c63066e1038e9aa01321652370',
    done: getLocalMsgByIdClientDone
});
function getLocalMsgByIdClientDone(error, obj) {
    console.log(error);
    console.log(obj);
    console.log('获取本地消息' + (!error?'成功':'失败'));
    if (!error) {
        console.log(obj.msg);
    }
}

获取 idClients 对应的本地消息

nim.getLocalMsgsByIdClients({
    idClients: [
        'd7a1b2c63066e1038e9aa01321652370',
        '22e604c7811c23586355f63f24658525'
    ],
    done: getLocalMsgsByIdClientsDone
});
function getLocalMsgsByIdClientsDone(error, obj) {
    console.log(error);
    console.log(obj);
    console.log('获取本地消息' + (!error?'成功':'失败'));
    if (!error) {
        console.log(obj.msgs);
    }
}

更新本地消息

 nim.updateLocalMsg({
     idClient: 'p2p-idClient',
     localCustom: '{"key","value"}',
     done: updateLocalMsgDone
 });
 function updateLocalMsgDone(error, obj) {
     console.log(error);
     console.log(obj);
     console.log('更新本地消息' + (!error?'成功':'失败'));
 }

删除本地消息

nim.deleteLocalMsg({
    msg: msg,
    done: deleteLocalMsgDone
});
function deleteLocalMsgDone(error, obj) {
    console.log('删除本地消息' + (!error?'成功':'失败'), error, obj);
}

删除某个会话的本地消息

nim.deleteLocalMsgsBySession({
    scene: 'p2p',
    to: 'account',
    delLastMsg: true,
    done: deleteLocalMsgsBySessionDone
});
function deleteLocalMsgsBySessionDone(error, obj) {
    console.log(error);
    console.log(obj);
    console.log('删除会话本地消息' + (!error?'成功':'失败'));
}

删除所有本地消息

nim.deleteAllLocalMsgs({
    done: deleteAllLocalMsgsDone
});
function deleteAllLocalMsgsDone(error, obj) {
    console.log(error);
    console.log(obj);
    console.log('删除所有本地消息' + (!error?'成功':'失败'));
}

云端历史记录

获取云端历史记录

nim.getHistoryMsgs({
    scene: 'p2p',
    to: 'a2',
    done: getHistoryMsgsDone
});
function getHistoryMsgsDone(error, obj) {
    console.log('获取p2p历史消息' + (!error?'成功':'失败'));
    console.log(error);
    console.log(obj);
    if (!error) {
        console.log(obj.msgs);
    }
}

删除点对点云端历史记录

nim.clearServerHistoryMsgs({
    account: 'xxx',
    delRoam: false,
    done: clearServerHistoryMsgsDone
});
function clearServerHistoryMsgsDone(error, obj) {
    console.log('删除服务器消息' + (!error?'成功':'失败'), error, obj);
}