searchMessages static method

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

根据会话,搜索本地历史消息。 搜索结果可分页返回。 conversationType 指定的会话类型。 targetId 指定的会话 id。 keyword 搜索的关键字。 count 返回的搜索结果数量, count > 0。 beginTime 查询记录的起始时间, 传0时从最新消息开始搜索。从该时间往前搜索。 resultCallback 搜索结果回调。

Implementation

static Future<void> searchMessages(int conversationType, String targetId, String keyword, int count, int beginTime, Function(List? /*<Message>*/ msgList, int? code)? finished) async {
  Map paramMap = {
    "conversationType": conversationType,
    "targetId": targetId,
    "keyword": keyword,
    "count": count,
    "beginTime": beginTime,
  };
  Map resultMap = await _channel.invokeMethod(RCMethodKey.SearchMessages, 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);
    }
  }
}