fix: большой фикс недочетов и фикс пары язв

This commit is contained in:
Jganenok
2026-06-09 01:00:04 +07:00
parent 73ad6dd1e6
commit 580e30897b
32 changed files with 590 additions and 244 deletions
+17 -1
View File
@@ -159,7 +159,7 @@ class AppDatabase {
final dbPath = await getDatabasesPath();
return openDatabase(
join(dbPath, 'komet.db'),
version: 10,
version: 11,
onOpen: (db) => db.execute('PRAGMA foreign_keys = ON'),
onCreate: (db, _) => _createTables(db),
onUpgrade: (db, oldVersion, newVersion) async {
@@ -209,6 +209,9 @@ class AppDatabase {
'ALTER TABLE chats_cache ADD COLUMN admins TEXT',
);
}
if (oldVersion < 11) {
await _createIndexes(db);
}
},
);
}
@@ -234,6 +237,19 @@ class AppDatabase {
await db.execute(_chatsCacheSchema);
await db.execute(_contactsSchema);
await db.execute(_messagesSchema);
await _createIndexes(db);
}
static Future<void> _createIndexes(Database db) async {
await db.execute(
'CREATE INDEX IF NOT EXISTS idx_messages_chat ON messages(account_id, chat_id, time DESC)',
);
await db.execute(
'CREATE INDEX IF NOT EXISTS idx_chats_account ON chats_cache(account_id, last_event_time DESC)',
);
await db.execute(
'CREATE INDEX IF NOT EXISTS idx_contacts_account ON contacts(account_id)',
);
}
static const _contactsSchema = '''
+32 -4
View File
@@ -1,22 +1,50 @@
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:shared_preferences/shared_preferences.dart';
class TokenStorage {
static const _tokenPrefix = 'auth_token_';
static const _activeAccountKey = 'active_account_id';
static const _secure = FlutterSecureStorage(
aOptions: AndroidOptions(encryptedSharedPreferences: true),
);
static Future<void> writeSecure(String key, String value) async {
await _secure.write(key: key, value: value);
}
static Future<String?> readSecure(String key) async {
return _secure.read(key: key);
}
static Future<void> deleteSecure(String key) async {
await _secure.delete(key: key);
}
static Future<void> saveToken(String token, int accountId) async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString('$_tokenPrefix$accountId', token);
await _secure.write(key: '$_tokenPrefix$accountId', value: token);
}
static Future<String?> readToken(int accountId) async {
final key = '$_tokenPrefix$accountId';
final secured = await _secure.read(key: key);
if (secured != null) return secured;
final prefs = await SharedPreferences.getInstance();
return prefs.getString('$_tokenPrefix$accountId');
final legacy = prefs.getString(key);
if (legacy != null) {
await _secure.write(key: key, value: legacy);
await prefs.remove(key);
return legacy;
}
return null;
}
static Future<void> deleteToken(int accountId) async {
final key = '$_tokenPrefix$accountId';
await _secure.delete(key: key);
final prefs = await SharedPreferences.getInstance();
await prefs.remove('$_tokenPrefix$accountId');
await prefs.remove(key);
}
static Future<void> setActiveAccount(int accountId) async {