合并两个firestore querystream
我正在尝试创建一个Instagram feed,为此,我有两个查询,一个查询所有公开帖子,另一篇是我关注的用户的私人帖子。
我很难将两个流融合在一起,并且在结尾处仍具有流;我试图使用RXDART,但我觉得自己是不可能的。
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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论