我在我的应用程序中使用了react-native-gifted-chat来添加聊天功能。目前我能够正确发送和接收来自 firebase 的消息。但是,问题是react-native-gifted-chat
总是显示 12:00 AM 的消息发送时间。这是因为它无法将 firebase 时间戳转换为时间。谁能帮我解决一下?
这是我使用GiftedChat组件的方式:
<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
}}
/>
以下是我用于在 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}] `, '')}
});
}
}
在上面的代码中是有天赋的聊天消息,message
其中包含属性:_id
、、text
和。createdAt
user
以下是消息在 firebase 中的存储方式:
当我显示消息时: