diff --git a/lib/im/SocketClient.dart b/lib/im/SocketClient.dart index 023313cf..696c4d8f 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 7590f47f..2d277a41 100644 --- a/lib/im/database/hx_database.dart +++ b/lib/im/database/hx_database.dart @@ -65,7 +65,6 @@ class HxDatabase { await _dbIsOpen(); String sql = 'SELECT * FROM (SELECT * FROM Message WHERE toId = ? OR fromId = ? ORDER BY time DESC) mm GROUP BY mm.toId,mm.fromId'; - debugPrint("66666666666$sql"); return db.rawQuery(sql, [userId, userId]).then((value) { return value.map((e) { debugPrint("Message: ${e}"); @@ -88,16 +87,13 @@ class HxDatabase { }); } - Future> messageUnreadCount( - List userIds, String selfUserId) async { + Future> messageUnreadCount(List userIds, String selfUserId) async { await _dbIsOpen(); - List messages = await db - .query("Message", - where: 'fromId IN (?) AND toId = ? AND state = 0 AND isDelete = 0', - whereArgs: [] - ..addAll(userIds) - ..add(selfUserId)) - .then((value) { + 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) { debugPrint("Message-error: $error"); diff --git a/lib/im/im_view/im_page.dart b/lib/im/im_view/im_page.dart index 4428f370..4cf6e560 100644 --- a/lib/im/im_view/im_page.dart +++ b/lib/im/im_view/im_page.dart @@ -144,6 +144,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