insertOrUpdateWithConvMsg method
Implementation
Future<WKUIConversationMsg?> insertOrUpdateWithConvMsg(
WKConversationMsg conversationMsg) async {
if (WKDBHelper.shared.getDB() == null) {
return null;
}
int row;
WKConversationMsg? lastMsg = await queryMsgByMsgChannelId(
conversationMsg.channelID, conversationMsg.channelType);
if (lastMsg == null || lastMsg.channelID.isEmpty) {
row = await WKDBHelper.shared.getDB()!.insert(
WKDBConst.tableConversation, getMap(conversationMsg, false),
conflictAlgorithm: ConflictAlgorithm.replace);
} else {
// 这里有错误数据,需要清理
var len = lastMsg.localExtraMap?.toString().length ?? 0;
if (len < 1000000) {
conversationMsg.localExtraMap ??= lastMsg.localExtraMap;
}
conversationMsg.unreadCount =
lastMsg.unreadCount + conversationMsg.unreadCount;
row = await WKDBHelper.shared.getDB()!.update(
WKDBConst.tableConversation, getMap(conversationMsg, false),
where: "channel_id=? and channel_type=?",
whereArgs: [conversationMsg.channelID, conversationMsg.channelType]);
}
if (row > 0) {
return getUIMsg(conversationMsg);
}
return null;
}