| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var async = require('async'), | 
					
						
							|  |  |  | 	nconf = require('nconf'), | 
					
						
							|  |  |  | 	winston = require('winston'), | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-18 15:35:48 -04:00
										 |  |  | 	user = require('../user'), | 
					
						
							|  |  |  | 	utils = require('../../public/src/utils'), | 
					
						
							|  |  |  | 	db = require('../database'), | 
					
						
							|  |  |  | 	notifications = require('../notifications'), | 
					
						
							| 
									
										
										
										
											2014-06-03 12:30:36 -04:00
										 |  |  | 	posts = require('../posts'), | 
					
						
							| 
									
										
										
										
											2014-06-21 01:14:49 -04:00
										 |  |  | 	postTools = require('../postTools'), | 
					
						
							| 
									
										
										
										
											2014-06-26 13:43:57 -04:00
										 |  |  | 	topics = require('../topics'), | 
					
						
							|  |  |  | 	privileges = require('../privileges'); | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | (function(UserNotifications) { | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 	UserNotifications.get = function(uid, callback) { | 
					
						
							|  |  |  | 		function getNotifications(set, start, stop, iterator, done) { | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 			db.getSortedSetRevRange(set, start, stop, function(err, uniqueIds) { | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 				if(err) { | 
					
						
							|  |  |  | 					return done(err); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 				if(!Array.isArray(uniqueIds) || !uniqueIds.length) { | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 					return done(null, []); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 				if (uniqueIds.length > maxNotifs) { | 
					
						
							|  |  |  | 					uniqueIds.length = maxNotifs; | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 				db.getObjectFields('uid:' + uid + ':notifications:uniqueId:nid', uniqueIds, function(err, uniqueIdToNids) { | 
					
						
							|  |  |  | 					if (err) { | 
					
						
							|  |  |  | 						return done(err); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 					var nidsToUniqueIds = {}; | 
					
						
							| 
									
										
										
										
											2014-07-28 17:50:49 -04:00
										 |  |  | 					var nids = []; | 
					
						
							|  |  |  | 					uniqueIds.forEach(function(uniqueId) { | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 						nidsToUniqueIds[uniqueIdToNids[uniqueId]] = uniqueId; | 
					
						
							| 
									
										
										
										
											2014-07-28 17:50:49 -04:00
										 |  |  | 						nids.push(uniqueIdToNids[uniqueId]); | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-28 17:50:49 -04:00
										 |  |  | 					async.map(nids, function(nid, next) { | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 						notifications.get(nid, function(err, notif_data) { | 
					
						
							|  |  |  | 							if (err) { | 
					
						
							|  |  |  | 								return next(err); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							if (!notif_data) { | 
					
						
							|  |  |  | 								if (process.env.NODE_ENV === 'development') { | 
					
						
							|  |  |  | 									winston.info('[notifications.get] nid ' + nid + ' not found. Removing.'); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 								db.sortedSetRemove(set, nidsToUniqueIds[nid]); | 
					
						
							|  |  |  | 								return next(); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							if (typeof iterator === 'function') { | 
					
						
							|  |  |  | 								iterator(notif_data, next); | 
					
						
							|  |  |  | 							} else { | 
					
						
							|  |  |  | 								next(null, notif_data); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					}, done); | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var maxNotifs = 15; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		async.parallel({ | 
					
						
							|  |  |  | 			unread: function(next) { | 
					
						
							| 
									
										
										
										
											2014-07-28 16:08:16 -04:00
										 |  |  | 				getNotifications('uid:' + uid + ':notifications:unread', 0, 9, function(notif_data, next) { | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 					notif_data.read = false; | 
					
						
							|  |  |  | 					notif_data.readClass = !notif_data.read ? 'label-warning' : ''; | 
					
						
							|  |  |  | 					next(null, notif_data); | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 				}, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			read: function(next) { | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 				getNotifications('uid:' + uid + ':notifications:read', 0, 9, function(notif_data, next) { | 
					
						
							|  |  |  | 					notif_data.read = true; | 
					
						
							|  |  |  | 					next(null, notif_data); | 
					
						
							|  |  |  | 				}, next); | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}, function(err, notifications) { | 
					
						
							|  |  |  | 			function filterDeleted(notifObj) { | 
					
						
							|  |  |  | 				return !!notifObj; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-07-28 16:08:16 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			notifications.read = notifications.read.filter(filterDeleted); | 
					
						
							|  |  |  | 			notifications.unread = notifications.unread.filter(filterDeleted); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// Limit the number of notifications to `maxNotifs`, prioritising unread notifications
 | 
					
						
							|  |  |  | 			if (notifications.read.length + notifications.unread.length > maxNotifs) { | 
					
						
							|  |  |  | 				notifications.read.length = maxNotifs - notifications.unread.length; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			callback(null, notifications); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	UserNotifications.getAll = function(uid, limit, before, callback) { | 
					
						
							|  |  |  | 		var	now = new Date(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!limit || parseInt(limit, 10) <= 0) { | 
					
						
							|  |  |  | 			limit = 25; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (before) { | 
					
						
							|  |  |  | 			before = new Date(parseInt(before, 10)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 		db.getObjectValues('uid:' + uid + ':notifications:uniqueId:nid', function(err, nids) { | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 			async.map(nids, function(nid, next) { | 
					
						
							|  |  |  | 				notifications.get(nid, function(err, notif_data) { | 
					
						
							|  |  |  | 					if (err || !notif_data) { | 
					
						
							|  |  |  | 						return next(err); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					UserNotifications.isNotificationRead(notif_data.nid, uid, function(err, isRead) { | 
					
						
							|  |  |  | 						if (err) { | 
					
						
							|  |  |  | 							return next(err); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						notif_data.read = isRead; | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 						next(null, notif_data); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}, function(err, notifs) { | 
					
						
							|  |  |  | 				if (err) { | 
					
						
							|  |  |  | 					return callback(err); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 				notifs = notifs.filter(function(notif) { | 
					
						
							|  |  |  | 					return notif !== null; | 
					
						
							|  |  |  | 				}).sort(function(a, b) { | 
					
						
							|  |  |  | 					return parseInt(b.datetime, 10) - parseInt(a.datetime, 10); | 
					
						
							|  |  |  | 				}).map(function(notif) { | 
					
						
							|  |  |  | 					notif.datetimeISO = utils.toISOString(notif.datetime); | 
					
						
							|  |  |  | 					notif.readClass = !notif.read ? 'label-warning' : ''; | 
					
						
							|  |  |  | 					return notif; | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				callback(null, notifs); | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-03-18 15:35:48 -04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 	UserNotifications.isNotificationRead = function(nid, uid, callback) { | 
					
						
							|  |  |  | 		db.isSortedSetMember('uid:' + uid + ':notifications:read', nid, callback); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-18 15:35:48 -04:00
										 |  |  | 	UserNotifications.getDailyUnread = function(uid, callback) { | 
					
						
							|  |  |  | 		var	now = Date.now(), | 
					
						
							|  |  |  | 			yesterday = now - (1000*60*60*24);	// Approximate, can be more or less depending on time changes, makes no difference really.
 | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		db.getSortedSetRangeByScore('uid:' + uid + ':notifications:unread', 0, 20, yesterday, now, function(err, uniqueIds) { | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (!Array.isArray(uniqueIds) || !uniqueIds.length) { | 
					
						
							|  |  |  | 				return callback(null, []); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			db.getObjectFields('uid:' + uid + ':notifications:uniqueId:nid', uniqueIds, function(err, uniqueIdToNids) { | 
					
						
							|  |  |  | 				if (err) { | 
					
						
							|  |  |  | 					return callback(err); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				var nids = Object.keys(uniqueIdToNids).map(function(uniqueId) { | 
					
						
							|  |  |  | 					return uniqueIdToNids[uniqueId]; | 
					
						
							| 
									
										
										
										
											2014-03-18 15:35:48 -04:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				async.map(nids, function(nid, next) { | 
					
						
							|  |  |  | 					notifications.get(nid, next); | 
					
						
							|  |  |  | 				}, callback); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2014-03-18 15:35:48 -04:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	UserNotifications.getUnreadCount = function(uid, callback) { | 
					
						
							|  |  |  | 		db.sortedSetCount('uid:' + uid + ':notifications:unread', -Infinity, Infinity, callback); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 	UserNotifications.getUnreadByField = function(uid, field, value, callback) { | 
					
						
							|  |  |  | 		db.getSortedSetRange('uid:' + uid + ':notifications:unread', 0, -1, function(err, uniqueIds) { | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 			if (!Array.isArray(uniqueIds) || !uniqueIds.length) { | 
					
						
							|  |  |  | 				return callback(null, []); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 			db.getObjectFields('uid:' + uid + ':notifications:uniqueId:nid', uniqueIds, function(err, uniqueIdsToNids) { | 
					
						
							|  |  |  | 				if (err) { | 
					
						
							|  |  |  | 					return callback(err); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				var nids = Object.keys(uniqueIdsToNids).map(function(uniqueId) { | 
					
						
							|  |  |  | 					return uniqueIdsToNids[uniqueId]; | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				async.filter(nids, function(nid, next) { | 
					
						
							| 
									
										
										
										
											2014-07-28 16:11:26 -04:00
										 |  |  | 					notifications.get(nid, function(err, notifObj) { | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 						if (err || !notifObj) { | 
					
						
							|  |  |  | 							return next(false); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						next(notifObj[field] === value.toString()); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}, function(nids) { | 
					
						
							|  |  |  | 					callback(null, nids); | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-16 15:51:05 -04:00
										 |  |  | 	UserNotifications.sendPostNotificationToFollowers = function(uid, tid, pid) { | 
					
						
							| 
									
										
										
										
											2014-06-03 12:30:36 -04:00
										 |  |  | 		db.getSetMembers('followers:' + uid, function(err, followers) { | 
					
						
							|  |  |  | 			if (err || !followers || !followers.length) { | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			async.parallel({ | 
					
						
							| 
									
										
										
										
											2014-06-20 16:54:34 -04:00
										 |  |  | 				username: async.apply(user.getUserField, uid, 'username'), | 
					
						
							| 
									
										
										
										
											2014-07-21 17:43:38 -04:00
										 |  |  | 				topic: async.apply(topics.getTopicFields, tid, ['slug', 'cid', 'title']), | 
					
						
							| 
									
										
										
										
											2014-06-20 16:54:34 -04:00
										 |  |  | 				postIndex: async.apply(posts.getPidIndex, pid), | 
					
						
							| 
									
										
										
										
											2014-06-21 01:14:49 -04:00
										 |  |  | 				postContent: function(next) { | 
					
						
							|  |  |  | 					async.waterfall([ | 
					
						
							|  |  |  | 						async.apply(posts.getPostField, pid, 'content'), | 
					
						
							|  |  |  | 						function(content, next) { | 
					
						
							|  |  |  | 							postTools.parse(content, next); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					], next); | 
					
						
							| 
									
										
										
										
											2014-07-21 17:43:38 -04:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 				topicFollowers: function(next) { | 
					
						
							|  |  |  | 					db.isSetMembers('tid:' + tid + ':followers', followers, next); | 
					
						
							| 
									
										
										
										
											2014-06-21 01:14:49 -04:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-06-03 12:30:36 -04:00
										 |  |  | 			}, function(err, results) { | 
					
						
							|  |  |  | 				if (err) { | 
					
						
							|  |  |  | 					return; | 
					
						
							| 
									
										
										
										
											2014-04-16 15:51:05 -04:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-06-03 12:30:36 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-21 17:43:38 -04:00
										 |  |  | 				followers = followers.filter(function(value, index) { | 
					
						
							|  |  |  | 					return !results.topicFollowers[index]; | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-03 12:30:36 -04:00
										 |  |  | 				notifications.create({ | 
					
						
							| 
									
										
										
										
											2014-07-21 17:43:38 -04:00
										 |  |  | 					bodyShort: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topic.title + ']]', | 
					
						
							| 
									
										
										
										
											2014-06-20 17:53:40 -04:00
										 |  |  | 					bodyLong: results.postContent, | 
					
						
							| 
									
										
										
										
											2014-06-26 13:43:57 -04:00
										 |  |  | 					path: nconf.get('relative_path') + '/topic/' + results.topic.slug + '/' + results.postIndex, | 
					
						
							| 
									
										
										
										
											2014-07-28 17:50:49 -04:00
										 |  |  | 					uniqueId: 'topic:' + tid + ':uid:' + uid, | 
					
						
							| 
									
										
										
										
											2014-06-03 12:30:36 -04:00
										 |  |  | 					from: uid | 
					
						
							| 
									
										
										
										
											2014-07-28 15:52:33 -04:00
										 |  |  | 				}, function(err, nid) { | 
					
						
							|  |  |  | 					if (err) { | 
					
						
							|  |  |  | 						return; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2014-06-26 13:43:57 -04:00
										 |  |  | 					async.filter(followers, function(uid, next) { | 
					
						
							|  |  |  | 						privileges.categories.can('read', results.topic.cid, uid, function(err, canRead) { | 
					
						
							|  |  |  | 							next(!err && canRead); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					}, function(followers){ | 
					
						
							|  |  |  | 						notifications.push(nid, followers); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2014-06-03 12:30:36 -04:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2014-04-16 15:51:05 -04:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 	UserNotifications.pushCount = function(uid) { | 
					
						
							| 
									
										
										
										
											2014-03-12 20:53:42 -04:00
										 |  |  | 		var websockets = require('./../socket.io'); | 
					
						
							| 
									
										
										
										
											2014-03-12 18:00:27 -04:00
										 |  |  | 		UserNotifications.getUnreadCount(uid, function(err, count) { | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return winston.warn('[User.pushNotifCount] Count not retrieve unread notifications count to push to uid ' + uid + '\'s client(s)'); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			websockets.in('uid_' + uid).emit('event:notifications.updateCount', count); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-10 20:31:57 +01:00
										 |  |  | }(exports)); |