update sync channel msgs

This commit is contained in:
SL 2023-08-19 21:10:18 +08:00
parent 6a64a7f145
commit a19656e45e
11 changed files with 44 additions and 33 deletions

View File

@ -4,3 +4,5 @@
* update connection
### 1.0.2
* Reconnect when handling connection errors
### 1.0.3
* update sync channel msgs

View File

@ -10,7 +10,7 @@
#### 安装
```
dependencies:
wukongimfluttersdk: ^1.0.2
wukongimfluttersdk: ^1.0.3
```
#### 引入
```dart

View File

@ -102,6 +102,8 @@ class ChatListDataState extends State<ChatList> {
Future.delayed(const Duration(milliseconds: 300), () {
_scrollController.jumpTo(_scrollController.position.maxScrollExtent);
});
}, () {
print('消息同步中');
});
}

View File

@ -79,7 +79,7 @@ class HttpUtils {
int pullMode,
Function(WKSyncChannelMsg) back) async {
final dio = Dio();
print('请求参数${UserInfo.uid},$channelID');
print('请求参数${startMsgSeq},$endMsgSeq');
final response = await dio.post('$apiURL/channel/messagesync', data: {
"login_uid": UserInfo.uid, // uid
"channel_id": channelID, // ID
@ -118,7 +118,6 @@ class HttpUtils {
msg.channelID = json['channel_id'];
// msg.payload = json['payload'];
String payload = json['payload'];
// print('消息发送着:${msg.from_uid},${msg.channel_id}');
try {
msg.payload = jsonDecode(utf8.decode(base64Decode(payload)));
// print('查询的消息${msg.payload}');

View File

@ -499,7 +499,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.2"
version: "1.0.3"
x25519:
dependency: transitive
description:

View File

@ -28,7 +28,7 @@ class WKDBConst {
msg.messageSeq = readInt(data, 'message_seq');
msg.clientSeq = readInt(data, 'client_seq');
msg.timestamp = readInt(data, 'timestamp');
msg.fromUID = readString(data, ' from_uid');
msg.fromUID = readString(data, 'from_uid');
msg.channelID = readString(data, 'channel_id');
msg.channelType = readInt(data, 'channel_type');
msg.contentType = readInt(data, 'type');

View File

@ -260,11 +260,11 @@ class MessaggeDB {
bool contain,
int pullMode,
int limit,
final Function(List<WKMsg>) iGetOrSyncHistoryMsgBack) async {
final Function(List<WKMsg>) iGetOrSyncHistoryMsgBack,
final Function() syncBack) async {
//
List<WKMsg> list = await getMessages(
channelId, channelType, oldestOrderSeq, contain, pullMode, limit);
//
List<WKMsg> tempList = [];
for (int i = 0, size = list.length; i < size; i++) {
@ -383,9 +383,9 @@ class MessaggeDB {
if (isSyncMsg &&
(startMsgSeq != endMsgSeq || (startMsgSeq == 0 && endMsgSeq == 0)) &&
requestCount < 5) {
// if (requestCount == 0) {
// iGetOrSyncHistoryMsgBack.onSyncing();
// }
if (requestCount == 0) {
syncBack();
}
//
requestCount++;
WKIM.shared.messageManager.setSyncChannelMsgListener(
@ -395,7 +395,7 @@ class MessaggeDB {
syncChannelMsg.messages != null &&
syncChannelMsg.messages!.isNotEmpty) {
getOrSyncHistoryMessages(channelId, channelType, oldestOrderSeq,
contain, pullMode, limit, iGetOrSyncHistoryMsgBack);
contain, pullMode, limit, iGetOrSyncHistoryMsgBack, syncBack);
} else {
requestCount = 0;
iGetOrSyncHistoryMsgBack(list);

View File

@ -44,6 +44,7 @@ class _WKSocket {
class WKConnectionManager {
bool isReconnection = false;
final int reconnMilliseconds = 1500;
Timer? heartTimer;
Timer? checkNetworkTimer;
final heartIntervalSecond = const Duration(seconds: 60);
@ -99,7 +100,7 @@ class WKConnectionManager {
}
_socketConnect(String addr) {
Logs.info("addr--->$addr");
Logs.info("连接地址--->$addr");
var addrs = addr.split(":");
var host = addrs[0];
var port = addrs[1];
@ -110,10 +111,8 @@ class WKConnectionManager {
_socket = _WKSocket.newSocket(socket);
_connectSuccess();
}).catchError((err) {
Logs.info("失败");
_connectFail(err);
}).onError((err, stackTrace) {
Logs.info("错误");
_connectFail(err);
});
} catch (e) {
@ -121,7 +120,7 @@ class WKConnectionManager {
}
}
// socket
// socket
_connectSuccess() {
//
_socket?.listen((Uint8List data) {
@ -129,7 +128,8 @@ class WKConnectionManager {
// _decodePacket(data);
}, () {
isReconnection = true;
Future.delayed(const Duration(milliseconds: 1500), () {
Logs.error('发送消息失败');
Future.delayed(Duration(milliseconds: reconnMilliseconds), () {
connect();
});
});
@ -138,7 +138,10 @@ class WKConnectionManager {
}
_connectFail(error) {
Logs.error(error);
Logs.error('连接失败:${error.toString()}');
Future.delayed(Duration(milliseconds: reconnMilliseconds), () {
connect();
});
}
testCutData(Uint8List data) {
@ -272,7 +275,6 @@ class WKConnectionManager {
}
_sendConnectPacket() {
Logs.info("发送连接包");
var connectPacket = ConnectPacket(
uid: WKIM.shared.options.uid!,
token: WKIM.shared.options.token!,
@ -393,24 +395,23 @@ class WKConnectionManager {
msg.messageContent = WKIM.shared.messageManager
.getMessageModel(msg.contentType, contentJson);
WKIM.shared.messageManager.parsingMsg(msg);
WKIM.shared.messageManager.saveMsg(msg);
if (msg.isDeleted == 0 &&
!msg.header.noPersist &&
msg.contentType != WkMessageContentType.insideMsg) {
List<WKMsg> list = [];
list.add(msg);
WKIM.shared.messageManager.pushNewMsg(list);
int row = await WKIM.shared.messageManager.saveMsg(msg);
msg.clientSeq = row;
WKUIConversationMsg? uiMsg =
await WKIM.shared.conversationManager.saveWithLiMMsg(msg);
if (uiMsg != null) {
Logs.info('刷新最近会话');
WKIM.shared.conversationManager.setRefreshMsg(uiMsg, true);
}
} else {
Logs.debug(
'消息不能存库:is_deleted=${msg.isDeleted},no_persist=${msg.header.noPersist},content_type:${msg.contentType}');
}
List<WKMsg> list = [];
list.add(msg);
WKIM.shared.messageManager.pushNewMsg(list);
}
int _isDeletedMsg(dynamic jsonObject) {

View File

@ -80,8 +80,8 @@ class WKMessageManager {
return MessaggeDB.shared.queryWithClientMsgNo(clientMsgNo);
}
saveMsg(WKMsg msg) {
MessaggeDB.shared.insert(msg);
Future<int> saveMsg(WKMsg msg) async {
return await MessaggeDB.shared.insert(msg);
}
String generateClientMsgNo() {
@ -181,7 +181,8 @@ class WKMessageManager {
int pullMode,
int limit,
int aroundMsgOrderSeq,
final Function(List<WKMsg>) iGetOrSyncHistoryMsgBack) async {
final Function(List<WKMsg>) iGetOrSyncHistoryMsgBack,
final Function() syncBack) async {
if (aroundMsgOrderSeq != 0) {
int maxMsgSeq = await getMaxMessageSeq(channelId, channelType);
int aroundMsgSeq = getOrNearbyMsgSeq(aroundMsgOrderSeq);
@ -222,8 +223,15 @@ class WKMessageManager {
contain = true;
}
}
MessaggeDB.shared.getOrSyncHistoryMessages(channelId, channelType,
oldestOrderSeq, contain, pullMode, limit, iGetOrSyncHistoryMsgBack);
MessaggeDB.shared.getOrSyncHistoryMessages(
channelId,
channelType,
oldestOrderSeq,
contain,
pullMode,
limit,
iGetOrSyncHistoryMsgBack,
syncBack);
}
int getOrNearbyMsgSeq(int orderSeq) {
@ -319,7 +327,7 @@ class WKMessageManager {
dynamic json = wkMsg.messageContent!.encodeJson();
json['type'] = wkMsg.contentType;
wkMsg.content = jsonEncode(json);
int row = await MessaggeDB.shared.insert(wkMsg);
int row = await saveMsg(wkMsg);
wkMsg.clientSeq = row;
WKIM.shared.messageManager.setOnMsgInserted(wkMsg);
if (wkMsg.messageContent is WKMediaMessageContent) {

View File

@ -80,7 +80,6 @@ class Proto {
}
Uint8List encodeConnect(ConnectPacket packet) {
Logs.info("连接包信息${packet.toString()}");
WriteData write = WriteData();
write.writeUint8(packet.version);
write.writeUint8(packet.deviceFlag);

View File

@ -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.0.2
version: 1.0.3
homepage: https://github.com/WuKongIM/WuKongIMFlutterSDK
environment: