fix: фикс закрепов

This commit is contained in:
Jganenokk
2026-07-25 15:46:40 +07:00
parent 20503c9b1a
commit d0fb5e317f
2 changed files with 36 additions and 0 deletions
+1
View File
@@ -608,6 +608,7 @@ class AccountModule {
} catch (e) {
logger.w('Папки чатов: $e');
}
await chats.applyFavorites(profile.id);
try {
await _saveLoginInfo(data, profile.id);
+35
View File
@@ -1265,6 +1265,7 @@ class ChatsModule {
if (next is! int || next == marker || chats.length < count) break;
marker = next;
}
await applyFavorites(accountId);
} catch (e) {
_paginatedAccountId = null;
logger.w('Пагинация чатов: $e');
@@ -1613,6 +1614,40 @@ class ChatsModule {
}
}
Future<void> applyFavorites(int accountId) async {
try {
final folders = await FoldersModule.loadFolders(accountId);
if (folders.isEmpty) return;
final allFolder = folders.firstWhere(
FoldersModule.isAllChatsFolder,
orElse: () => folders.first,
);
final favorites = allFolder.favorites ?? const <int>[];
final favIndexById = <int, int>{};
for (var i = 0; i < favorites.length; i++) {
favIndexById[favorites[i]] = i + 1;
}
final rows = await AppDatabase.loadChats(accountId, includeHidden: true);
final updates = <Map<String, dynamic>>[];
for (final row in rows) {
final id = row['id'] as int;
final current = (row['fav_index'] as int?) ?? 0;
final next = favIndexById[id] ?? 0;
if (current == next) continue;
final newRow = Map<String, dynamic>.from(row);
newRow['fav_index'] = next;
updates.add(newRow);
}
if (updates.isNotEmpty) {
await AppDatabase.saveChats(updates);
_bump();
}
} catch (e) {
logger.w('applyFavorites: $e');
}
}
Future<String?> setChatMute(
Api api, {
required int chatId,