Message History

Update time: 2024/03/14 18:45:31

Local message history

Get local message history

Parameter Description

  • sessionId: If this parameter is provided, it will query messages of the session only.
  • sessionIds: If this parameter is provided, it will query limit messages from total messages of the session, but not every session will return acceptable limit messages.
  • start: It specifies the beginning time of query. By default, the parameter value is 0, which indicates no limit in the beginning time).
  • end specifies the end time. By default, the parameter value is Infinity, which indicates no limit in the end time. The 13-digit UTC timestamp (unit: ms) can be input.
  • desc specifies query direction. By default, the parameter value is "true" which indicates that messages are queried from end. The query result is sorted in a descending order by timestamp). If the value is set as "False", messages are sorted in ascending order by timestamp.
  • limit specifies the limit of quantity.
  • type specifies Message types. If this parameter is provided, query this type of messages.
  • types: If this parameter is provided, query these types of messages.
  • keyword: If this parameter is provided, query messages related to the keyword.
javascriptnim.getLocalMsgs({
  sessionId: 'p2p-account',// one-to-one chat(p2p). The account of party B is account.
  limit: 100,
  done: getLocalMsgsDone
})
function getLocalMsgsDone(error, obj) {
  console.log('get local message' + (!error?'succeeded':'failed’), error, obj)
}

Get local messages corresponding to idClient

  • If it does not Support database, successfully get local messages and return null.
javascriptnim.getLocalMsgByIdClient({
    idClient: 'd7a1b2c63066e1038e9aa01321652370',
    done: getLocalMsgByIdClientDone
});
function getLocalMsgByIdClientDone(error, obj) {
    console.log(error);
    console.log(obj);
    console.log('get local message' + (!error?'succeeded':'failed’));
    if (!error) {
        console.log(obj.msg);
    }
}

Get local messages corresponding to idClients

  • If it does not support database, it is successful and will return an empty array.
javascriptnim.getLocalMsgsByIdClients({
    idClients: [
        'd7a1b2c63066e1038e9aa01321652370',
        '22e604c7811c23586355f63f24658525'
    ],
    done: getLocalMsgsByIdClientsDone
});
function getLocalMsgsByIdClientsDone(error, obj) {
    console.log(error);
    console.log(obj);
    console.log('get local message' + (!error?'succeeded':'failed’));
    if (!error) {
        console.log(obj.msgs);
    }
}

Update local messages

  • Update local messages of idClient.
  • If it does not support database, it is successful.
  • If related messages do not exist, it is successful and will return null.
  • These fields will be updated to a local database, instead of the server.
javascript nim.updateLocalMsg({
     idClient: 'p2p-idClient',
     localCustom: '{"key","value"}',
     done: updateLocalMsgDone
 });
 function updateLocalMsgDone(error, obj) {
     console.log(error);
     console.log(obj);
     console.log('update local message' + (!error?'succeeded':'failed’));
 }

Delete local messages

  • If it does not support database, it is successful.
  • If related messages do not exist, it is successful.
javascriptnim.deleteLocalMsg({
    msg: msg,
    done: deleteLocalMsgDone
});
function deleteLocalMsgDone(error, obj) {
    console.log('delete local message' + (!error?'succeeded':'failed’), error, obj);
}

Delete local message of a certain session

  • If it does not support database, it is successful.
  • Parameter description
    • scene means scene, 'P2P' or 'team'.
    • to means chat object, account or team ID.
    • delLastMsg is bool type, which means lastMsg in local session object is deleted. By default, the parameter value is false.
javascriptnim.deleteLocalMsgsBySession({
    scene: 'p2p',
    to: 'account',
    delLastMsg: true,
    done: deleteLocalMsgsBySessionDone
});
function deleteLocalMsgsBySessionDone(error, obj) {
    console.log(error);
    console.log(obj);
    console.log('delete local message of the session' + (!error?'succeeded':'failed’));
}

Delete all local messages

  • If it does not support database, it is successful.
  • The method will clear all sessions, so that the developer shall clear session list in memory independently.
javascriptnim.deleteAllLocalMsgs({
    done: deleteAllLocalMsgsDone
});
function deleteAllLocalMsgsDone(error, obj) {
    console.log(error);
    console.log(obj);
    console.log('delete all local messages' + (!error?'succeeded':'failed’));
}

Cloud message history

Get cloud message history

  • Get message history of a certain session, and receive Messages array in callback function donefor results.
  • Parameter description
    • scene: Please refer to Message scenarios.
    • to: Account or team ID.
    • beginTime: It means begin time of query (0 by default, indicating no limitation in begin time).
    • endTime: endTime means end time (default value is current time of server). The 13-digit UTC timestamp (unit: ms) can be input.
    • lastMsgId: query starting from a certain message, which is combined with time parameter beginTime or endTime. The selection of time parameter depends on reverse parameter . During query, the time parameter is set to time of the message, and lastMsgId is set to idServer of the message. The message is not included in query results.
    • limit: It means limit of queried message count. The max. count is 100 and default value is 100.
    • reverse: The default false means to query message history forward from endTime; true means to query message history backward from beginTime.
    • asc: It means sorting method for query results by time. If asc and reverse are set to same value (i.e. "true" or "false"), query results are sorted in descending order by timestamp. If asc and reverse are set to different value, query results are sorted in ascending order by timestamp.
    • lastMsgId means idServer of the message as start point of query (the message will not be contained in query results). If reverse is false (default value), the parameter endTime must be set to corresponding time attribute of the message when lastMsgId is configured. If reverse is true, the parameter beginTime must be set to corresponding time attribute of the message when lastMsgId is configured.
  • The API is used to get message history of a certain time. The time range is determined by parameter beginTime and endTime.
    • If reverse isfalse, subsequent endTime corresponds to field time of the last message in the last query.
    • If reverse istrue, subsequent beginTime corresponds to field time of the last message in the last query.
javascriptnim.getHistoryMsgs({
    scene: 'p2p',
    to: 'a2',
    done: getHistoryMsgsDone
});
function getHistoryMsgsDone(error, obj) {
    console.log('get p2p message history' + (!error?'succeeded':'failed’));
    console.log(error);
    console.log(obj);
    if (!error) {
        console.log(obj.msgs);
    }
}

Delete P2P cloud message history

  • Parameter description
    • account: (Required) It is the account of friend. If you delete the chat history with your friend, you cannot query it any more, but your friend can do so. The clear time is subject to the time when server receives request.
    • delRoam: It means simultaneous deletion of roaming messages, true by default.
javascriptnim.clearServerHistoryMsgs({
    account: 'xxx',
    delRoam: false,
    done: clearServerHistoryMsgsDone
});
function clearServerHistoryMsgsDone(error, obj) {
    console.log('delete server message' + (!error?'succeeded':'failed’), error, obj);
}
Was this page helpful?
Yes
No
  • Local message history
  • Get local message history
  • Parameter Description
  • Get local messages corresponding to idClient
  • Get local messages corresponding to idClients
  • Update local messages
  • Delete local messages
  • Delete local message of a certain session
  • Delete all local messages
  • Cloud message history
  • Get cloud message history
  • Delete P2P cloud message history