refactor: centralize conversation cache management

- Introduced a new method `refreshConversationsCache` to streamline the invalidation of the conversations provider and optionally the folders provider.
- Updated various components to utilize the new cache management method, enhancing code clarity and reducing redundancy.
- This refactor improves the efficiency of conversation and folder synchronization across the application.
This commit is contained in:
cogwheel0
2025-10-02 00:30:14 +05:30
parent 73ccb14b20
commit ff02af1e89
7 changed files with 122 additions and 68 deletions

View File

@@ -236,7 +236,7 @@ class _ChatPageState extends ConsumerState<ChatPage> {
// Force refresh conversations provider to ensure we get the demo conversations
if (!mounted) return;
ref.invalidate(conversationsProvider);
refreshConversationsCache(ref);
// Try to load demo conversation
for (int i = 0; i < 10; i++) {
@@ -1486,7 +1486,7 @@ class _ChatPageState extends ConsumerState<ChatPage> {
// Also refresh the conversations list to reconcile missed events
// and keep timestamps/order in sync with the server.
try {
ref.invalidate(conversationsProvider);
refreshConversationsCache(ref);
// Best-effort await to stabilize UI; ignore errors.
await ref.read(conversationsProvider.future);
} catch (_) {}