So I am building a chat app using flutter and firebase and I need to trigger a function whenever two new users starting chatting with each other for the first time (whenever one of them sent the first message) so I can store that information somewhere to show it later to the users as chat history (people who've got in contact with).
So my data tree looks like this : 'rooms/{roomId}/messages/{messageWithRandomId}'
Logically whenever a user sends the first message to another user the room document gets created along with the sub-collection 'messages' containing a single message document with a randomId. `
I've set up an OnCreate listener on the room's collection and it gets triggered whenever I manually create a new document under 'rooms'.
But it doesn't get triggered when that same document is created by the subcollection.
So my Code looks like this :
export const testfunction = functions.firestore.document('rooms/{_someRoom}').onCreate(async (snapshot,context) => {
// the function Core
}