🐛 Fix the is syncing state of chat shows wrongly

This commit is contained in:
2025-12-27 22:55:13 +08:00
parent 7ad7ab53a6
commit 5d0469e187

View File

@@ -332,9 +332,12 @@ class MessagesNotifier extends _$MessagesNotifier {
_allRemoteMessagesFetched = false; _allRemoteMessagesFetched = false;
talker.log('Starting message sync'); talker.log('Starting message sync');
if (!_disposed) { // Use Future.microtask to set syncing state, but check disposal to avoid errors
Future.microtask(() => ref.read(chatSyncingProvider.notifier).set(true)); Future.microtask(() {
} if (!_disposed) {
ref.read(chatSyncingProvider.notifier).set(true);
}
});
try { try {
final dbMessages = await _database.getMessagesForRoom( final dbMessages = await _database.getMessagesForRoom(
_room.id, _room.id,
@@ -411,11 +414,8 @@ class MessagesNotifier extends _$MessagesNotifier {
showErrorAlert(err); showErrorAlert(err);
} finally { } finally {
talker.log('Finished message sync'); talker.log('Finished message sync');
if (!_disposed) { // Always reset global syncing state, regardless of disposal
Future.microtask( Future.microtask(() => ref.read(chatSyncingProvider.notifier).set(false));
() => ref.read(chatSyncingProvider.notifier).set(false),
);
}
_isSyncing = false; _isSyncing = false;
} }
} }
@@ -537,11 +537,8 @@ class MessagesNotifier extends _$MessagesNotifier {
); );
showErrorAlert(err); showErrorAlert(err);
} finally { } finally {
if (!_disposed) { // Always reset global syncing state, regardless of disposal
Future.microtask( Future.microtask(() => ref.read(chatSyncingProvider.notifier).set(false));
() => ref.read(chatSyncingProvider.notifier).set(false),
);
}
} }
} }