From bd9cd7a331911991fba2f9fc9b4d9d9ee2fa4a59 Mon Sep 17 00:00:00 2001 From: David Guo Date: Sun, 22 May 2022 22:51:15 -0700 Subject: [PATCH 1/2] fix chat bug, order by timestamp --- michael/components/Chat.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/michael/components/Chat.js b/michael/components/Chat.js index 1d06072..e3f73c4 100644 --- a/michael/components/Chat.js +++ b/michael/components/Chat.js @@ -26,6 +26,13 @@ export default function Chat({ navigation, route }) { let newMessage = snapshot.val(); newMessage = {...newMessage, _id: snapshot.key, createdAt: JSON.parse(newMessage.createdAt)}; + const messagesRef = database.child("groups").child('messages').child(`${group.id}`).child(_id) + // const messagesRef = firebase.database().ref(`${companySymbol}Messages`); + messagesRef.orderByChild("createdAt") + // the callback function once a new message has been created. + console.log(snapshot.val()); + // }); + // Okay still so confused on what this is doing but it works so whatever setMessages((prevMessages) => GiftedChat.append(prevMessages, newMessage) From 1cb75edf2ce181b39135236d2d7a82628f11a2ae Mon Sep 17 00:00:00 2001 From: David Guo Date: Sun, 22 May 2022 22:52:23 -0700 Subject: [PATCH 2/2] edit firebase ref --- michael/components/Chat.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/michael/components/Chat.js b/michael/components/Chat.js index e3f73c4..382ee72 100644 --- a/michael/components/Chat.js +++ b/michael/components/Chat.js @@ -26,11 +26,11 @@ export default function Chat({ navigation, route }) { let newMessage = snapshot.val(); newMessage = {...newMessage, _id: snapshot.key, createdAt: JSON.parse(newMessage.createdAt)}; - const messagesRef = database.child("groups").child('messages').child(`${group.id}`).child(_id) + const messagesRef = database.child("groups").child('messages').child(`${group.id}`) // const messagesRef = firebase.database().ref(`${companySymbol}Messages`); messagesRef.orderByChild("createdAt") // the callback function once a new message has been created. - console.log(snapshot.val()); + console.log('after chat sort ', snapshot.val()); // }); // Okay still so confused on what this is doing but it works so whatever