mirror of
https://github.com/WuKongIM/WuKongIMFlutterSDK
synced 2025-06-01 16:42:48 +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,13 +70,16 @@ class ListViewShowDataState extends State<ListViewShowData> {
|
|||||||
}
|
}
|
||||||
setState(() {});
|
setState(() {});
|
||||||
});
|
});
|
||||||
// 监听更新消息事件
|
WKIM.shared.conversationManager
|
||||||
WKIM.shared.conversationManager.addOnRefreshMsgListener('chat_conversation',
|
.addOnRefreshMsgListListener('chat_conversation', (msgs) {
|
||||||
(msg, isEnd) async {
|
if (msgs.isEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<UIConversation> list = [];
|
||||||
|
for (WKUIConversationMsg msg in msgs) {
|
||||||
bool isAdd = true;
|
bool isAdd = true;
|
||||||
for (var i = 0; i < msgList.length; i++) {
|
for (var i = 0; i < msgList.length; i++) {
|
||||||
if (msgList[i].msg.channelID == msg.channelID &&
|
if (msgList[i].msg.channelID == msg.channelID) {
|
||||||
msgList[i].msg.channelType == msg.channelType) {
|
|
||||||
msgList[i].msg = msg;
|
msgList[i].msg = msg;
|
||||||
msgList[i].lastContent = '';
|
msgList[i].lastContent = '';
|
||||||
isAdd = false;
|
isAdd = false;
|
||||||
@ -84,12 +87,36 @@ class ListViewShowDataState extends State<ListViewShowData> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isAdd) {
|
if (isAdd) {
|
||||||
msgList.add(UIConversation(msg));
|
list.add(UIConversation(msg));
|
||||||
}
|
}
|
||||||
if (isEnd && mounted) {
|
}
|
||||||
|
if (list.isNotEmpty) {
|
||||||
|
msgList.addAll(list);
|
||||||
|
}
|
||||||
|
if (mounted) {
|
||||||
setState(() {});
|
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资料事件
|
// 监听刷新channel资料事件
|
||||||
WKIM.shared.channelManager.addOnRefreshListener("cover_chat", (channel) {
|
WKIM.shared.channelManager.addOnRefreshListener("cover_chat", (channel) {
|
||||||
for (var i = 0; i < msgList.length; i++) {
|
for (var i = 0; i < msgList.length; i++) {
|
||||||
|
@ -54,19 +54,19 @@ class IMUtils {
|
|||||||
// 获取channel资料
|
// 获取channel资料
|
||||||
WKIM.shared.channelManager
|
WKIM.shared.channelManager
|
||||||
.addOnGetChannelListener((channelId, channelType, back) {
|
.addOnGetChannelListener((channelId, channelType, back) {
|
||||||
print('获取channel资料');
|
|
||||||
if (channelType == WKChannelType.personal) {
|
if (channelType == WKChannelType.personal) {
|
||||||
// 获取个人资料
|
// 获取个人资料
|
||||||
// 这里直接返回了。实际情况可通过API请求后返回
|
// 这里直接返回了
|
||||||
|
// todo 实际情况可通过API请求后返回
|
||||||
var channel = WKChannel(channelId, channelType);
|
var channel = WKChannel(channelId, channelType);
|
||||||
channel.channelName = "单聊${channel.channelID.hashCode}";
|
channel.channelName = "【单聊】${channel.channelID}";
|
||||||
var index = channel.channelID.hashCode % imgs.length;
|
var index = channel.channelID.hashCode % imgs.length;
|
||||||
channel.avatar = imgs[index];
|
channel.avatar = imgs[index];
|
||||||
back(channel);
|
back(channel);
|
||||||
} else if (channelType == WKChannelType.group) {
|
} else if (channelType == WKChannelType.group) {
|
||||||
// 获取群资料
|
// 获取群资料
|
||||||
var channel = WKChannel(channelId, channelType);
|
var channel = WKChannel(channelId, channelType);
|
||||||
channel.channelName = "群聊${channel.channelID.hashCode}";
|
channel.channelName = "【群聊】${channel.channelID}";
|
||||||
var index = channel.channelID.hashCode % imgs.length;
|
var index = channel.channelID.hashCode % imgs.length;
|
||||||
channel.avatar = imgs[index];
|
channel.avatar = imgs[index];
|
||||||
back(channel);
|
back(channel);
|
||||||
|
@ -159,6 +159,12 @@ class WKDBConst {
|
|||||||
channel.deviceFlag = readInt(data, 'device_flag');
|
channel.deviceFlag = readInt(data, 'device_flag');
|
||||||
channel.parentChannelID = readString(data, 'parent_channel_id');
|
channel.parentChannelID = readString(data, 'parent_channel_id');
|
||||||
channel.parentChannelType = readInt(data, 'parent_channel_type');
|
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.createdAt = readString(data, 'created_at');
|
||||||
channel.updatedAt = readString(data, 'updated_at');
|
channel.updatedAt = readString(data, 'updated_at');
|
||||||
String remoteExtra = readString(data, 'remote_extra');
|
String remoteExtra = readString(data, 'remote_extra');
|
||||||
|
@ -127,6 +127,21 @@ class ConversationDB {
|
|||||||
return list;
|
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 {
|
insertMsgList(List<WKConversationMsg> list) async {
|
||||||
List<String> channelIds = [];
|
List<String> channelIds = [];
|
||||||
for (var i = 0; i < list.length; i++) {
|
for (var i = 0; i < list.length; i++) {
|
||||||
|
@ -608,6 +608,25 @@ class MessageDB {
|
|||||||
return msgs;
|
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 {
|
Future<bool> insertOrUpdateMsgExtras(List<WKMsgExtra> list) async {
|
||||||
List<String> msgIds = [];
|
List<String> msgIds = [];
|
||||||
for (int i = 0, size = list.length; i < size; i++) {
|
for (int i = 0, size = list.length; i < size; i++) {
|
||||||
@ -635,7 +654,7 @@ class MessageDB {
|
|||||||
WKDBHelper.shared.getDB().transaction((txn) async {
|
WKDBHelper.shared.getDB().transaction((txn) async {
|
||||||
if (insertCVList.isNotEmpty) {
|
if (insertCVList.isNotEmpty) {
|
||||||
for (int i = 0; i < insertCVList.length; i++) {
|
for (int i = 0; i < insertCVList.length; i++) {
|
||||||
txn.insert(WKDBConst.tableMessageExtra, insertCVList[0],
|
txn.insert(WKDBConst.tableMessageExtra, insertCVList[i],
|
||||||
conflictAlgorithm: ConflictAlgorithm.replace);
|
conflictAlgorithm: ConflictAlgorithm.replace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,9 +111,8 @@ class ReminderDB {
|
|||||||
if (maps.containsKey(key) && maps[key] != null) {
|
if (maps.containsKey(key) && maps[key] != null) {
|
||||||
uiMsgList[i].setReminderList(maps[key]!);
|
uiMsgList[i].setReminderList(maps[key]!);
|
||||||
}
|
}
|
||||||
WKIM.shared.conversationManager
|
|
||||||
.setRefreshMsg(uiMsgList[i], i == list.length - 1);
|
|
||||||
}
|
}
|
||||||
|
WKIM.shared.conversationManager.setRefreshUIMsgs(uiMsgList);
|
||||||
return reminderList;
|
return reminderList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,7 +463,9 @@ class WKConnectionManager {
|
|||||||
WKUIConversationMsg? uiMsg =
|
WKUIConversationMsg? uiMsg =
|
||||||
await WKIM.shared.conversationManager.saveWithLiMMsg(msg);
|
await WKIM.shared.conversationManager.saveWithLiMMsg(msg);
|
||||||
if (uiMsg != null) {
|
if (uiMsg != null) {
|
||||||
WKIM.shared.conversationManager.setRefreshMsg(uiMsg, true);
|
List<WKUIConversationMsg> list = [];
|
||||||
|
list.add(uiMsg);
|
||||||
|
WKIM.shared.conversationManager.setRefreshUIMsgs(list);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Logs.debug(
|
Logs.debug(
|
||||||
|
@ -16,6 +16,7 @@ class WKConversationManager {
|
|||||||
static WKConversationManager get shared => _instance;
|
static WKConversationManager get shared => _instance;
|
||||||
|
|
||||||
HashMap<String, Function(WKUIConversationMsg, bool)>? _refeshMsgMap;
|
HashMap<String, Function(WKUIConversationMsg, bool)>? _refeshMsgMap;
|
||||||
|
HashMap<String, Function(List<WKUIConversationMsg>)>? _refreshMsgListMap;
|
||||||
HashMap<String, Function(String, int)>? _deleteMsgMap;
|
HashMap<String, Function(String, int)>? _deleteMsgMap;
|
||||||
HashMap<String, Function()>? _clearAllRedDotMap;
|
HashMap<String, Function()>? _clearAllRedDotMap;
|
||||||
|
|
||||||
@ -97,7 +98,9 @@ class WKConversationManager {
|
|||||||
.queryMsgByMsgChannelId(channelID, channelType);
|
.queryMsgByMsgChannelId(channelID, channelType);
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
var uiMsg = ConversationDB.shared.getUIMsg(msg);
|
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) {
|
if (_refeshMsgMap != null) {
|
||||||
_refeshMsgMap!.forEach((key, back) {
|
_refeshMsgMap!.forEach((key, back) {
|
||||||
back(msg, isEnd);
|
back(msg, isEnd);
|
||||||
@ -147,6 +150,7 @@ class WKConversationManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Please replace with `addOnRefreshMsgListListener` method")
|
||||||
addOnRefreshMsgListener(
|
addOnRefreshMsgListener(
|
||||||
String key, Function(WKUIConversationMsg, bool) back) {
|
String key, Function(WKUIConversationMsg, bool) back) {
|
||||||
_refeshMsgMap ??= HashMap();
|
_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(
|
addOnSyncConversationListener(
|
||||||
Function(String lastSsgSeqs, int msgCount, int version,
|
Function(String lastSsgSeqs, int msgCount, int version,
|
||||||
Function(WKSyncConversation))
|
Function(WKSyncConversation))
|
||||||
@ -239,14 +270,16 @@ class WKConversationManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (msgExtraList.isNotEmpty) {
|
if (msgExtraList.isNotEmpty) {
|
||||||
MessageDB.shared.insertOrUpdateMsgExtras(msgExtraList);
|
MessageDB.shared.insertMsgExtras(msgExtraList);
|
||||||
|
// MessageDB.shared.insertOrUpdateMsgExtras(msgExtraList);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msgList.isNotEmpty) {
|
if (msgList.isNotEmpty) {
|
||||||
MessageDB.shared.insertMsgList(msgList);
|
MessageDB.shared.insertMsgList(msgList);
|
||||||
}
|
}
|
||||||
if (conversationMsgList.isNotEmpty) {
|
if (conversationMsgList.isNotEmpty) {
|
||||||
ConversationDB.shared.insertMsgList(conversationMsgList);
|
// ConversationDB.shared.insertMsgList(conversationMsgList);
|
||||||
|
ConversationDB.shared.insetMsgs(conversationMsgList);
|
||||||
}
|
}
|
||||||
if (msgReactionList.isNotEmpty) {
|
if (msgReactionList.isNotEmpty) {
|
||||||
ReactionDB.shared.insertOrUpdateReactionList(msgReactionList);
|
ReactionDB.shared.insertOrUpdateReactionList(msgReactionList);
|
||||||
@ -256,10 +289,7 @@ class WKConversationManager {
|
|||||||
WKIM.shared.messageManager.pushNewMsg(msgList);
|
WKIM.shared.messageManager.pushNewMsg(msgList);
|
||||||
}
|
}
|
||||||
if (uiMsgList.isNotEmpty) {
|
if (uiMsgList.isNotEmpty) {
|
||||||
for (int i = 0, size = uiMsgList.length; i < size; i++) {
|
setRefreshUIMsgs(uiMsgList);
|
||||||
WKIM.shared.conversationManager
|
|
||||||
.setRefreshMsg(uiMsgList[i], i == uiMsgList.length - 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (syncChat.cmds != null && syncChat.cmds!.isNotEmpty) {
|
if (syncChat.cmds != null && syncChat.cmds!.isNotEmpty) {
|
||||||
for (int i = 0, size = syncChat.cmds!.length; i < size; i++) {
|
for (int i = 0, size = syncChat.cmds!.length; i < size; i++) {
|
||||||
|
@ -582,7 +582,9 @@ class WKMessageManager {
|
|||||||
WKUIConversationMsg? uiMsg =
|
WKUIConversationMsg? uiMsg =
|
||||||
await WKIM.shared.conversationManager.saveWithLiMMsg(wkMsg);
|
await WKIM.shared.conversationManager.saveWithLiMMsg(wkMsg);
|
||||||
if (uiMsg != null) {
|
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) {
|
if (wkMsg.messageContent is WKMediaMessageContent) {
|
||||||
@ -773,7 +775,9 @@ class WKMessageManager {
|
|||||||
var uiMsg =
|
var uiMsg =
|
||||||
await WKIM.shared.conversationManager.saveWithLiMMsg(tempMsg);
|
await WKIM.shared.conversationManager.saveWithLiMMsg(tempMsg);
|
||||||
if (uiMsg != null) {
|
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