diff --git a/lib/api/api_service_chats.dart b/lib/api/api_service_chats.dart index a1fcee5..a5a68b4 100644 --- a/lib/api/api_service_chats.dart +++ b/lib/api/api_service_chats.dart @@ -170,15 +170,14 @@ extension ApiServiceChats on ApiService { }; _lastChatsPayload = result; - final contacts = - contactListJson.map((json) => Contact.fromJson(json)).toList(); + final contacts = contactListJson + .map((json) => Contact.fromJson(json)) + .toList(); updateContactCache(contacts); _lastChatsAt = DateTime.now(); _preloadContactAvatars(contacts); unawaited( - _chatCacheService.cacheChats( - chatListJson.cast>(), - ), + _chatCacheService.cacheChats(chatListJson.cast>()), ); unawaited(_chatCacheService.cacheContacts(contacts)); return result; @@ -204,9 +203,7 @@ extension ApiServiceChats on ApiService { } } - if (!force && - !_chatsFetchedInThisSession && - _lastChatsPayload == null) { + if (!force && !_chatsFetchedInThisSession && _lastChatsPayload == null) { final cachedChats = await _chatCacheService.getCachedChats(); final cachedContacts = await _chatCacheService.getCachedContacts(); if (cachedChats != null && @@ -393,15 +390,14 @@ extension ApiServiceChats on ApiService { }; _lastChatsPayload = result; - final contacts = - contactListJson.map((json) => Contact.fromJson(json)).toList(); + final contacts = contactListJson + .map((json) => Contact.fromJson(json)) + .toList(); updateContactCache(contacts); _lastChatsAt = DateTime.now(); _preloadContactAvatars(contacts); unawaited( - _chatCacheService.cacheChats( - chatListJson.cast>(), - ), + _chatCacheService.cacheChats(chatListJson.cast>()), ); unawaited(_chatCacheService.cacheContacts(contacts)); _chatsFetchedInThisSession = true; @@ -461,10 +457,13 @@ extension ApiServiceChats on ApiService { } if (!force) { - final cachedMessages = - await _chatCacheService.getCachedChatMessages(chatId); + final cachedMessages = await _chatCacheService.getCachedChatMessages( + chatId, + ); if (cachedMessages != null && cachedMessages.isNotEmpty) { - print("История сообщений для чата $chatId загружена из ChatCacheService."); + print( + "История сообщений для чата $chatId загружена из ChatCacheService.", + ); _messageCache[chatId] = cachedMessages; return cachedMessages; } @@ -670,8 +669,7 @@ extension ApiServiceChats on ApiService { final prefs = await SharedPreferences.getInstance(); final totalTraffic = - prefs.getDouble('network_total_traffic') ?? - (150.0 * 1024 * 1024); + prefs.getDouble('network_total_traffic') ?? (150.0 * 1024 * 1024); final messagesTraffic = prefs.getDouble('network_messages_traffic') ?? (totalTraffic * 0.15); final mediaTraffic = @@ -679,8 +677,7 @@ extension ApiServiceChats on ApiService { final syncTraffic = prefs.getDouble('network_sync_traffic') ?? (totalTraffic * 0.1); - final currentSpeed = - _isSessionOnline ? 512.0 * 1024 : 0.0; + final currentSpeed = _isSessionOnline ? 512.0 * 1024 : 0.0; final ping = 25; @@ -1015,4 +1012,3 @@ extension ApiServiceChats on ApiService { } } } - diff --git a/lib/api/api_service_contacts.dart b/lib/api/api_service_contacts.dart index 3f12d93..a98af52 100644 --- a/lib/api/api_service_contacts.dart +++ b/lib/api/api_service_contacts.dart @@ -313,4 +313,3 @@ extension ApiServiceContacts on ApiService { } } } - diff --git a/lib/models/message.dart b/lib/models/message.dart index 53e2f0e..07be68d 100644 --- a/lib/models/message.dart +++ b/lib/models/message.dart @@ -24,19 +24,13 @@ class Message { }); factory Message.fromJson(Map json) { - - - - int senderId; if (json['sender'] is int) { senderId = json['sender']; } else { - senderId = 0; } - int time; if (json['time'] is int) { time = json['time']; @@ -45,7 +39,6 @@ class Message { } return Message( - id: json['id']?.toString() ?? 'local_${DateTime.now().millisecondsSinceEpoch}', @@ -96,11 +89,6 @@ class Message { bool get isReply => link != null && link!['type'] == 'REPLY'; bool get isForwarded => link != null && link!['type'] == 'FORWARD'; - - - - - bool canEdit(int currentUserId) { if (isDeleted) return false; if (senderId != currentUserId) return false; @@ -108,7 +96,6 @@ class Message { return false; // Нельзя редактировать сообщения с вложениями } - final now = DateTime.now().millisecondsSinceEpoch; final messageTime = time; final hoursSinceCreation = (now - messageTime) / (1000 * 60 * 60); diff --git a/lib/screens/settings/session_spoofing_screen.dart b/lib/screens/settings/session_spoofing_screen.dart index 55e3849..dee313c 100644 --- a/lib/screens/settings/session_spoofing_screen.dart +++ b/lib/screens/settings/session_spoofing_screen.dart @@ -9,12 +9,9 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:gwid/api/api_service.dart'; import 'package:uuid/uuid.dart'; import 'package:gwid/device_presets.dart'; -import 'package:gwid/phone_entry_screen.dart'; - enum SpoofingMethod { partial, full } - enum PresetCategory { web, device } class SessionSpoofingScreen extends StatefulWidget { @@ -48,7 +45,6 @@ class _SessionSpoofingScreenState extends State { _loadInitialData(); } - Future _loadInitialData() async { setState(() => _isLoading = true); final prefs = await SharedPreferences.getInstance(); @@ -81,7 +77,6 @@ class _SessionSpoofingScreenState extends State { setState(() => _isLoading = false); } - Future _loadDeviceData() async { setState(() => _isLoading = true); @@ -129,7 +124,6 @@ class _SessionSpoofingScreenState extends State { }); } - Future _applyGeneratedData() async { final List filteredPresets; if (_selectedCategory == PresetCategory.web) { @@ -157,7 +151,6 @@ class _SessionSpoofingScreenState extends State { await _applyPreset(preset); } - Future _applyPreset(DevicePreset preset) async { setState(() { _userAgentController.text = preset.userAgent; @@ -195,13 +188,11 @@ class _SessionSpoofingScreenState extends State { } } - Future _saveSpoofingSettings() async { if (!mounted) return; final prefs = await SharedPreferences.getInstance(); - final oldValues = { 'user_agent': prefs.getString('spoof_useragent') ?? '', 'device_name': prefs.getString('spoof_devicename') ?? '', @@ -227,7 +218,6 @@ class _SessionSpoofingScreenState extends State { final oldAppVersion = prefs.getString('spoof_appversion') ?? '25.10.10'; final newAppVersion = _appVersionController.text; - bool otherDataChanged = false; for (final key in oldValues.keys) { if (oldValues[key] != newValues[key]) { @@ -238,43 +228,33 @@ class _SessionSpoofingScreenState extends State { final appVersionChanged = oldAppVersion != newAppVersion; - - - if (appVersionChanged && !otherDataChanged) { - await _saveAllData(prefs); if (mounted) { ScaffoldMessenger.of(context).showSnackBar( const SnackBar( - content: Text( - 'Настройки применятся при следующем входе в приложение.', - ), + content: Text('Перезайди!'), duration: Duration(seconds: 3), ), ); Navigator.of(context).pop(); } - } - - else { + } else { final confirmed = await showDialog( context: context, builder: (context) => AlertDialog( title: const Text('Применить настройки?'), - content: const Text( - 'Для применения настроек потребуется перезайти в аккаунт. Вы уверены?', - ), + content: const Text('Нужно перезайти в приложение, ок?'), actions: [ TextButton( onPressed: () => Navigator.of(context).pop(false), - child: const Text('Отмена'), + child: const Text('Не'), ), FilledButton( onPressed: () => Navigator.of(context).pop(true), - child: const Text('Применить'), + child: const Text('Ок!'), ), ], ), @@ -285,17 +265,23 @@ class _SessionSpoofingScreenState extends State { await _saveAllData(prefs); try { + await ApiService.instance.performFullReconnection(); + if (mounted) { - Navigator.of(context).pushAndRemoveUntil( - MaterialPageRoute(builder: (context) => const PhoneEntryScreen()), - (route) => false, + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('Настройки применены. Перезайдите в приложение.'), + backgroundColor: Colors.green, + ), ); + + Navigator.of(context).pop(); } } catch (e) { if (mounted) { ScaffoldMessenger.of(context).showSnackBar( SnackBar( - content: Text('Ошибка при выходе: $e'), + content: Text('Ошибка при применении настроек: $e'), backgroundColor: Theme.of(context).colorScheme.error, ), ); @@ -304,7 +290,6 @@ class _SessionSpoofingScreenState extends State { } } - Future _saveAllData(SharedPreferences prefs) async { await prefs.setBool('spoofing_enabled', true); await prefs.setString('spoof_useragent', _userAgentController.text); @@ -376,7 +361,6 @@ class _SessionSpoofingScreenState extends State { body: _isLoading ? const Center(child: CircularProgressIndicator()) : SingleChildScrollView( - padding: const EdgeInsets.fromLTRB(16, 8, 16, 120), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, @@ -651,10 +635,8 @@ class _SessionSpoofingScreenState extends State { 'Версия приложения', Icons.info_outline_rounded, ).copyWith( - suffixIcon: _isCheckingVersion ? const Padding( - padding: EdgeInsets.all(12.0), child: SizedBox( height: 24, @@ -665,7 +647,6 @@ class _SessionSpoofingScreenState extends State { ), ) : IconButton( - icon: const Icon(Icons.cloud_sync_outlined), tooltip: 'Проверить последнюю версию', onPressed: diff --git a/lib/services/chat_cache_service.dart b/lib/services/chat_cache_service.dart index 1705764..6d4bcb1 100644 --- a/lib/services/chat_cache_service.dart +++ b/lib/services/chat_cache_service.dart @@ -1,5 +1,3 @@ - - import 'dart:async'; import 'package:gwid/models/contact.dart'; import 'package:gwid/models/message.dart'; @@ -12,24 +10,20 @@ class ChatCacheService { final CacheService _cacheService = CacheService(); - Future initialize() async { await _cacheService.initialize(); print('ChatCacheService инициализирован'); } - static const String _chatsKey = 'cached_chats'; static const String _contactsKey = 'cached_contacts'; static const String _messagesKey = 'cached_messages'; static const String _chatMessagesKey = 'cached_chat_messages'; - static const Duration _chatsTTL = Duration(hours: 1); static const Duration _contactsTTL = Duration(hours: 6); static const Duration _messagesTTL = Duration(hours: 2); - Future cacheChats(List> chats) async { try { await _cacheService.set(_chatsKey, chats, ttl: _chatsTTL); @@ -39,7 +33,6 @@ class ChatCacheService { } } - Future>?> getCachedChats() async { try { final cached = await _cacheService.get>( @@ -55,7 +48,6 @@ class ChatCacheService { return null; } - Future cacheContacts(List contacts) async { try { final contactsData = contacts @@ -81,7 +73,6 @@ class ChatCacheService { } } - Future?> getCachedContacts() async { try { final cached = await _cacheService.get>( @@ -97,7 +88,6 @@ class ChatCacheService { return null; } - Future cacheChatMessages(int chatId, List messages) async { try { final key = '$_chatMessagesKey$chatId'; @@ -125,7 +115,6 @@ class ChatCacheService { } } - Future?> getCachedChatMessages(int chatId) async { try { final key = '$_chatMessagesKey$chatId'; @@ -142,17 +131,14 @@ class ChatCacheService { return null; } - Future addMessageToCache(int chatId, Message message) async { try { final cached = await getCachedChatMessages(chatId); if (cached != null) { - final updatedMessages = [message, ...cached]; await cacheChatMessages(chatId, updatedMessages); } else { - await cacheChatMessages(chatId, [message]); } } catch (e) { @@ -160,7 +146,6 @@ class ChatCacheService { } } - Future updateMessageInCache(int chatId, Message updatedMessage) async { try { final cached = await getCachedChatMessages(chatId); @@ -180,7 +165,6 @@ class ChatCacheService { } } - Future removeMessageFromCache(int chatId, String messageId) async { try { final cached = await getCachedChatMessages(chatId); @@ -196,7 +180,6 @@ class ChatCacheService { } } - Future cacheChatInfo(int chatId, Map chatInfo) async { try { final key = 'chat_info_$chatId'; @@ -206,7 +189,6 @@ class ChatCacheService { } } - Future?> getCachedChatInfo(int chatId) async { try { final key = 'chat_info_$chatId'; @@ -217,7 +199,6 @@ class ChatCacheService { } } - Future cacheLastMessage(int chatId, Message? lastMessage) async { try { final key = 'last_message_$chatId'; @@ -243,7 +224,6 @@ class ChatCacheService { } } - Future getCachedLastMessage(int chatId) async { try { final key = 'last_message_$chatId'; @@ -262,7 +242,6 @@ class ChatCacheService { return null; } - Future clearChatCache(int chatId) async { try { final keys = [ @@ -281,22 +260,18 @@ class ChatCacheService { } } - Future clearAllChatCache() async { try { await _cacheService.remove(_chatsKey); await _cacheService.remove(_contactsKey); await _cacheService.remove(_messagesKey); - - print('Весь кэш чатов очищен'); } catch (e) { print('Ошибка очистки всего кэша чатов: $e'); } } - Future> getChatCacheStats() async { try { final cacheStats = await _cacheService.getCacheStats(); @@ -314,7 +289,6 @@ class ChatCacheService { } } - Future isCacheValid(String cacheType) async { try { switch (cacheType) { diff --git a/pubspec.lock b/pubspec.lock index f5b7c08..3b073f6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -809,10 +809,10 @@ packages: dependency: transitive description: name: meta - sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" + sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c url: "https://pub.dev" source: hosted - version: "1.17.0" + version: "1.16.0" mime: dependency: transitive description: @@ -1318,10 +1318,10 @@ packages: dependency: transitive description: name: test_api - sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55 + sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00" url: "https://pub.dev" source: hosted - version: "0.7.7" + version: "0.7.6" timezone: dependency: "direct main" description: