fix(chats): просмотренный канал не попадает в список чатов (флаг in_list)
This commit is contained in:
@@ -846,6 +846,7 @@ class ChatsModule {
|
||||
Map<dynamic, dynamic> chat,
|
||||
int accountId, {
|
||||
Map<int, CachedChat>? preloadedExisting,
|
||||
bool inList = true,
|
||||
}) async {
|
||||
final cachedAt = DateTime.now().millisecondsSinceEpoch;
|
||||
final id = chat['id'];
|
||||
@@ -876,7 +877,9 @@ class ChatsModule {
|
||||
if (ex != null && _sameContent(ex, parsed)) {
|
||||
return parsed;
|
||||
}
|
||||
await AppDatabase.saveChats([parsed.toDbRow()]);
|
||||
final row = parsed.toDbRow();
|
||||
row['in_list'] = inList ? 1 : 0;
|
||||
await AppDatabase.saveChats([row]);
|
||||
_bump();
|
||||
return parsed;
|
||||
}
|
||||
@@ -953,7 +956,7 @@ class ChatsModule {
|
||||
),
|
||||
)
|
||||
.whereType<CachedChat>()
|
||||
.map((c) => c.toDbRow())
|
||||
.map((c) => c.toDbRow()..['in_list'] = 1)
|
||||
.toList();
|
||||
|
||||
if (rows.isNotEmpty) {
|
||||
@@ -1295,7 +1298,7 @@ class ChatsModule {
|
||||
try {
|
||||
final info = await getChatInfo(api, chatId);
|
||||
if (info == null) return false;
|
||||
await cacheServerChat(info, accountId);
|
||||
await cacheServerChat(info, accountId, inList: false);
|
||||
return true;
|
||||
} catch (e) {
|
||||
logger.w('ensureChatCached failed for $chatId: $e');
|
||||
|
||||
@@ -185,7 +185,7 @@ class AppDatabase {
|
||||
await _migrateLegacyDb(target);
|
||||
return openDatabase(
|
||||
target,
|
||||
version: 13,
|
||||
version: 14,
|
||||
onOpen: (db) => db.execute('PRAGMA foreign_keys = ON'),
|
||||
onCreate: (db, _) => _createTables(db),
|
||||
onUpgrade: (db, oldVersion, newVersion) async {
|
||||
@@ -248,6 +248,11 @@ class AppDatabase {
|
||||
'ALTER TABLE messages ADD COLUMN deleted INTEGER NOT NULL DEFAULT 0',
|
||||
);
|
||||
}
|
||||
if (oldVersion < 14) {
|
||||
await db.execute(
|
||||
'ALTER TABLE chats_cache ADD COLUMN in_list INTEGER NOT NULL DEFAULT 1',
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -335,6 +340,7 @@ class AppDatabase {
|
||||
options TEXT,
|
||||
owner INTEGER,
|
||||
admins TEXT,
|
||||
in_list INTEGER NOT NULL DEFAULT 1,
|
||||
PRIMARY KEY (id, account_id)
|
||||
)
|
||||
''';
|
||||
@@ -534,7 +540,7 @@ class AppDatabase {
|
||||
final db = await _instance;
|
||||
return db.query(
|
||||
'chats_cache',
|
||||
where: 'account_id = ?',
|
||||
where: 'account_id = ? AND in_list = 1',
|
||||
whereArgs: [accountId],
|
||||
orderBy: 'last_event_time DESC',
|
||||
);
|
||||
@@ -543,8 +549,8 @@ class AppDatabase {
|
||||
static Future<int> sumUnread(int accountId, {int? excludeChatId}) async {
|
||||
final db = await _instance;
|
||||
final where = excludeChatId != null
|
||||
? 'account_id = ? AND id != ?'
|
||||
: 'account_id = ?';
|
||||
? 'account_id = ? AND in_list = 1 AND id != ?'
|
||||
: 'account_id = ? AND in_list = 1';
|
||||
final args = excludeChatId != null
|
||||
? [accountId, excludeChatId]
|
||||
: [accountId];
|
||||
|
||||
@@ -164,6 +164,7 @@ class _ChatScreenState extends State<ChatScreen>
|
||||
late AnimationController _shimmerController;
|
||||
Timer? _shimmerStartTimer;
|
||||
bool _historyKickedOff = false;
|
||||
bool _previewChat = false;
|
||||
List<CachedMessage> _messages = [];
|
||||
final ValueNotifier<int> _messagesRev = ValueNotifier(0);
|
||||
final Set<String> _deletingIds = {};
|
||||
@@ -411,6 +412,7 @@ class _ChatScreenState extends State<ChatScreen>
|
||||
try {
|
||||
final cachedRows = await AppDatabase.loadChat(_myId, widget.chatId);
|
||||
if (cachedRows.isEmpty) {
|
||||
_previewChat = true;
|
||||
await ChatsModule.ensureChatCached(api, _myId, widget.chatId);
|
||||
await ChatsModule.subscribeChat(api, widget.chatId);
|
||||
}
|
||||
@@ -537,6 +539,9 @@ class _ChatScreenState extends State<ChatScreen>
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (_previewChat) {
|
||||
unawaited(ChatsModule.subscribeChat(api, widget.chatId, subscribe: false));
|
||||
}
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
ChatsModule.chatsChanged.removeListener(_onChatsBump);
|
||||
_otherUnread.dispose();
|
||||
|
||||
Reference in New Issue
Block a user