Hi,
I use observeChanges to determine if a new message inside a chat got sent, so I can play a notification sound if the user is not focusing the chat-channel. Everything works fine so far - except one thing. If a user enters the channel the notification audio plays for every document that gets subscribed. I have a limit of 50 messages that get subscribed.
I would like to ask for advice on how I can make observeChanges behave in a way that it will hold back on the initial record and only act if actual new messages are sent.
The function of observeChanges
OOC_Messages.find({ ooc: true, character: { $not: char }}
).observeChanges({
added() {
var oocNow = Session.get("OOC");
if (oocNow == true) { console.log(ooc) ; } else {
$('.enterOOC').css('background', 'green');
var audio = new Audio('/sounds/oocMsg.ogg');
audio.play();
}
},
});
Thanks for any help!