getHistoryMessages method

Future<List> getHistoryMessages (
  1. {@required dynamic type,
  2. @required int from,
  3. @required int limit,
  4. bool isDescend: false}
)

批量获取本地历史消息

@param target 聊天对象, JMSingle | JMGroup @param from 起始位置 @param limit 获取数量 @param isDescend 是否倒叙

Implementation

Future<List> getHistoryMessages({
  @required dynamic type, /// (JMSingle | JMGroup)
  @required int from,
  @required int limit,
  bool isDescend = false
}) async {
  Map param = type.toJson();

  param..addAll({
    'from': from,
    'limit': limit,
    'isDescend': isDescend
    });

  List resArr = await _channel.invokeMethod('getHistoryMessages',
    param..removeWhere((key,value) => value == null));

  List res = [];
  for (Map messageMap in resArr) {
    dynamic d = JMNormalMessage.generateMessageFromJson(messageMap);
    if (d != null) {
      res.add(d);
    }else{
      print("get history msg, get a message is null");
    }
  }
  //var res = resArr.map((messageMap) => JMNormalMessage.generateMessageFromJson(messageMap)).toList();
  return res;
}