getMessages static method

Future<void> getMessages(
  1. int conversationType,
  2. String targetId,
  3. HistoryMessageOption option,
  4. dynamic finished(
    1. List? msgList,
    2. int? code
    )?,
)

Implementation

static Future<void> getMessages(int conversationType, String targetId, HistoryMessageOption option, Function(List? /*<Message>*/ msgList, int? code)? finished) async {
  Map paramMap = {
    'conversationType': conversationType,
    'targetId': targetId,
    "count": option.count,
    "recordTime": option.recordTime,
    "order": option.order,
  };
  Map resultMap = await _channel.invokeMethod(RCMethodKey.GetMessages, paramMap);
  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);
    }
  }
}