getHistoryMessageList method
Implementation
Future<V2TimValueCallback<List<V2TimMessage>>> getHistoryMessageList({
HistoryMsgGetTypeEnum? getType,
String? userID,
String? groupID,
int? lastMsgSeq,
required int count,
String? lastMsgID,
List<int>? messageTypeList,
List<int>? messageSeqList,
int? timeBegin,
int? timePeriod,
}) async {
if (!TIMManager.instance.isInitSDK()) {
return V2TimValueCallback<List<V2TimMessage>>(code: TIMErrCode.ERR_SDK_NOT_INITIALIZED.value, desc: "sdk not init");
}
if ((userID == null || userID.isEmpty) && (groupID == null || groupID.isEmpty)) {
return V2TimValueCallback<List<V2TimMessage>>(code: TIMErrCode.ERR_INVALID_PARAMETERS.value, desc: "invalid userID and groupID");
}
V2TimMessage? lastMessage;
if (lastMsgID != null) {
V2TimValueCallback<List<V2TimMessage>> findResult = await findMessages(messageIDList: [lastMsgID]);
if (findResult.code != TIMErrCode.ERR_SUCC.value) {
print("getHistoryMessageList, find last message failed");
return V2TimValueCallback<List<V2TimMessage>>(code: findResult.code, desc: findResult.desc);
}
List<V2TimMessage> msgList = findResult.data!;
if (msgList.isNotEmpty) {
lastMessage = msgList[0];
}
}
String userData = Tools.generateUserData('getHistoryMessageList');
Completer<V2TimValueCallback<List<V2TimMessage>>> completer = Completer();
NativeLibraryManager.timValueCallback2Future<List<V2TimMessage>>(userData, completer);
String convID = '';
TIMConvType convType = TIMConvType.kTIMConv_Group;
if (groupID != null && groupID.isNotEmpty) {
convID = groupID;
convType = TIMConvType.kTIMConv_Group;
} else {
convID = userID!;
convType = TIMConvType.kTIMConv_C2C;
}
V2TimMessageGetHistoryMessageListParam param = V2TimMessageGetHistoryMessageListParam(count: count, getType: getType, lastMessage: lastMessage, lastMessageSeq: lastMsgSeq, timeBegin: timeBegin, timePeriod: timePeriod, messageTypeList: messageTypeList, messageSeqList: messageSeqList);
Pointer<Char> pParam = Tools.string2PointerChar(json.encode(param.toJson()));
Pointer<Char> pConvID = Tools.string2PointerChar(convID);
Pointer<Void> pUserData = Tools.string2PointerVoid(userData);
NativeLibraryManager.bindings.DartGetHistoryMessageList(pConvID, convType, pParam, pUserData);
return completer.future;
}