diff --git a/lib/backend/modules/account.dart b/lib/backend/modules/account.dart index babf93c..c74e913 100644 --- a/lib/backend/modules/account.dart +++ b/lib/backend/modules/account.dart @@ -608,6 +608,7 @@ class AccountModule { } catch (e) { logger.w('Папки чатов: $e'); } + await chats.applyFavorites(profile.id); try { await _saveLoginInfo(data, profile.id); diff --git a/lib/backend/modules/chats.dart b/lib/backend/modules/chats.dart index c8686c9..2dcaaca 100644 --- a/lib/backend/modules/chats.dart +++ b/lib/backend/modules/chats.dart @@ -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 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 []; + final favIndexById = {}; + for (var i = 0; i < favorites.length; i++) { + favIndexById[favorites[i]] = i + 1; + } + + final rows = await AppDatabase.loadChats(accountId, includeHidden: true); + final updates = >[]; + 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.from(row); + newRow['fav_index'] = next; + updates.add(newRow); + } + if (updates.isNotEmpty) { + await AppDatabase.saveChats(updates); + _bump(); + } + } catch (e) { + logger.w('applyFavorites: $e'); + } + } + Future setChatMute( Api api, { required int chatId,