如何将角度Firestore代码转换为Flutter

时间:2019-06-23 21:39:36

标签: flutter dart stream google-cloud-firestore

我想将旧的角度代码转换为flutter,如何在flutter中嵌套查询,使此代码正常工作,但是找不到flutter的嵌套查询

this.MatchCollection = this.afs.collection<Matches>('matches',
            ref => ref.where('match', 'array-contains', this.curId).where('status', '==', true));
        this.matchcombine = this.MatchCollection.snapshotChanges().pipe(map(actions => {
            return actions.map(a => {
                const data = a.payload.doc.data() as Matches;
                const uid = this.curId === data.match[0] ? data.match[1] : data.match[0];
                const id = a.payload.doc.id;
                const username = this.afs.collection<User>(`users`).doc(uid).valueChanges();
                const messagesanddate = this.afs.collection<Messages>(`matches`).doc(id).collection(`chat`,
                    ref => ref.orderBy('date', 'desc').limit(1)).valueChanges();
                const notReadedCount = this.afs.collection(`matches`).doc(id).collection(`chat`,
                    ref => ref.where('muid', '==', uid).where('readed', '==', false)).valueChanges();
                const combinedData = combineLatest(username, messagesanddate, notReadedCount,
                    (data1, data3, data4) => {
                        return {...data1, ...data3[0], count: data4.length};
                    });
                return combinedData.pipe(map(datam => Object.assign({}, {id, ...datam, ...data})));
            });
        }), mergeMap(observables => {
            return observables.length > 0 ? combineLatest(observables) : of([]);
        }), tap(m => {
            if (m.length > 0) {
                return m.sort((a, b) => {
                    const aD = a.date ? a.date.toDate() : a.matchDate.toDate();
                    const bD = b.date ? b.date.toDate() : b.matchDate.toDate();
                    return bD < aD ? -1 : 1;
                });
            } else {
                return m;
            }
        }));

0 个答案:

没有答案
相关问题