mirror of
https://github.com/WuKongIM/WuKongIMFlutterSDK
synced 2025-05-29 23:22:52 +00:00
fix:Modify synchronization. There is a problem with too much recent session data and failure to save
This commit is contained in:
parent
26b17fffc6
commit
fdecdbbfbe
@ -70,26 +70,53 @@ class ListViewShowDataState extends State<ListViewShowData> {
|
||||
}
|
||||
setState(() {});
|
||||
});
|
||||
// 监听更新消息事件
|
||||
WKIM.shared.conversationManager.addOnRefreshMsgListener('chat_conversation',
|
||||
(msg, isEnd) async {
|
||||
bool isAdd = true;
|
||||
for (var i = 0; i < msgList.length; i++) {
|
||||
if (msgList[i].msg.channelID == msg.channelID &&
|
||||
msgList[i].msg.channelType == msg.channelType) {
|
||||
msgList[i].msg = msg;
|
||||
msgList[i].lastContent = '';
|
||||
isAdd = false;
|
||||
break;
|
||||
WKIM.shared.conversationManager
|
||||
.addOnRefreshMsgListListener('chat_conversation', (msgs) {
|
||||
if (msgs.isEmpty) {
|
||||
return;
|
||||
}
|
||||
List<UIConversation> list = [];
|
||||
for (WKUIConversationMsg msg in msgs) {
|
||||
bool isAdd = true;
|
||||
for (var i = 0; i < msgList.length; i++) {
|
||||
if (msgList[i].msg.channelID == msg.channelID) {
|
||||
msgList[i].msg = msg;
|
||||
msgList[i].lastContent = '';
|
||||
isAdd = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isAdd) {
|
||||
list.add(UIConversation(msg));
|
||||
}
|
||||
}
|
||||
if (isAdd) {
|
||||
msgList.add(UIConversation(msg));
|
||||
if (list.isNotEmpty) {
|
||||
msgList.addAll(list);
|
||||
}
|
||||
if (isEnd && mounted) {
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
// 监听更新消息事件
|
||||
// WKIM.shared.conversationManager.addOnRefreshMsgListener('chat_conversation',
|
||||
// (msg, isEnd) async {
|
||||
// bool isAdd = true;
|
||||
// for (var i = 0; i < msgList.length; i++) {
|
||||
// if (msgList[i].msg.channelID == msg.channelID &&
|
||||
// msgList[i].msg.channelType == msg.channelType) {
|
||||
// msgList[i].msg = msg;
|
||||
// msgList[i].lastContent = '';
|
||||
// isAdd = false;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (isAdd) {
|
||||
// msgList.add(UIConversation(msg));
|
||||
// }
|
||||
// if (isEnd && mounted) {
|
||||
// setState(() {});
|
||||
// }
|
||||
// });
|
||||
// 监听刷新channel资料事件
|
||||
WKIM.shared.channelManager.addOnRefreshListener("cover_chat", (channel) {
|
||||
for (var i = 0; i < msgList.length; i++) {
|
||||
|
@ -54,19 +54,19 @@ class IMUtils {
|
||||
// 获取channel资料
|
||||
WKIM.shared.channelManager
|
||||
.addOnGetChannelListener((channelId, channelType, back) {
|
||||
print('获取channel资料');
|
||||
if (channelType == WKChannelType.personal) {
|
||||
// 获取个人资料
|
||||
// 这里直接返回了。实际情况可通过API请求后返回
|
||||
// 这里直接返回了
|
||||
// todo 实际情况可通过API请求后返回
|
||||
var channel = WKChannel(channelId, channelType);
|
||||
channel.channelName = "单聊${channel.channelID.hashCode}";
|
||||
channel.channelName = "【单聊】${channel.channelID}";
|
||||
var index = channel.channelID.hashCode % imgs.length;
|
||||
channel.avatar = imgs[index];
|
||||
back(channel);
|
||||
} else if (channelType == WKChannelType.group) {
|
||||
// 获取群资料
|
||||
var channel = WKChannel(channelId, channelType);
|
||||
channel.channelName = "群聊${channel.channelID.hashCode}";
|
||||
channel.channelName = "【群聊】${channel.channelID}";
|
||||
var index = channel.channelID.hashCode % imgs.length;
|
||||
channel.avatar = imgs[index];
|
||||
back(channel);
|
||||
|
@ -159,6 +159,12 @@ class WKDBConst {
|
||||
channel.deviceFlag = readInt(data, 'device_flag');
|
||||
channel.parentChannelID = readString(data, 'parent_channel_id');
|
||||
channel.parentChannelType = readInt(data, 'parent_channel_type');
|
||||
String parentChannelId = readString(data, 'c_parent_channel_id');
|
||||
int parentChannelType = readInt(data, 'c_parent_channel_type');
|
||||
if (parentChannelId != '') {
|
||||
channel.parentChannelID = parentChannelId;
|
||||
channel.parentChannelType = parentChannelType;
|
||||
}
|
||||
channel.createdAt = readString(data, 'created_at');
|
||||
channel.updatedAt = readString(data, 'updated_at');
|
||||
String remoteExtra = readString(data, 'remote_extra');
|
||||
|
@ -127,6 +127,21 @@ class ConversationDB {
|
||||
return list;
|
||||
}
|
||||
|
||||
insetMsgs(List<WKConversationMsg> list) async {
|
||||
List<Map<String, dynamic>> insertList = [];
|
||||
for (WKConversationMsg msg in list) {
|
||||
insertList.add(getMap(msg, true));
|
||||
}
|
||||
WKDBHelper.shared.getDB().transaction((txn) async {
|
||||
if (insertList.isNotEmpty) {
|
||||
for (int i = 0; i < insertList.length; i++) {
|
||||
txn.insert(WKDBConst.tableConversation, insertList[i],
|
||||
conflictAlgorithm: ConflictAlgorithm.replace);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
insertMsgList(List<WKConversationMsg> list) async {
|
||||
List<String> channelIds = [];
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
|
@ -608,6 +608,25 @@ class MessageDB {
|
||||
return msgs;
|
||||
}
|
||||
|
||||
Future<bool> insertMsgExtras(List<WKMsgExtra> list) async {
|
||||
if (list.isEmpty) {
|
||||
return true;
|
||||
}
|
||||
List<Map<String, Object>> insertCVList = [];
|
||||
for (int i = 0, size = list.length; i < size; i++) {
|
||||
insertCVList.add(getExtraMap(list[i]));
|
||||
}
|
||||
WKDBHelper.shared.getDB().transaction((txn) async {
|
||||
if (insertCVList.isNotEmpty) {
|
||||
for (int i = 0; i < insertCVList.length; i++) {
|
||||
txn.insert(WKDBConst.tableMessageExtra, insertCVList[i],
|
||||
conflictAlgorithm: ConflictAlgorithm.replace);
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<bool> insertOrUpdateMsgExtras(List<WKMsgExtra> list) async {
|
||||
List<String> msgIds = [];
|
||||
for (int i = 0, size = list.length; i < size; i++) {
|
||||
@ -635,7 +654,7 @@ class MessageDB {
|
||||
WKDBHelper.shared.getDB().transaction((txn) async {
|
||||
if (insertCVList.isNotEmpty) {
|
||||
for (int i = 0; i < insertCVList.length; i++) {
|
||||
txn.insert(WKDBConst.tableMessageExtra, insertCVList[0],
|
||||
txn.insert(WKDBConst.tableMessageExtra, insertCVList[i],
|
||||
conflictAlgorithm: ConflictAlgorithm.replace);
|
||||
}
|
||||
}
|
||||
|
@ -111,9 +111,8 @@ class ReminderDB {
|
||||
if (maps.containsKey(key) && maps[key] != null) {
|
||||
uiMsgList[i].setReminderList(maps[key]!);
|
||||
}
|
||||
WKIM.shared.conversationManager
|
||||
.setRefreshMsg(uiMsgList[i], i == list.length - 1);
|
||||
}
|
||||
WKIM.shared.conversationManager.setRefreshUIMsgs(uiMsgList);
|
||||
return reminderList;
|
||||
}
|
||||
|
||||
|
@ -463,7 +463,9 @@ class WKConnectionManager {
|
||||
WKUIConversationMsg? uiMsg =
|
||||
await WKIM.shared.conversationManager.saveWithLiMMsg(msg);
|
||||
if (uiMsg != null) {
|
||||
WKIM.shared.conversationManager.setRefreshMsg(uiMsg, true);
|
||||
List<WKUIConversationMsg> list = [];
|
||||
list.add(uiMsg);
|
||||
WKIM.shared.conversationManager.setRefreshUIMsgs(list);
|
||||
}
|
||||
} else {
|
||||
Logs.debug(
|
||||
|
@ -16,6 +16,7 @@ class WKConversationManager {
|
||||
static WKConversationManager get shared => _instance;
|
||||
|
||||
HashMap<String, Function(WKUIConversationMsg, bool)>? _refeshMsgMap;
|
||||
HashMap<String, Function(List<WKUIConversationMsg>)>? _refreshMsgListMap;
|
||||
HashMap<String, Function(String, int)>? _deleteMsgMap;
|
||||
HashMap<String, Function()>? _clearAllRedDotMap;
|
||||
|
||||
@ -97,7 +98,9 @@ class WKConversationManager {
|
||||
.queryMsgByMsgChannelId(channelID, channelType);
|
||||
if (msg != null) {
|
||||
var uiMsg = ConversationDB.shared.getUIMsg(msg);
|
||||
setRefreshMsg(uiMsg, true);
|
||||
List<WKUIConversationMsg> uiMsgs = [];
|
||||
uiMsgs.add(uiMsg);
|
||||
setRefreshUIMsgs(uiMsgs);
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,7 +142,7 @@ class WKConversationManager {
|
||||
}
|
||||
}
|
||||
|
||||
setRefreshMsg(WKUIConversationMsg msg, bool isEnd) {
|
||||
_setRefreshMsg(WKUIConversationMsg msg, bool isEnd) {
|
||||
if (_refeshMsgMap != null) {
|
||||
_refeshMsgMap!.forEach((key, back) {
|
||||
back(msg, isEnd);
|
||||
@ -147,6 +150,7 @@ class WKConversationManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Please replace with `addOnRefreshMsgListListener` method")
|
||||
addOnRefreshMsgListener(
|
||||
String key, Function(WKUIConversationMsg, bool) back) {
|
||||
_refeshMsgMap ??= HashMap();
|
||||
@ -159,6 +163,33 @@ class WKConversationManager {
|
||||
}
|
||||
}
|
||||
|
||||
setRefreshUIMsgs(List<WKUIConversationMsg> msgs) {
|
||||
_setRefreshMsgList(msgs);
|
||||
for (int i = 0, size = msgs.length; i < size; i++) {
|
||||
_setRefreshMsg(msgs[i], i == msgs.length - 1);
|
||||
}
|
||||
}
|
||||
|
||||
_setRefreshMsgList(List<WKUIConversationMsg> msgs) {
|
||||
if (_refreshMsgListMap != null) {
|
||||
_refreshMsgListMap!.forEach((key, back) {
|
||||
back(msgs);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
addOnRefreshMsgListListener(
|
||||
String key, Function(List<WKUIConversationMsg>) back) {
|
||||
_refreshMsgListMap ??= HashMap();
|
||||
_refreshMsgListMap![key] = back;
|
||||
}
|
||||
|
||||
removeOnRefreshMsgListListener(String key) {
|
||||
if (_refreshMsgListMap != null) {
|
||||
_refreshMsgListMap!.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
addOnSyncConversationListener(
|
||||
Function(String lastSsgSeqs, int msgCount, int version,
|
||||
Function(WKSyncConversation))
|
||||
@ -239,14 +270,16 @@ class WKConversationManager {
|
||||
}
|
||||
}
|
||||
if (msgExtraList.isNotEmpty) {
|
||||
MessageDB.shared.insertOrUpdateMsgExtras(msgExtraList);
|
||||
MessageDB.shared.insertMsgExtras(msgExtraList);
|
||||
// MessageDB.shared.insertOrUpdateMsgExtras(msgExtraList);
|
||||
}
|
||||
|
||||
if (msgList.isNotEmpty) {
|
||||
MessageDB.shared.insertMsgList(msgList);
|
||||
}
|
||||
if (conversationMsgList.isNotEmpty) {
|
||||
ConversationDB.shared.insertMsgList(conversationMsgList);
|
||||
// ConversationDB.shared.insertMsgList(conversationMsgList);
|
||||
ConversationDB.shared.insetMsgs(conversationMsgList);
|
||||
}
|
||||
if (msgReactionList.isNotEmpty) {
|
||||
ReactionDB.shared.insertOrUpdateReactionList(msgReactionList);
|
||||
@ -256,10 +289,7 @@ class WKConversationManager {
|
||||
WKIM.shared.messageManager.pushNewMsg(msgList);
|
||||
}
|
||||
if (uiMsgList.isNotEmpty) {
|
||||
for (int i = 0, size = uiMsgList.length; i < size; i++) {
|
||||
WKIM.shared.conversationManager
|
||||
.setRefreshMsg(uiMsgList[i], i == uiMsgList.length - 1);
|
||||
}
|
||||
setRefreshUIMsgs(uiMsgList);
|
||||
}
|
||||
if (syncChat.cmds != null && syncChat.cmds!.isNotEmpty) {
|
||||
for (int i = 0, size = syncChat.cmds!.length; i < size; i++) {
|
||||
|
@ -582,7 +582,9 @@ class WKMessageManager {
|
||||
WKUIConversationMsg? uiMsg =
|
||||
await WKIM.shared.conversationManager.saveWithLiMMsg(wkMsg);
|
||||
if (uiMsg != null) {
|
||||
WKIM.shared.conversationManager.setRefreshMsg(uiMsg, true);
|
||||
List<WKUIConversationMsg> uiMsgs = [];
|
||||
uiMsgs.add(uiMsg);
|
||||
WKIM.shared.conversationManager.setRefreshUIMsgs(uiMsgs);
|
||||
}
|
||||
}
|
||||
if (wkMsg.messageContent is WKMediaMessageContent) {
|
||||
@ -773,7 +775,9 @@ class WKMessageManager {
|
||||
var uiMsg =
|
||||
await WKIM.shared.conversationManager.saveWithLiMMsg(tempMsg);
|
||||
if (uiMsg != null) {
|
||||
WKIM.shared.conversationManager.setRefreshMsg(uiMsg, true);
|
||||
List<WKUIConversationMsg> uiMsgs = [];
|
||||
uiMsgs.add(uiMsg);
|
||||
WKIM.shared.conversationManager.setRefreshUIMsgs(uiMsgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user