We provide different chat channels for users to talk about various topics.
Every user has access to the chat channels. Here is the code for a channel:
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}`)
}
Now, when a user sends a message in any channel, I want to send a notification to all users who have push notifications on that there is a new message in xyz channel.
My thoughts are to do this in onSend():
When a user sends a new message, call a firebase function to send a notification to all users that there is a new message in xyz channel.
I can't think of another way to do this. I already know how to send push notifications, how to change a tab bar icon if there are notifications, ETC, but am having trouble ideating how exactly to go about this since there are multiple channels.
I am also worried that these notifications will be too "spammy". Perhaps sending out notifications if they have x amount of unread messages across all channels?
Let me know if you have a better idea, thanks in advance.