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() {
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());

8
lib/im/database/hx_database.dart

@ -89,10 +89,10 @@ class HxDatabase {
if (db == null || !db.isOpen) {
return Future.value({});
}
List<Message> 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<Message> 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) {

1
lib/im/im_view/im_page.dart

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

Loading…
Cancel
Save