ПИДОРАСЫ ЕБАНЫЕ Я ВАШ РОТ НАХУЙ СДЕЛАЮ УДАЛИТИ ГРУПА ПИДАРАСЫ КАКОГА ХУЯ ДЛЯ ИЗМЕНЕНЕЯ СПУФА НАДА ПЕРЕЗАХАДИТЬ ПИТАРАСЫ Я ВАШ РОТ НООБОРОТ
This commit is contained in:
@@ -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<void> 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<void> cacheChats(List<Map<String, dynamic>> chats) async {
|
||||
try {
|
||||
await _cacheService.set(_chatsKey, chats, ttl: _chatsTTL);
|
||||
@@ -39,7 +33,6 @@ class ChatCacheService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<List<Map<String, dynamic>>?> getCachedChats() async {
|
||||
try {
|
||||
final cached = await _cacheService.get<List<dynamic>>(
|
||||
@@ -55,7 +48,6 @@ class ChatCacheService {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Future<void> cacheContacts(List<Contact> contacts) async {
|
||||
try {
|
||||
final contactsData = contacts
|
||||
@@ -81,7 +73,6 @@ class ChatCacheService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<List<Contact>?> getCachedContacts() async {
|
||||
try {
|
||||
final cached = await _cacheService.get<List<dynamic>>(
|
||||
@@ -97,7 +88,6 @@ class ChatCacheService {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Future<void> cacheChatMessages(int chatId, List<Message> messages) async {
|
||||
try {
|
||||
final key = '$_chatMessagesKey$chatId';
|
||||
@@ -125,7 +115,6 @@ class ChatCacheService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<List<Message>?> getCachedChatMessages(int chatId) async {
|
||||
try {
|
||||
final key = '$_chatMessagesKey$chatId';
|
||||
@@ -142,17 +131,14 @@ class ChatCacheService {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Future<void> 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<void> updateMessageInCache(int chatId, Message updatedMessage) async {
|
||||
try {
|
||||
final cached = await getCachedChatMessages(chatId);
|
||||
@@ -180,7 +165,6 @@ class ChatCacheService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<void> removeMessageFromCache(int chatId, String messageId) async {
|
||||
try {
|
||||
final cached = await getCachedChatMessages(chatId);
|
||||
@@ -196,7 +180,6 @@ class ChatCacheService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<void> cacheChatInfo(int chatId, Map<String, dynamic> chatInfo) async {
|
||||
try {
|
||||
final key = 'chat_info_$chatId';
|
||||
@@ -206,7 +189,6 @@ class ChatCacheService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<Map<String, dynamic>?> getCachedChatInfo(int chatId) async {
|
||||
try {
|
||||
final key = 'chat_info_$chatId';
|
||||
@@ -217,7 +199,6 @@ class ChatCacheService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<void> cacheLastMessage(int chatId, Message? lastMessage) async {
|
||||
try {
|
||||
final key = 'last_message_$chatId';
|
||||
@@ -243,7 +224,6 @@ class ChatCacheService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<Message?> getCachedLastMessage(int chatId) async {
|
||||
try {
|
||||
final key = 'last_message_$chatId';
|
||||
@@ -262,7 +242,6 @@ class ChatCacheService {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Future<void> clearChatCache(int chatId) async {
|
||||
try {
|
||||
final keys = [
|
||||
@@ -281,22 +260,18 @@ class ChatCacheService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<void> clearAllChatCache() async {
|
||||
try {
|
||||
await _cacheService.remove(_chatsKey);
|
||||
await _cacheService.remove(_contactsKey);
|
||||
await _cacheService.remove(_messagesKey);
|
||||
|
||||
|
||||
|
||||
print('Весь кэш чатов очищен');
|
||||
} catch (e) {
|
||||
print('Ошибка очистки всего кэша чатов: $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<Map<String, dynamic>> getChatCacheStats() async {
|
||||
try {
|
||||
final cacheStats = await _cacheService.getCacheStats();
|
||||
@@ -314,7 +289,6 @@ class ChatCacheService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<bool> isCacheValid(String cacheType) async {
|
||||
try {
|
||||
switch (cacheType) {
|
||||
|
||||
Reference in New Issue
Block a user