返回内部可观察哪个运算符?

时间:2018-11-07 13:23:14

标签: typescript firebase rxjs google-cloud-firestore observable

chat.service.ts:

  getUserChats(): Observable<Chat[]> {
    return this.auth.currUser
      .pipe(
        take(1),
        flatMap(user => this.afs
          .collection('chats', ref => {
            console.log(user.uid)
            return ref.where('members', 'array-contains', `/users/${user.uid}`);
          })
          .snapshotChanges()
          .pipe(
            map(actions => {
              return actions.map(action => {
                const data = action.payload.doc.data() as Chat;
                const id = action.payload.doc.id;
                return {id, ...data};
              });
            })
          ) as Observable<Chat[]>)
      );
  }

有没有办法返回保存用户聊天内容的内部Observable?

this.afs
              .collection('chats', ref => {
                console.log(user.uid)
                return ref.where('members', 'array-contains', `/users/${user.uid}`);
              })
              .snapshotChanges()
              .pipe(
                map(actions => {
                  return actions.map(action => {
                    const data = action.payload.doc.data() as Chat;
                    const id = action.payload.doc.id;
                    return {id, ...data};
                  });
                })
              ) as Observable<Chat[]>

在内部可见区域中,我需要等待user.uid查询聊天记录。

1 个答案:

答案 0 :(得分:0)

Switchmap没问题,可以很好地工作,但问题在于“数组包含”不适用于Firestore中的DocumentReferences