am devloping a chat app with flutter and want to know which is best practice when creating a new room should i create a new topic and subscribe to this topic from the client app , or to use message trigger with devices token using sendtodevice method and sendmulticast
exports.messageTrigger = functions.firestore.document('/Messages/{messageID}').onCreate(
async (snapshot, context) => {
var currentRoomUsers = snapshot.data().members;
currentRoomUsers.forEach( (userID) => {
db.collection('Users').doc(userID).get().then(async(doc)=>{
if(doc.exists){
const message = {
notification: {
title: `New message from ${snapshot.data().room}`,
body: snapshot.data().body
},
data: {
click_action: 'FLUTTER_NOTIFICATION_CLICK'
},
tokens: doc.data()['Device_token'],
android: {
priority: "high"
},
priority: 10
}
const response2 = await admin.messaging().sendMulticast(message);
}else {
console.log("No such document!");
}
}).catch((error)=>{
console.log("Error getting document:", error);
});
}
);
i think there is a better way rather than what am actually doing maybe subscribing to topics but how to create a new topic and subscribe users when creating a new room