'Merge two Firestore QueryStream
I'm trying to create an Instagram feed, for this I have two queries, one that fetches all public posts, and the other one brings private posts from users that I follow.
I have trouble merging both my Stream, and still have a Stream<QuerySnapshot<Map<String, dynamic>>> at the end. I tried to use rxDart, but I feel I'm out of options.
Stream<QuerySnapshot<Map<String, dynamic>>> getUserPostsByUuid(
{String? userUuid, List<dynamic>? followers}) {
List<String> acceptedFollowersUuid = [];
if (followers != null) {
for (var follower in followers) {
acceptedFollowersUuid.add(follower['uuid']);
}
}
final _firestoreSubscribe = _firestore
.collection('posts')
.where('userId',
whereIn:
acceptedFollowersUuid.isEmpty ? [''] : acceptedFollowersUuid)
.orderBy('timestamp', descending: true)
.snapshots();
final _firestorePublic = _firestore
.collection('posts')
.where('isPublic', isEqualTo: true)
.orderBy('timestamp', descending: true)
.snapshots();
// Should return a Stream<QuerySnapshot<Map<String, dynamic>>> with data from both _firestorePublic & _firestoreSubscribe without duplicate.
return _firestorePublic;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
