getRemoteHistoryMessages static method

Future<void> getRemoteHistoryMessages(
  1. int conversationType,
  2. String targetId,
  3. int recordTime,
  4. int count,
  5. dynamic finished(
    1. List? msgList,
    2. int? code
    )?,
)

返回一个Map {"code":...,"messages":...,"isRemaining":...} code:是否获取成功 messages:获取到的历史消息数组, isRemaining:是否还有剩余消息 YES 表示还有剩余,NO 表示无剩余

conversationType 会话类型,参见枚举 RCConversationType

targetId 聊天室的会话ID

recordTime 起始的消息发送时间戳,毫秒

count 需要获取的消息数量, 0 < count <= 200

此方法从服务器端获取之前的历史消息,但是必须先开通历史消息云存储功能。 例如,本地会话中有10条消息,您想拉取更多保存在服务器的消息的话,recordTime应传入最早的消息的发送时间戳,count传入1~20之间的数值。

Implementation

static Future<void> getRemoteHistoryMessages(int conversationType, String targetId, int recordTime, int count, Function(List? /*<Message>*/ msgList, int? code)? finished) async {
  Map map = {'conversationType': conversationType, 'targetId': targetId, 'recordTime': recordTime, 'count': count};
  Map resultMap = await _channel.invokeMethod(RCMethodCallBackKey.GetRemoteHistoryMessages, map);
  int? code = resultMap["code"];
  if (code == 0) {
    List? msgStrList = resultMap["messages"];
    if (msgStrList == null) {
      if (finished != null) {
        finished(null, code);
      }
      return;
    }
    List l = [];
    for (String msgStr in msgStrList) {
      Message? m = MessageFactory.instance!.string2Message(msgStr);
      l.add(m);
    }
    if (finished != null) {
      finished(l, code);
    }
  } else {
    if (finished != null) {
      finished(null, code);
    }
  }
}