0

I have an issue in reading my documents in Firestore. I want to get the last modified documents (their ID) to check who has sent a message (it's a chat application) but when I open the activity, all the documents are added, even though they were not new. However when another user sends a message, then the change is good, only this user is added. I don't understand why the first change consider all the users added and how to fix it, I hope you'll be able to help me.

                emailWithNewMessage = new ArrayList<>();

                for (DocumentChange change : queryDocumentSnapshots.getDocumentChanges()){
                    if (change.getType()==DocumentChange.Type.MODIFIED || change.getType()==DocumentChange.Type.ADDED){
                        emailWithNewMessage.add(change.getDocument().getId());
                    }
                }
Lucas
  • 1
  • 2
  • Here you can find a tutorial on how to create a complete and functional [Firestore Chat App using Kotlin](https://www.youtube.com/playlist?list=PLn2n4GESV0Ak1HiH0tTPTJXsOEy-5v9qb). Besides that, note that all messages are added again. Please check the duplicate to see why you have that behavior. – Alex Mamo Apr 02 '20 at 10:58
  • Hello thank you ! But I made all the work in java so it's difficult to change... I saw the other question on stack overflow and the answers, I already have an object date, I order new messages by date but what I want is getting the profils were the content was new/modified to put an imageview as notification, how do I search if the date has changed ? – Lucas Apr 02 '20 at 11:49
  • I fixed my problem by adding a string field "MessageIsOpened" in my object in Firestore so that I check on every document if the user has opened the message, I don't have to range all the changed documents – Lucas Apr 02 '20 at 13:16

0 Answers0