mirror of
https://github.com/WuKongIM/WuKongIMFlutterSDK
synced 2025-05-28 22:52:20 +00:00
fix: synchronization channel message multiple synchronization issue
This commit is contained in:
parent
4c83ae1697
commit
6459f2ed7e
@ -59,4 +59,6 @@
|
||||
### 1.2.9
|
||||
* Modification of sending messages containing replies or tag class message parsing errors
|
||||
### 1.3.0
|
||||
* Modification of sending messages containing replies error
|
||||
* Modification of sending messages containing replies error
|
||||
### 1.3.1
|
||||
* fix: synchronization channel message multiple synchronization issue
|
@ -9,7 +9,7 @@
|
||||
#### 安装
|
||||
```
|
||||
dependencies:
|
||||
wukongimfluttersdk: ^1.3.0
|
||||
wukongimfluttersdk: ^1.3.1
|
||||
```
|
||||
#### 引入
|
||||
```dart
|
||||
|
@ -143,7 +143,6 @@ class ChatListDataState extends State<ChatList> {
|
||||
oldestOrderSeq, oldestOrderSeq == 0, pullMode, 20, 0, (list) {
|
||||
List<UIMsg> uiList = [];
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
print(list[i].orderSeq);
|
||||
if (pullMode == 0 && !isReset) {
|
||||
uiList.add(UIMsg(list[i]));
|
||||
// msgList.insert(0, UIMsg(list[i]));
|
||||
|
@ -32,7 +32,6 @@ class HttpUtils {
|
||||
|
||||
static syncConversation(String lastSsgSeqs, int msgCount, int version,
|
||||
Function(WKSyncConversation) back) async {
|
||||
print("同步最近会话的参数${version}");
|
||||
final dio = Dio();
|
||||
final response = await dio.post('$apiURL/conversation/sync', data: {
|
||||
"uid": UserInfo.uid, // 当前登录用户uid
|
||||
@ -81,7 +80,6 @@ class HttpUtils {
|
||||
int pullMode,
|
||||
Function(WKSyncChannelMsg) back) async {
|
||||
final dio = Dio();
|
||||
print('请求参数${startMsgSeq},$endMsgSeq');
|
||||
final response = await dio.post('$apiURL/channel/messagesync', data: {
|
||||
"login_uid": UserInfo.uid, // 当前登录用户uid
|
||||
"channel_id": channelID, // 频道ID
|
||||
@ -117,7 +115,6 @@ class HttpUtils {
|
||||
msg.messageSeq = json['message_seq'];
|
||||
msg.fromUID = json['from_uid'];
|
||||
msg.timestamp = json['timestamp'];
|
||||
msg.channelID = json['channel_id'];
|
||||
// msg.payload = json['payload'];
|
||||
String payload = json['payload'];
|
||||
try {
|
||||
|
@ -63,11 +63,11 @@ class LoginDemoState extends State<LoginDemo> {
|
||||
body: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 60.0),
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(top: 60.0),
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: const [
|
||||
children: [
|
||||
Text(
|
||||
'悟空IM登录',
|
||||
style:
|
||||
|
@ -196,7 +196,6 @@ class MessageDB {
|
||||
List<String> fromUIDs = [];
|
||||
List<Map<String, Object?>> results =
|
||||
await WKDBHelper.shared.getDB().rawQuery(sql, args);
|
||||
|
||||
if (results.isNotEmpty) {
|
||||
WKChannel? wkChannel =
|
||||
await ChannelDB.shared.query(channelId, channelType);
|
||||
@ -321,6 +320,7 @@ class MessageDB {
|
||||
//获取原始数据
|
||||
List<WKMsg> list = await getMessages(
|
||||
channelId, channelType, oldestOrderSeq, contain, pullMode, limit);
|
||||
print("查询总数量${list.length}");
|
||||
//业务判断数据
|
||||
List<WKMsg> tempList = [];
|
||||
for (int i = 0, size = list.length; i < size; i++) {
|
||||
@ -413,7 +413,6 @@ class MessageDB {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isSyncMsg) {
|
||||
if (minMessageSeq == 1) {
|
||||
requestCount = 0;
|
||||
@ -422,20 +421,28 @@ class MessageDB {
|
||||
}
|
||||
}
|
||||
//计算最后一页后是否还存在消息
|
||||
int syncLimit = limit;
|
||||
if (!isSyncMsg && tempList.length < limit) {
|
||||
if (pullMode == 0) {
|
||||
//如果下拉获取数据
|
||||
isSyncMsg = true;
|
||||
startMsgSeq = oldestMsgSeq;
|
||||
// startMsgSeq = oldestMsgSeq;
|
||||
startMsgSeq = minMessageSeq; // 不满足查询数量同步时按查询到的最小seq开始同步
|
||||
if (!contain) {
|
||||
syncLimit = syncLimit + 1;
|
||||
}
|
||||
endMsgSeq = 0;
|
||||
} else {
|
||||
//如果上拉获取数据
|
||||
isSyncMsg = true;
|
||||
startMsgSeq = oldestMsgSeq;
|
||||
// startMsgSeq = oldestMsgSeq;
|
||||
startMsgSeq = maxMessageSeq; // 不满足查询数量同步时按查询到的最大seq开始同步
|
||||
endMsgSeq = 0;
|
||||
if (!contain) {
|
||||
syncLimit = syncLimit + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isSyncMsg &&
|
||||
(startMsgSeq != endMsgSeq || (startMsgSeq == 0 && endMsgSeq == 0)) &&
|
||||
requestCount < 5) {
|
||||
@ -445,7 +452,7 @@ class MessageDB {
|
||||
//同步消息
|
||||
requestCount++;
|
||||
WKIM.shared.messageManager.setSyncChannelMsgListener(
|
||||
channelId, channelType, startMsgSeq, endMsgSeq, limit, pullMode,
|
||||
channelId, channelType, startMsgSeq, endMsgSeq, syncLimit, pullMode,
|
||||
(syncChannelMsg) {
|
||||
if (syncChannelMsg != null &&
|
||||
syncChannelMsg.messages != null &&
|
||||
@ -500,11 +507,11 @@ class MessageDB {
|
||||
return messageSeq;
|
||||
}
|
||||
|
||||
insertMsgList(List<WKMsg> list) async {
|
||||
if (list.isEmpty) return;
|
||||
Future<bool> insertMsgList(List<WKMsg> list) async {
|
||||
if (list.isEmpty) return true;
|
||||
if (list.length == 1) {
|
||||
insert(list[0]);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
List<WKMsg> saveList = [];
|
||||
for (int i = 0, size = list.length; i < size; i++) {
|
||||
@ -568,6 +575,7 @@ class MessageDB {
|
||||
}
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<List<WKMsg>> queryWithClientMsgNos(List<String> clientMsgNos) async {
|
||||
|
@ -57,31 +57,37 @@ class ReactionDB {
|
||||
return list;
|
||||
}
|
||||
|
||||
insertOrUpdateReactionList(List<WKMsgReaction> list) {
|
||||
if (list.isEmpty) return;
|
||||
Future<bool> insertOrUpdateReactionList(List<WKMsgReaction> list) async {
|
||||
if (list.isEmpty) return true;
|
||||
bool isSuccess = true;
|
||||
for (int i = 0, size = list.length; i < size; i++) {
|
||||
insertOrUpdateReaction(list[i]);
|
||||
// insertOrUpdateReaction(list[i]);
|
||||
int row = await insertReaction(list[i]);
|
||||
if (isSuccess) {
|
||||
isSuccess = row > 0;
|
||||
}
|
||||
}
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
insertOrUpdateReaction(WKMsgReaction reaction) async {
|
||||
bool isExist = await isExistReaction(reaction.uid, reaction.messageID);
|
||||
if (isExist) {
|
||||
updateReaction(reaction);
|
||||
} else {
|
||||
insertReaction(reaction);
|
||||
}
|
||||
}
|
||||
// insertOrUpdateReaction(WKMsgReaction reaction) async {
|
||||
// bool isExist = await isExistReaction(reaction.uid, reaction.messageID);
|
||||
// if (isExist) {
|
||||
// updateReaction(reaction);
|
||||
// } else {
|
||||
// insertReaction(reaction);
|
||||
// }
|
||||
// }
|
||||
|
||||
updateReaction(WKMsgReaction reaction) {
|
||||
var map = <String, Object>{};
|
||||
map['is_deleted'] = reaction.isDeleted;
|
||||
map['seq'] = reaction.seq;
|
||||
map['emoji'] = reaction.emoji;
|
||||
WKDBHelper.shared.getDB().update(WKDBConst.tableMessageReaction, map,
|
||||
where: "message_id=? and uid=?",
|
||||
whereArgs: [reaction.messageID, reaction.uid]);
|
||||
}
|
||||
// updateReaction(WKMsgReaction reaction) {
|
||||
// var map = <String, Object>{};
|
||||
// map['is_deleted'] = reaction.isDeleted;
|
||||
// map['seq'] = reaction.seq;
|
||||
// map['emoji'] = reaction.emoji;
|
||||
// WKDBHelper.shared.getDB().update(WKDBConst.tableMessageReaction, map,
|
||||
// where: "message_id=? and uid=?",
|
||||
// whereArgs: [reaction.messageID, reaction.uid]);
|
||||
// }
|
||||
|
||||
insertReaction(WKMsgReaction reaction) {
|
||||
WKDBHelper.shared.getDB().insert(
|
||||
|
@ -186,19 +186,20 @@ class WKMessageManager {
|
||||
int endMessageSeq,
|
||||
int limit,
|
||||
int pullMode,
|
||||
Function(WKSyncChannelMsg?) back) {
|
||||
Function(WKSyncChannelMsg?) back) async {
|
||||
if (_syncChannelMsgBack != null) {
|
||||
_syncChannelMsgBack!(channelID, channelType, startMessageSeq,
|
||||
endMessageSeq, limit, pullMode, (result) {
|
||||
endMessageSeq, limit, pullMode, (result) async {
|
||||
if (result != null && result.messages != null) {
|
||||
_saveSyncChannelMSGs(result.messages!);
|
||||
_saveSyncChannelMSGs(result.messages!).then((value) => back(result));
|
||||
} else {
|
||||
back(result);
|
||||
}
|
||||
back(result);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_saveSyncChannelMSGs(List<WKSyncMsg> list) {
|
||||
Future<bool> _saveSyncChannelMSGs(List<WKSyncMsg> list) async {
|
||||
List<WKMsg> msgList = [];
|
||||
List<WKMsgExtra> msgExtraList = [];
|
||||
List<WKMsgReaction> msgReactionList = [];
|
||||
@ -214,15 +215,18 @@ class WKMessageManager {
|
||||
msgReactionList.addAll(wkMsg.reactionList!);
|
||||
}
|
||||
}
|
||||
bool isSuccess = true;
|
||||
if (msgExtraList.isNotEmpty) {
|
||||
MessageDB.shared.insertOrUpdateMsgExtras(msgExtraList);
|
||||
isSuccess = await MessageDB.shared.insertOrUpdateMsgExtras(msgExtraList);
|
||||
}
|
||||
if (msgList.isNotEmpty) {
|
||||
MessageDB.shared.insertMsgList(msgList);
|
||||
isSuccess = await MessageDB.shared.insertMsgList(msgList);
|
||||
}
|
||||
if (msgReactionList.isNotEmpty) {
|
||||
ReactionDB.shared.insertOrUpdateReactionList(msgReactionList);
|
||||
isSuccess =
|
||||
await ReactionDB.shared.insertOrUpdateReactionList(msgReactionList);
|
||||
}
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
WKMsgExtra wkSyncExtraMsg2WKMsgExtra(
|
||||
|
@ -15,7 +15,7 @@ description: wukong IM flutter sdk
|
||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
# In Windows, build-name is used as the major, minor, and patch parts
|
||||
# of the product and file versions while build-number is used as the build suffix.
|
||||
version: 1.3.0
|
||||
version: 1.3.1
|
||||
homepage: https://github.com/WuKongIM/WuKongIMFlutterSDK
|
||||
|
||||
environment:
|
||||
|
Loading…
x
Reference in New Issue
Block a user