I used react-native-gifted-chat in my app to add chat feature. Currently I am able to send and receive message from firebase properly. But, the problem is that react-native-gifted-chat
always displays 12:00 AM of message send time. This is because it not able to convert firebase timestamp into time. Can anyone please help me how can I solve it ?
Here is the how I used GiftedChat component :
<GiftedChat
messages={this.props.messages}
renderUsernameOnMessage={true}
onSend={messages => this.onSend(messages)}
alwaysShowSend={true}
textInputStyle={styles.composer}
minComposerHeight={40}
minInputToolbarHeight={60}
user={{
_id: this.props.account ?.user ?.uid,
name: this.props.account ?.data ?.fullName,
avatar: this.props.account ?.data ?.avatar
}}
/>
Below is the code that i used for saving message in firestore :
export const sendMessage = (message, groupId) => {
return async () => {
await firestore().collection('groupMessages').doc(groupId).collection('messages').doc(message._id).set(message).catch((e) => {
throw {message: e.message.replace(`[${e.code}] `, '')}
});
}
}
In above code message
is gifted chat message which contains properties : _id
, text
, createdAt
and user
.
Here is how message is stored in firebase :
When I display message :