feat: история изменения сообщений

This commit is contained in:
Jganenokk
2026-06-29 15:05:22 +07:00
parent 0abbc2b59d
commit cd1ebaee24
6 changed files with 584 additions and 11 deletions
+20 -1
View File
@@ -190,7 +190,7 @@ class AppDatabase {
await _migrateLegacyDb(target);
return openDatabase(
target,
version: 14,
version: 15,
onOpen: (db) => db.execute('PRAGMA foreign_keys = ON'),
onCreate: (db, _) => _createTables(db),
onUpgrade: (db, oldVersion, newVersion) async {
@@ -244,6 +244,9 @@ class AppDatabase {
db, 'chats_cache', 'in_list', 'INTEGER NOT NULL DEFAULT 1',
);
}
if (oldVersion < 15) {
await _addColumnIfMissing(db, 'messages', 'edit_history', 'TEXT');
}
},
);
}
@@ -359,6 +362,7 @@ class AppDatabase {
status TEXT,
payload TEXT,
deleted INTEGER NOT NULL DEFAULT 0,
edit_history TEXT,
PRIMARY KEY (id, account_id),
FOREIGN KEY (chat_id, account_id) REFERENCES chats_cache (id, account_id) ON DELETE CASCADE
)
@@ -780,6 +784,21 @@ class AppDatabase {
);
}
static Future<List<Map<String, dynamic>>> loadMessagesByIds(
int accountId,
int chatId,
List<String> messageIds,
) async {
if (messageIds.isEmpty) return const [];
final db = await _instance;
final placeholders = List.filled(messageIds.length, '?').join(',');
return db.query(
'messages',
where: 'account_id = ? AND chat_id = ? AND id IN ($placeholders)',
whereArgs: [accountId, chatId, ...messageIds],
);
}
static Future<Map<String, dynamic>?> loadMessage(
int accountId,
int chatId,