I am managing a database within firestore that has the following structure:
-> Chat Room -> Users
Within the "ChatRoom" collection, there is a "Users" collection. Each document in the users collection includes a field "read: true/false" to track whether the user has read the messages in the room.
To fetch the rooms specific to the current user, I utilize the following code:
getRoomFromUserId(userId: string) {
let rooms$: Observable<any>;
let rooms: AngularFirestoreCollection<any>;
rooms = this.afs.collection('ChatRoom', ref => {
return ref.where('Chatter.' + userId, '==', true);
});
rooms$ = rooms.snapshotChanges().map(changes => {
return changes.map(a => {
const data = a.payload.doc.data();
const id = a.payload.doc.id;
return {id, ...data};
});
});
return rooms$;
}
To access data from the "Users" subcollection, I use the following line of code:
this.afs.collection('ChatRoom').doc(RoomID).collection('Users').doc(UserId);
I am keen on retrieving an object that combines the room data and the "read: true/false" status for each room. I believe it is achievable with observables, but I am uncertain about the implementation. Any suggestions on a potential solution would be highly appreciated.