Повторный вход в аккаунт, очистка кэша

This commit is contained in:
Халимов Рустам
2026-05-15 00:10:34 +03:00
parent 0b013def2e
commit 40589dbb75
21 changed files with 1732 additions and 309 deletions
@@ -21,6 +21,12 @@ class ChatRepositoryImpl implements ChatRepository {
@override
Stream<Message> get messageStream => signalRService.messages;
@override
Stream<Map<String, dynamic>> get typingStream => signalRService.typingUpdates;
@override
Future<void> sendTypingStatus(String chatId, bool isTyping) => signalRService.sendTypingStatus(chatId, isTyping);
@override
Future<void> initSignalR() => signalRService.init();
@@ -29,6 +35,8 @@ class ChatRepositoryImpl implements ChatRepository {
@override
Future<Result<List<Chat>>> getChats({String? currentUserId}) async {
// ignore: avoid_print
print('[DEBUG] ChatRepository.getChats for user: $currentUserId');
// 1. Return cached chats immediately if available
final cachedResult = await localDataSource.getCachedChats();
@@ -36,10 +44,14 @@ class ChatRepositoryImpl implements ChatRepository {
final remoteResult = await remoteDataSource.getChats(currentUserId: currentUserId);
if (remoteResult.isSuccess) {
final chats = remoteResult.data!;
// ignore: avoid_print
print('[DEBUG] Remote getChats success: ${chats.length} chats');
await localDataSource.cacheChats(chats);
return Result.success(chats);
}
// ignore: avoid_print
print('[DEBUG] Remote getChats failed or empty');
// If remote fails, return cached or error
return cachedResult;
}
@@ -97,13 +109,19 @@ class ChatRepositoryImpl implements ChatRepository {
@override
Future<Result<List<Message>>> getMessages(String chatId, {String? cursor}) async {
// ignore: avoid_print
print('[DEBUG] ChatRepository.getMessages for chat: $chatId');
if (cursor == null) {
final cached = await localDataSource.getMessagesFromCache(chatId);
final remote = await remoteDataSource.getMessages(chatId);
if (remote.isSuccess) {
// ignore: avoid_print
print('[DEBUG] Remote getMessages success: ${remote.data!.length} messages');
await localDataSource.cacheMessages(chatId, remote.data!);
return remote;
}
// ignore: avoid_print
print('[DEBUG] Remote getMessages failed: ${remote.failure?.message}');
return cached;
} else {
return remoteDataSource.getMessages(chatId, cursor: cursor);
@@ -130,4 +148,7 @@ class ChatRepositoryImpl implements ChatRepository {
}
return result;
}
@override
Future<Result<void>> clearCache() => localDataSource.clearCache();
}