The previous chat data contains the pre-change nickname, so it is not reflected in real time when changing the nickname. What method should I use to make the nickname change in real time even the chat before changing the nickname?.
Do I have to change the nickname information in the chat data every time I change my nickname?
Firebase.usersRef
.doc(Firebase.currentUser.email)
.update({'nickname': nickname})
.then(() ⇒ {
Firebase.chatsRef
.where('user.name', '==', Firebase.currentUser.email)
.get()
.then((querySnapshot) ⇒ {
querySnapshot.forEach(doc ⇒
// Changing the nickname
)
})
})
.catch(err => console.log(err));
You should identify the user for each chat message by a so-called stable identifier, which apparently their nickname is not in your case.
Given that you seem to be using Firebase Authentication, the most common stable identifier for a user is their UID, which you can get with Firebase.currentUser.uid. So in addition to the nickname for the user, also store their UID in each document. Then use the UID for selecting the messages for a user, and use the nickname only to display in the UI,