feat: мультиаккаунтинг — переключение долгим нажатием на «Настройки»

This commit is contained in:
klockky
2026-05-26 18:09:29 +03:00
parent 80706daf45
commit f781a5f3d0
4 changed files with 582 additions and 16 deletions
+21
View File
@@ -9,6 +9,7 @@ import '../../core/utils/logger.dart';
import 'chats.dart';
import 'contacts.dart';
import 'folders.dart';
import 'messages.dart';
String _normalizeAuthPhone(String phone) {
final digits = phone.replaceAll(RegExp(r'\D'), '');
@@ -925,14 +926,34 @@ class AccountModule {
if (profile == null) {
throw StateError('switchAccount: аккаунт $accountId не найден в базе');
}
final token = await TokenStorage.readToken(accountId);
if (token == null) {
throw StateError('switchAccount: нет токена для аккаунта $accountId');
}
try {
await _api.disconnect();
} catch (_) {}
await AppDatabase.setActiveAccount(accountId);
await TokenStorage.setActiveAccount(accountId);
ContactCache.clear();
TranscriptionCache.clear();
await ContactsModule.primeCacheFromDb(accountId);
try {
await _api.connect();
} catch (_) {}
logger.i('Активный аккаунт переключён на $accountId');
return profile;
}
Future<List<ProfileData>> listAccounts() async {
return AppDatabase.loadAllProfiles();
}
Future<void> removeAccount(int accountId) async {
await AppDatabase.deleteAccount(accountId);
await TokenStorage.deleteAccount(accountId);