|
|
|
@ -19,12 +19,9 @@ class HxDatabase {
|
|
|
|
|
if (key?.isNotEmpty ?? false) { |
|
|
|
|
databaseName = 'hx_$key.db'; |
|
|
|
|
} |
|
|
|
|
await openDatabase(databaseName, version: 1, |
|
|
|
|
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( |
|
|
|
|
'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`))'); |
|
|
|
|
await openDatabase(databaseName, version: 1, 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('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 { |
|
|
|
|
await database.execute('PRAGMA foreign_keys = ON'); |
|
|
|
|
debugPrint("database-version: ${await database.getVersion()}"); |
|
|
|
@ -111,19 +108,16 @@ class HxDatabase {
|
|
|
|
|
|
|
|
|
|
Future<Map<String, int>> messageUnreadCount(List<String> conversationIds) async { |
|
|
|
|
await _dbIsOpen(); |
|
|
|
|
String userStr = conversationIds.join(","); |
|
|
|
|
String userStr = conversationIds.join("','"); |
|
|
|
|
debugPrint("userStr: $userStr"); |
|
|
|
|
List<Message> messages = await db.query("Message", |
|
|
|
|
where: "`conversationId` IN (?) AND state = 0 AND isDelete = 0", |
|
|
|
|
whereArgs: [userStr], |
|
|
|
|
where: "conversationId IN ('$userStr') AND state = 0 AND isDelete = 0", |
|
|
|
|
whereArgs: [], |
|
|
|
|
).then((value) { |
|
|
|
|
return value.map((e) => Message.fromJson(e)).toList(); |
|
|
|
|
}, onError: (error) { |
|
|
|
|
debugPrint("Message-error: $error"); |
|
|
|
|
}); |
|
|
|
|
messages.forEach((element) { |
|
|
|
|
debugPrint("messageUnreadCount: ${element.toJson()}"); |
|
|
|
|
}); |
|
|
|
|
return (messages??[]).lGroupBy((p) => p.conversationId).mGroupCount; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|