0

In Chatting Application I am using StreamBuilder and in stream I am using it. Where layout show sender and reciever messages.

.where
  '(RecieverId == $RecieverId && SenderId == ${_auth.currentUser!.uid}) || (RecieverId == ${_auth.currentUser!.uid} && SenderId == $RecieverId)'
  )
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Muhammad Zain
  • 11
  • 1
  • 2
  • In Chatting Application I am using StreamBuilder and in stream I am using it. Where layout show sender and reciever messages – Muhammad Zain Mar 23 '22 at 21:41

1 Answers1

0

This type of condition is not possible in Firestore without modifying your data structure. My common approach is to have a field participants where you concatenate the UIDs of the two users in lexicographical order. With that field you could then query it with:

.where("participants", "==", "uidOfMuhammad_uidOfPuf")

The ordering of the UIDs is key here, as it removes the distinction between sender and receiver (so you'll still need your RecieverId and SenderId). For more on this model, also have a look at Best way to manage Chat channels in Firebase.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807