Browse Source

Merge remote-tracking branch 'origin/wr_202303' into wr_202303

# Conflicts:
#	lib/im/database/hx_database.dart
wr_202303
wurong 4 months ago
parent
commit
8bb96c12b8
  1. 5
      lib/im/SocketClient.dart
  2. 16
      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());

16
lib/im/database/hx_database.dart

@ -65,7 +65,6 @@ class HxDatabase {
await _dbIsOpen(); await _dbIsOpen();
String sql = String sql =
'SELECT * FROM (SELECT * FROM Message WHERE toId = ? OR fromId = ? ORDER BY time DESC) mm GROUP BY mm.toId,mm.fromId'; '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 db.rawQuery(sql, [userId, userId]).then((value) {
return value.map((e) { return value.map((e) {
debugPrint("Message: ${e}"); debugPrint("Message: ${e}");
@ -88,16 +87,13 @@ class HxDatabase {
}); });
} }
Future<Map<String, int>> messageUnreadCount( Future<Map<String, int>> messageUnreadCount(List<String> userIds, String selfUserId) async {
List<String> userIds, String selfUserId) async {
await _dbIsOpen(); await _dbIsOpen();
List<Message> messages = await db String userStr = userIds.join(",");
.query("Message", debugPrint("userStr: $userStr");
where: 'fromId IN (?) AND toId = ? AND state = 0 AND isDelete = 0', List<Message> messages = await db.rawQuery(
whereArgs: [] "SELECT * FROM Message WHERE fromId IN ($userStr) AND toId = $selfUserId AND state = 0 AND isDelete = 0",
..addAll(userIds) ).then((value) {
..add(selfUserId))
.then((value) {
return value.map((e) => Message.fromJson(e)).toList(); return value.map((e) => Message.fromJson(e)).toList();
}, onError: (error) { }, onError: (error) {
debugPrint("Message-error: $error"); debugPrint("Message-error: $error");

1
lib/im/im_view/im_page.dart

@ -144,6 +144,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