watchNewItems method
Returns a stream that emits raw maps for new items as they arrive.
userId — when non-null, limits the stream to items for that user.
Implementation
@override
Stream<Map<String, dynamic>> watchNewItems({String? userId}) {
final now = DateTime.now();
var query = _ref
.where('timestamp', isGreaterThan: now.toIso8601String())
.orderBy('timestamp', descending: true);
if (userId != null) {
query = query.where('actorId', isEqualTo: userId);
}
return query.snapshots().expand(
(qs) => qs.docChanges
.where((c) => c.type == DocumentChangeType.added)
.map((c) => {'id': c.doc.id, ...?c.doc.data()}),
);
}