Implemented per stream subscription recovery with polling fallback
This commit is contained in:
@@ -6,6 +6,7 @@ import '../utils/device_id.dart';
|
||||
import '../models/notification_item.dart';
|
||||
import 'profile_provider.dart';
|
||||
import 'supabase_provider.dart';
|
||||
import 'stream_recovery.dart';
|
||||
import '../utils/app_time.dart';
|
||||
|
||||
final notificationsProvider = StreamProvider<List<NotificationItem>>((ref) {
|
||||
@@ -14,12 +15,26 @@ final notificationsProvider = StreamProvider<List<NotificationItem>>((ref) {
|
||||
return const Stream.empty();
|
||||
}
|
||||
final client = ref.watch(supabaseClientProvider);
|
||||
return client
|
||||
.from('notifications')
|
||||
.stream(primaryKey: ['id'])
|
||||
.eq('user_id', userId)
|
||||
.order('created_at', ascending: false)
|
||||
.map((rows) => rows.map(NotificationItem.fromMap).toList());
|
||||
|
||||
final wrapper = StreamRecoveryWrapper<NotificationItem>(
|
||||
stream: client
|
||||
.from('notifications')
|
||||
.stream(primaryKey: ['id'])
|
||||
.eq('user_id', userId)
|
||||
.order('created_at', ascending: false),
|
||||
onPollData: () async {
|
||||
final data = await client
|
||||
.from('notifications')
|
||||
.select()
|
||||
.eq('user_id', userId)
|
||||
.order('created_at', ascending: false);
|
||||
return data.map(NotificationItem.fromMap).toList();
|
||||
},
|
||||
fromMap: NotificationItem.fromMap,
|
||||
);
|
||||
|
||||
ref.onDispose(wrapper.dispose);
|
||||
return wrapper.stream.map((result) => result.data);
|
||||
});
|
||||
|
||||
final unreadNotificationsCountProvider = Provider<int>((ref) {
|
||||
|
||||
Reference in New Issue
Block a user