合并两个firestore querystream

发布于 2025-01-27 19:46:04 字数 1228 浏览 3 评论 0原文

我正在尝试创建一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文