i am working on a chat app which have various channels/rooms, want to display the unread messages for each room/channel, iam able to display the unread messages count on the active room of all the participants but not on all the rooms. The helper function is not executed although the new messages are there in the inactive rooms, any idea? thanks
'unReadCount':function(){
var currentuserid=Meteor.userId();
//updateChannelView
console.log("channelid and userid"+this._id + " " + currentuserid);
var res=channelViewLog.findOne({channelId:this._id,userId:currentuserid})
if(res){
var varlastviewed=new Date(res.lastViwed);
//console.log("last viewed timestamp"+varlastviewed + " " + this._id + " " + new Date());
var res1=Messages.find({channel:this._id,createdAt: {$gte:varlastviewed},user:{ $ne: currentuserid}}).count();
return res1;
}
}
Meteor.publish('PubChannelViewLog', function () {
var currentuserid=this.userId;
return channelViewLog.find({userId:currentuserid});
});
In an app I’m currently working on, we needed to display the same thing – unread counts by room. I started with your approach but ultimately switched once we realized we were going to be throttling the pub/sub, meaning our counts may not be correct on a find/count.
I ended up with a collection of message counts by userid/roomid that reset on entry and incremented on message insertions, rather than querying by last visit/message time.
thanks @vigorwebsolutions, no errors but does not display the unread count, however the room that are currently active and selected by the users display the unread count, this is exactly the opposite i need. it does not makes sense when the user is in a room and it shows unread count, when ever there are new messages in that room. let me try your approach. thanks a lot.
@vigorwebsolutions, i have done as per your suggestion, its simply works. not sure whether its an elegant way of doing, but it works for now. thanks a ton.