getHistoryMessages static method

Future<List?> getHistoryMessages(
  1. int? conversationType,
  2. String? targetId,
  3. int sentTime,
  4. int beforeCount,
  5. int afterCount,
)

获取特定方向的历史消息

conversationType 会话类型,参见枚举 RCConversationType

targetId 会话 id

sentTime 消息的发送时间

beforeCount 指定消息的前部分消息数量

afterCount 指定消息的后部分消息数量

return 获取到的消息列表

Implementation

static Future<List?> getHistoryMessages(int? conversationType, String? targetId, int sentTime, int beforeCount, int afterCount) async {
  if (conversationType == null || targetId == null) {
    developer.log("getHistoryMessages error: conversationType or targetId null", name: "RongIMClient");
    return null;
  }
  Map map = {
    'conversationType': conversationType,
    'targetId': targetId,
    "sentTime": TypeUtil.getProperInt(sentTime),
    "beforeCount": TypeUtil.getProperInt(beforeCount),
    "afterCount": TypeUtil.getProperInt(afterCount),
  };
  List? list = await _channel.invokeMethod(RCMethodKey.GetHistoryMessages, map);
  if (list == null) {
    return [];
  }
  List msgList = [];
  for (String msgStr in list) {
    Message? msg = MessageFactory.instance!.string2Message(msgStr);
    msgList.add(msg);
  }
  return msgList;
}