mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	updateUnreadCount
This commit is contained in:
		| @@ -24,6 +24,22 @@ define('forum/footer', ['notifications', 'chat'], function(Notifications, Chat) | ||||
| 			.attr('data-content', count > 20 ? '20+' : count); | ||||
| 	} | ||||
|  | ||||
| 	function onNewPost(data) { | ||||
| 		if (data && data.posts && data.posts.length) { | ||||
| 			var post = data.posts[0]; | ||||
| 			if (parseInt(post.uid, 10) !== parseInt(app.uid, 10)) { | ||||
| 				increaseUnreadCount(); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	function increaseUnreadCount() { | ||||
| 		var count = parseInt($('#unread-count').attr('data-content'), 10) + 1; | ||||
| 		updateUnreadTopicCount(null, count); | ||||
| 	} | ||||
|  | ||||
|  | ||||
| 	socket.on('event:new_post', onNewPost); | ||||
|  | ||||
| 	socket.on('event:unread.updateCount', updateUnreadTopicCount); | ||||
| 	socket.emit('user.getUnreadCount', updateUnreadTopicCount); | ||||
|   | ||||
| @@ -51,14 +51,13 @@ SocketPosts.reply = function(socket, data, callback) { | ||||
| 				return; | ||||
| 			} | ||||
| 			for(var i=0; i<uids.length; ++i) { | ||||
| 				if (uids[i] !== socket.uid) { | ||||
| 				if (parseInt(uids[i], 10) !== socket.uid) { | ||||
| 					websockets.in('uid_' + uids[i]).emit('event:new_post', result); | ||||
| 				} | ||||
| 			} | ||||
| 		}); | ||||
|  | ||||
| 		websockets.emitTopicPostStats(); | ||||
| 		topics.pushUnreadCount(); | ||||
| 	}); | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -47,7 +47,7 @@ SocketTopics.post = function(socket, data, callback) { | ||||
| 				return; | ||||
| 			} | ||||
| 			for(var i=0; i<uids.length; ++i) { | ||||
| 				if (uids[i] !== socket.uid) { | ||||
| 				if (parseInt(uids[i], 10) !== socket.uid) { | ||||
| 					websockets.in('uid_' + uids[i]).emit('event:new_post', result.postData); | ||||
| 					websockets.in('uid_' + uids[i]).emit('event:new_topic', result.topicData); | ||||
| 				} | ||||
| @@ -55,7 +55,6 @@ SocketTopics.post = function(socket, data, callback) { | ||||
| 		}); | ||||
|  | ||||
| 		websockets.emitTopicPostStats(); | ||||
| 		topics.pushUnreadCount(); | ||||
| 	}); | ||||
| }; | ||||
|  | ||||
| @@ -188,7 +187,7 @@ SocketTopics.markAsUnreadForAll = function(socket, tids, callback) { | ||||
| 						if(err) { | ||||
| 							return next(err); | ||||
| 						} | ||||
| 						topics.pushUnreadCount(); | ||||
| 						topics.pushUnreadCount(socket.uid); | ||||
| 						next(); | ||||
| 					}); | ||||
| 				}); | ||||
|   | ||||
| @@ -156,38 +156,18 @@ module.exports = function(Topics) { | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	Topics.pushUnreadCount = function(uids, callback) { | ||||
| 		if (typeof callback === 'function') { | ||||
| 			return callback(null); | ||||
| 		} else { | ||||
| 		    return null; | ||||
| 	Topics.pushUnreadCount = function(uid, callback) { | ||||
| 		callback = callback || function() {}: | ||||
|  | ||||
| 		if (!uid || parseInt(uid, 10) === 0) { | ||||
| 			return callback(); | ||||
| 		} | ||||
|  | ||||
| 		var	websockets = require('./../socket.io'); | ||||
|  | ||||
| 		if (!uids) { | ||||
| 			uids = websockets.getConnectedClients(); | ||||
| 		} else if (!Array.isArray(uids)) { | ||||
| 			uids = [uids]; | ||||
| 		} | ||||
|  | ||||
| 		uids = uids.filter(function(value) { | ||||
| 			return parseInt(value, 10) !== 0; | ||||
| 		}); | ||||
|  | ||||
| 		async.eachLimit(uids, 5, function(uid, next) { | ||||
| 			Topics.getTotalUnread(uid, function(err, count) { | ||||
| 				websockets.in('uid_' + uid).emit('event:unread.updateCount', null, count); | ||||
| 				next(); | ||||
| 			}); | ||||
| 		}, function(err) { | ||||
| 		Topics.getTotalUnread(uid, function(err, count) { | ||||
| 			if (err) { | ||||
| 				winston.error(err.message); | ||||
| 			} | ||||
|  | ||||
| 			if (callback) { | ||||
| 				callback(); | ||||
| 				return callback(err); | ||||
| 			} | ||||
| 			require('../socket.io').in('uid_' + uid).emit('event:unread.updateCount', null, count); | ||||
| 			callback(); | ||||
| 		}); | ||||
| 	}; | ||||
|  | ||||
|   | ||||
| @@ -135,8 +135,8 @@ var | ||||
|  | ||||
| 	User.updateLastOnlineTime = function(uid, callback) { | ||||
| 		callback = callback || function() {}; | ||||
| 		User.getUserField(uid, 'status', function(err, status) { | ||||
| 			if(err || status === 'offline') { | ||||
| 		User.getUserFields(uid, ['status', 'lastonline'], function(err, userData) { | ||||
| 			if(err || userData.status === 'offline' || Date.now() - parseInt(userData.lastonline, 10) < 300000) { | ||||
| 				return callback(err); | ||||
| 			} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user