From 19b502e7eb8faa6c0f0aa680c8650379104ebf98 Mon Sep 17 00:00:00 2001 From: zsw Date: Fri, 20 Sep 2024 16:35:23 +0800 Subject: [PATCH] socketclient heartbeat --- lib/im/SocketClient.dart | 5 +++-- lib/im/database/hx_database.dart | 8 ++++---- lib/im/im_view/im_page.dart | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/im/SocketClient.dart b/lib/im/SocketClient.dart index 4ec2a8e0..52dec77b 100644 --- a/lib/im/SocketClient.dart +++ b/lib/im/SocketClient.dart @@ -55,8 +55,9 @@ class SocketClient { heartbeat() { Timer.periodic(const Duration(milliseconds: 30000), (timer) { - debugPrint("heartbeat: ${DateTime.now().millisecondsSinceEpoch}"); - Uint8List data = utf8.encode(jsonEncode({"heartbeat": DateTime.now().millisecondsSinceEpoch})); + int milliseTime = DateTime.now().millisecondsSinceEpoch; + debugPrint("heartbeat: ${milliseTime}"); + Uint8List data = utf8.encode(jsonEncode({"heartbeat": milliseTime})); MsgData msgData = MsgData(from: userId, type: MsgType.TEXT, data: data); final proto2 = Proto(3, 1, msgData.writeToBuffer()); _socket.add(proto2.toBytes()); diff --git a/lib/im/database/hx_database.dart b/lib/im/database/hx_database.dart index 2af0d7a8..5637d8a1 100644 --- a/lib/im/database/hx_database.dart +++ b/lib/im/database/hx_database.dart @@ -89,10 +89,10 @@ class HxDatabase { if (db == null || !db.isOpen) { return Future.value({}); } - List messages = await db.query( - "Message", - where: 'fromId IN (?) AND toId = ? AND state = 0 AND isDelete = 0', - whereArgs: []..addAll(userIds)..add(selfUserId) + String userStr = userIds.join(","); + debugPrint("userStr: $userStr"); + List messages = await db.rawQuery( + "SELECT * FROM Message WHERE fromId IN ($userStr) AND toId = $selfUserId AND state = 0 AND isDelete = 0", ).then((value) { return value.map((e) => Message.fromJson(e)).toList(); }, onError: (error) { diff --git a/lib/im/im_view/im_page.dart b/lib/im/im_view/im_page.dart index 663179b7..8f2cdee6 100644 --- a/lib/im/im_view/im_page.dart +++ b/lib/im/im_view/im_page.dart @@ -145,6 +145,7 @@ class _IMPage extends State implements OnChatMessage { /// update conversation unreadcount queryUnreadCount(userIds, userId) async { unreadCountMap = await hxDatabase.messageUnreadCount(userIds, userId); + debugPrint("unreadCount: $unreadCountMap"); } /// update imuser info by mids