вроде контакты починил
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../../core/config/debug_test.dart';
|
||||
import '../../core/protocol/opcode_map.dart';
|
||||
import '../../core/storage/app_database.dart';
|
||||
import '../../core/utils/logger.dart';
|
||||
import '../api.dart';
|
||||
import 'messages.dart';
|
||||
|
||||
@@ -174,7 +176,11 @@ class ContactsModule {
|
||||
|
||||
if (rows.isNotEmpty) {
|
||||
await AppDatabase.saveContacts(rows);
|
||||
revision.value++;
|
||||
}
|
||||
logger.i(
|
||||
'Контакты: получено ${contacts.length}, сохранено ${rows.length} (акк $accountId)',
|
||||
);
|
||||
}
|
||||
|
||||
static void _primeContactCache(Map<dynamic, dynamic> contact) {
|
||||
@@ -228,6 +234,41 @@ class ContactsModule {
|
||||
return rows.map(CachedContact.fromDbRow).toList();
|
||||
}
|
||||
|
||||
static const List<String> _debugFirstNames = [
|
||||
'Алиса', 'Борис', 'Вера', 'Глеб', 'Дарья', 'Егор', 'Жанна', 'Захар',
|
||||
'Ирина', 'Кирилл', 'Лия', 'Максим', 'Нина', 'Олег', 'Полина', 'Роман',
|
||||
'София', 'Тимур', 'Ульяна', 'Фёдор', 'Ханна', 'Цветана', 'Чеслав', 'Шура',
|
||||
];
|
||||
|
||||
static const List<String> _debugLastNames = [
|
||||
'Иванов', 'Петров', 'Сидоров', 'Кузнецов', 'Смирнов', 'Попов', 'Волков',
|
||||
'Соколов', 'Морозов', 'Новиков', 'Фёдоров', 'Козлов',
|
||||
];
|
||||
|
||||
static List<CachedContact> debugContacts() {
|
||||
final count = DebugTest.contactCount;
|
||||
final out = <CachedContact>[];
|
||||
for (var i = 0; i < count; i++) {
|
||||
final first = _debugFirstNames[i % _debugFirstNames.length];
|
||||
final last =
|
||||
_debugLastNames[(i ~/ _debugFirstNames.length) %
|
||||
_debugLastNames.length];
|
||||
out.add(
|
||||
CachedContact(
|
||||
id: 900000000 + i,
|
||||
accountId: DebugTest.debugAccountId,
|
||||
firstName: '$first ${i + 1}',
|
||||
lastName: last,
|
||||
phone: 79000000000 + i,
|
||||
baseUrl: 'https://i.pravatar.cc/150?u=komet_debug_$i',
|
||||
updateTime: 1,
|
||||
options: i % 6 == 0 ? const {'OFFICIAL'} : const {},
|
||||
),
|
||||
);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/// Прогревает in-memory ContactCache из локальных контактов.
|
||||
/// Нужно вызывать на cold start: иначе кэш пуст до следующего логина.
|
||||
static Future<void> primeCacheFromDb(int accountId) async {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
class DebugTest {
|
||||
static bool enabled = false;
|
||||
static int contactCount = 0;
|
||||
|
||||
static const int debugAccountId = -424242;
|
||||
|
||||
static const bool _envEnabled = bool.fromEnvironment('DEBUG_TEST');
|
||||
static const int _envContacts = int.fromEnvironment(
|
||||
'DEBUG_CONTACTS',
|
||||
defaultValue: -1,
|
||||
);
|
||||
|
||||
static const String _flag = '--debug-test';
|
||||
static const String _contactsFlag = '--contacts';
|
||||
|
||||
static void parse(List<String> args) {
|
||||
if (_envEnabled) enabled = true;
|
||||
if (_envContacts >= 0) {
|
||||
enabled = true;
|
||||
contactCount = _envContacts;
|
||||
}
|
||||
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
final arg = args[i];
|
||||
if (arg == _flag) {
|
||||
enabled = true;
|
||||
} else if (arg.startsWith('$_contactsFlag=')) {
|
||||
enabled = true;
|
||||
contactCount =
|
||||
int.tryParse(arg.substring(_contactsFlag.length + 1)) ??
|
||||
contactCount;
|
||||
} else if (arg == _contactsFlag && i + 1 < args.length) {
|
||||
enabled = true;
|
||||
contactCount = int.tryParse(args[i + 1]) ?? contactCount;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import '../../../core/config/debug_test.dart';
|
||||
import '../../../core/protocol/opcode_map.dart';
|
||||
import '../../../core/protocol/packet.dart';
|
||||
import '../../../core/storage/app_database.dart';
|
||||
@@ -102,6 +103,18 @@ class _ContactsTabState extends State<ContactsTab> {
|
||||
}
|
||||
|
||||
Future<void> _loadContacts() async {
|
||||
if (DebugTest.enabled) {
|
||||
final debug = ContactsModule.debugContacts()
|
||||
..sort((a, b) => a.firstName.compareTo(b.firstName));
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_contacts = debug;
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final p = await AppDatabase.loadActiveProfile();
|
||||
if (p == null) {
|
||||
if (mounted) setState(() => _isLoading = false);
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../core/config/debug_test.dart';
|
||||
import '../../core/utils/update_checker.dart';
|
||||
import '../screens/chats/chat_list_screen.dart';
|
||||
import '../screens/chats/chat_screen.dart';
|
||||
@@ -52,6 +53,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
}
|
||||
|
||||
Future<void> _maybeCheckUpdate() async {
|
||||
if (DebugTest.enabled) return;
|
||||
final update = await UpdateChecker.check();
|
||||
if (update == null || !mounted) return;
|
||||
await showUpdateDialog(context, update);
|
||||
|
||||
+14
-1
@@ -22,6 +22,7 @@ import 'core/config/app_amoled.dart';
|
||||
import 'core/config/app_show_extra_info.dart';
|
||||
import 'core/config/app_bubble_behavior.dart';
|
||||
import 'core/config/komet_settings.dart';
|
||||
import 'core/config/debug_test.dart';
|
||||
import 'core/config/app_bubble_shape.dart';
|
||||
import 'core/config/app_cache_extent.dart';
|
||||
import 'core/config/app_fonts.dart';
|
||||
@@ -143,8 +144,9 @@ void _installLogCapture() {
|
||||
};
|
||||
}
|
||||
|
||||
void main() async {
|
||||
void main(List<String> args) async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
DebugTest.parse(args);
|
||||
_installLogCapture();
|
||||
VideoPlayerMediaKit.ensureInitialized(
|
||||
windows: true,
|
||||
@@ -930,6 +932,17 @@ class _StartupScreenState extends State<_StartupScreen> {
|
||||
}
|
||||
|
||||
Future<void> _tryAutoLogin() async {
|
||||
if (DebugTest.enabled) {
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
if (!mounted) return;
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const AdaptiveShell()),
|
||||
);
|
||||
KometApp.stateOf(context)?.markShellReady();
|
||||
return;
|
||||
}
|
||||
|
||||
unawaited(api.connect());
|
||||
|
||||
int? accountId = await TokenStorage.getActiveAccountId();
|
||||
|
||||
Reference in New Issue
Block a user