Browse Source

socketclient heartbeat

wr_202303
zsw 4 months ago
parent
commit
19b502e7eb
  1. 5
      lib/im/SocketClient.dart
  2. 8
      lib/im/database/hx_database.dart
  3. 1
      lib/im/im_view/im_page.dart

5
lib/im/SocketClient.dart

@ -55,8 +55,9 @@ class SocketClient {
heartbeat() { heartbeat() {
Timer.periodic(const Duration(milliseconds: 30000), (timer) { Timer.periodic(const Duration(milliseconds: 30000), (timer) {
debugPrint("heartbeat: ${DateTime.now().millisecondsSinceEpoch}"); int milliseTime = DateTime.now().millisecondsSinceEpoch;
Uint8List data = utf8.encode(jsonEncode({"heartbeat": DateTime.now().millisecondsSinceEpoch})); debugPrint("heartbeat: ${milliseTime}");
Uint8List data = utf8.encode(jsonEncode({"heartbeat": milliseTime}));
MsgData msgData = MsgData(from: userId, type: MsgType.TEXT, data: data); MsgData msgData = MsgData(from: userId, type: MsgType.TEXT, data: data);
final proto2 = Proto(3, 1, msgData.writeToBuffer()); final proto2 = Proto(3, 1, msgData.writeToBuffer());
_socket.add(proto2.toBytes()); _socket.add(proto2.toBytes());

8
lib/im/database/hx_database.dart

@ -89,10 +89,10 @@ class HxDatabase {
if (db == null || !db.isOpen) { if (db == null || !db.isOpen) {
return Future.value({}); return Future.value({});
} }
List<Message> messages = await db.query( String userStr = userIds.join(",");
"Message", debugPrint("userStr: $userStr");
where: 'fromId IN (?) AND toId = ? AND state = 0 AND isDelete = 0', List<Message> messages = await db.rawQuery(
whereArgs: []..addAll(userIds)..add(selfUserId) "SELECT * FROM Message WHERE fromId IN ($userStr) AND toId = $selfUserId AND state = 0 AND isDelete = 0",
).then((value) { ).then((value) {
return value.map((e) => Message.fromJson(e)).toList(); return value.map((e) => Message.fromJson(e)).toList();
}, onError: (error) { }, onError: (error) {

1
lib/im/im_view/im_page.dart

@ -145,6 +145,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
/// update conversation unreadcount /// update conversation unreadcount
queryUnreadCount(userIds, userId) async { queryUnreadCount(userIds, userId) async {
unreadCountMap = await hxDatabase.messageUnreadCount(userIds, userId); unreadCountMap = await hxDatabase.messageUnreadCount(userIds, userId);
debugPrint("unreadCount: $unreadCountMap");
} }
/// update imuser info by mids /// update imuser info by mids

Loading…
Cancel
Save