Browse Source

message page

wr_202303
zsw 4 months ago
parent
commit
c0404b6599
  1. 2
      lib/im/SocketClient.dart
  2. 18
      lib/im/database/hx_database.dart

2
lib/im/SocketClient.dart

@ -16,7 +16,7 @@ import 'package:shared_preferences/shared_preferences.dart';
class SocketClient { class SocketClient {
//47.93.216.24:9090 线 192.168.10.129:9090 //47.93.216.24:9090 线 192.168.10.129:9090
final String ip = kDebugMode ? '192.168.10.129' : '47.93.216.24'; final String ip = !kDebugMode ? '192.168.10.129' : '47.93.216.24';
final num port = 9090; final num port = 9090;
Socket _socket; Socket _socket;
SharedPreferences _shared; SharedPreferences _shared;

18
lib/im/database/hx_database.dart

@ -19,12 +19,9 @@ class HxDatabase {
if (key?.isNotEmpty ?? false) { if (key?.isNotEmpty ?? false) {
databaseName = 'hx_$key.db'; databaseName = 'hx_$key.db';
} }
await openDatabase(databaseName, version: 1, await openDatabase(databaseName, version: 1, onCreate: (Database db, int version) async {
onCreate: (Database db, int version) async { db.execute('CREATE TABLE IF NOT EXISTS `Message` (`id` INTEGER, `conversationId` VARCHAR(40), `fromId` VARCHAR(20), `toId` VARCHAR(20), `replyId` VARCHAR(20), `content` TEXT, `attach` TEXT, `msgType` INTEGER, `time` VARCHAR(20), `state` INTEGER, `isDelete` INTEGER, PRIMARY KEY (`id`))');
db.execute( db.execute('CREATE TABLE IF NOT EXISTS `ImUser` (`id` INTEGER, `mid` VARCHAR(20), `nickname` VARCHAR(20), `avatar` VARCHAR(200), `phone` VARCHAR(200), `isDelete` INTEGER, `isTop` INTEGER, PRIMARY KEY (`id`))');
'CREATE TABLE IF NOT EXISTS `Message` (`id` INTEGER, `conversationId` VARCHAR(40), `fromId` VARCHAR(20), `toId` VARCHAR(20), `replyId` VARCHAR(20), `content` TEXT, `attach` TEXT, `msgType` INTEGER, `time` VARCHAR(20), `state` INTEGER, `isDelete` INTEGER, PRIMARY KEY (`id`))');
db.execute(
'CREATE TABLE IF NOT EXISTS `ImUser` (`id` INTEGER, `mid` VARCHAR(20), `nickname` VARCHAR(20), `avatar` VARCHAR(200), `phone` VARCHAR(200), `isDelete` INTEGER, `isTop` INTEGER, PRIMARY KEY (`id`))');
}, onConfigure: (database) async { }, onConfigure: (database) async {
await database.execute('PRAGMA foreign_keys = ON'); await database.execute('PRAGMA foreign_keys = ON');
debugPrint("database-version: ${await database.getVersion()}"); debugPrint("database-version: ${await database.getVersion()}");
@ -111,19 +108,16 @@ class HxDatabase {
Future<Map<String, int>> messageUnreadCount(List<String> conversationIds) async { Future<Map<String, int>> messageUnreadCount(List<String> conversationIds) async {
await _dbIsOpen(); await _dbIsOpen();
String userStr = conversationIds.join(","); String userStr = conversationIds.join("','");
debugPrint("userStr: $userStr"); debugPrint("userStr: $userStr");
List<Message> messages = await db.query("Message", List<Message> messages = await db.query("Message",
where: "`conversationId` IN (?) AND state = 0 AND isDelete = 0", where: "conversationId IN ('$userStr') AND state = 0 AND isDelete = 0",
whereArgs: [userStr], whereArgs: [],
).then((value) { ).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");
}); });
messages.forEach((element) {
debugPrint("messageUnreadCount: ${element.toJson()}");
});
return (messages??[]).lGroupBy((p) => p.conversationId).mGroupCount; return (messages??[]).lGroupBy((p) => p.conversationId).mGroupCount;
} }

Loading…
Cancel
Save