feat(chats): очистка истории и удаление чата из меню

This commit is contained in:
klockky
2026-06-28 14:29:13 +03:00
parent 574206dc21
commit 39c4f89992
2 changed files with 108 additions and 2 deletions
+30
View File
@@ -7,6 +7,7 @@ import '../../core/config/komet_settings.dart';
import '../../core/protocol/opcode_map.dart';
import '../../core/protocol/packet.dart';
import '../../core/cache/info_cache.dart';
import '../../core/cache/message_session_cache.dart';
import '../../core/storage/app_database.dart';
import '../../core/storage/token_storage.dart';
import '../../core/utils/logger.dart';
@@ -1520,6 +1521,35 @@ class ChatsModule {
}
}
static Future<String?> clearHistory(
Api api, {
required int chatId,
required int lastEventTime,
bool forAll = false,
}) async {
try {
await api.sendRequest(Opcode.chatClear, {
'chatId': chatId,
'lastEventTime': lastEventTime,
'forAll': forAll,
});
final accountId = await TokenStorage.getActiveAccountId();
if (accountId != null) {
await AppDatabase.clearMessages(accountId, chatId);
MessageSessionCache.remove(accountId, chatId);
_historyFetched.remove(chatId);
await reconcileLastMessage(accountId, chatId);
}
return null;
} on PacketError catch (e) {
logger.w('clearHistory $chatId: ${e.message}');
return e.message;
} catch (e) {
logger.w('clearHistory $chatId: $e');
return 'Не удалось очистить историю';
}
}
static Future<bool> leaveChat(Api api, {required int chatId}) async {
try {
await api.sendRequest(Opcode.chatLeave, {'chatId': chatId});