あなただけの読み取りのようなフィールドを持っている、とのように更新することができます読み取りとして一つのメッセージをマーキングするための
方法:
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
ものを数えることができますし、
何かを記述する必要はありません
ヘルパー:
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)
}
}
それはあなたの問題/解答のすべてのご質問を解決するかどうか私に教えてください。