Вы можете просто поле, как чтение и обновление, как:
Способ маркировки одно сообщение прочитанным:
markRead: function(messageId){
Messages.update(messageId, {
$set: {
read: true //this needs to be set to false when its inserted
}
})
}
метод Массовое обновление (предполагается, что все сообщения имеют receiverId сохранены):
markAllRead: function(){
Messages.update({receiver: Meteor.userId(), read:false}, {
$set: {
read: true
}
}, {multi: true})
}
вы можете рассчитывать read:false
те, чтобы получить счет и вы не должны писать что-нибудь еще
Helper:
count: function(){
//even if your publish/subscribe is correct, the count we want is from messages that are not read and the receiver is current user.
return Messages.find({receiver: Meteor.userId(), read: false }).count();
}
Событие:
'click .elementClass': function(){
//both users see the messages and they can both click. We want to update the right message for the right user. Otherwise, the other user can mark the message as read when the receiver is the other user which they shouldn't be able to do. You can do a simple check on the client side, and another check in the method if necessary.
if(this.receiver === Meteor.userId()){
Meteor.call('markAsRead', this._id)
}
}
Позвольте мне знать, если он решает свои проблемы/ответы на все ваши вопросы.