我们提供不同的聊天频道供用户讨论各种话题。
每个用户都可以访问聊天频道。这是频道的代码:
constructor(props) {
super(props)
this.state = {
messages: [],
currentUser: null,
isLoading: true,
messageID: "",
isTyping: false,
messageText: "",
roomName: this.props.route.params.roomName,
}
}
//---------------------------------------------------------------
async componentDidMount (){
**Code to get current messages**
}
//Add a message to firestore
onSend = async(message) => {
this.setState({isTyping: true,})
const messageID = uuidv4()
await Firebase.firestore()
.collection("chatRooms")
.doc(this.state.roomName)
.collection("messages")
.doc(messageID)
.set({
_id: messageID,
text: message[0].text,
createdAt: new Date(message[0].createdAt),
user: {
_id: this.state.currentUser.id,
name: this.state.currentUser.name,
avatar: this.state.currentUser.avatar,
},
})
Analytics.logEvent(`ChatMessageSent_${this.state.roomName}`)
}
现在,当用户在任何频道中发送消息时,我想向所有收到推送通知的用户发送通知,说明 xyz 频道中有一条新消息。
我的想法是在 onSend() 中做到这一点:
当用户发送新消息时,调用 firebase 函数向所有用户发送通知,告知 xyz 频道中有新消息。
我想不出其他方法来做到这一点。我已经知道如何发送推送通知,如果有通知,如何更改标签栏图标,等等,但由于有多个渠道,我无法确定具体如何进行。
我也担心这些通知会过于“垃圾邮件”。如果他们在所有渠道中有 x 条未读消息,也许会发送通知?
如果您有更好的想法,请告诉我,提前致谢。