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