mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	if user is in the topic when a new post comes in mark the topic read
This commit is contained in:
		| @@ -8,11 +8,30 @@ define(['notifications', 'chat'], function(Notifications, Chat) { | |||||||
| 	Chat.prepareDOM(); | 	Chat.prepareDOM(); | ||||||
| 	translator.prepareDOM(); | 	translator.prepareDOM(); | ||||||
|  |  | ||||||
| 	function updateUnreadCount(err, count) { | 	function markCurrentTopicRead(tid) { | ||||||
|  | 		if(tids && tids.length > 0 && tids.indexOf(tid) !== -1) { | ||||||
|  | 			socket.emit('topics.markAsRead', {tid: tid, uid: app.uid}); | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	function updateUnreadCount(err, tids) { | ||||||
|  | 		var count = 0; | ||||||
|  | 		if(tids && tids.length) { | ||||||
|  | 			count = tids.length; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		var postContainer = $('#post-container'); | ||||||
|  | 		if(postContainer.length) { | ||||||
|  | 			markCurrentTopicRead(postContainer.attr('data-tid')); | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 		$('#unread-count').toggleClass('unread-count', count > 0); | 		$('#unread-count').toggleClass('unread-count', count > 0); | ||||||
| 		$('#unread-count').attr('data-content', count > 20 ? '20+' : count); | 		$('#unread-count').attr('data-content', count > 20 ? '20+' : count); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  |  | ||||||
| 	socket.on('event:unread.updateCount', updateUnreadCount); | 	socket.on('event:unread.updateCount', updateUnreadCount); | ||||||
| 	socket.emit('user.getUnreadCount', updateUnreadCount); | 	socket.emit('user.getUnreadCount', updateUnreadCount); | ||||||
| }); | }); | ||||||
| @@ -539,7 +539,6 @@ define(['composer'], function(composer) { | |||||||
| 			'posts.favourite' | 			'posts.favourite' | ||||||
| 		]); | 		]); | ||||||
|  |  | ||||||
|  |  | ||||||
| 		socket.on('get_users_in_room', function(data) { | 		socket.on('get_users_in_room', function(data) { | ||||||
|  |  | ||||||
| 			if(data && data.room.indexOf('topic') !== -1) { | 			if(data && data.room.indexOf('topic') !== -1) { | ||||||
|   | |||||||
| @@ -71,13 +71,23 @@ SocketTopics.postcount = function(socket, tid, callback) { | |||||||
| 	topics.getTopicField(tid, 'postcount', callback); | 	topics.getTopicField(tid, 'postcount', callback); | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | SocketTopics.markAsRead = function(socket, data) { | ||||||
|  | 	if(!data || !data.tid || !data.uid) { | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	topics.markAsRead(data.tid, data.uid, function(err) { | ||||||
|  | 		topics.pushUnreadCount(data.uid); | ||||||
|  | 	}); | ||||||
|  | } | ||||||
|  |  | ||||||
| SocketTopics.markAllRead = function(socket, data, callback) { | SocketTopics.markAllRead = function(socket, data, callback) { | ||||||
| 	topics.markAllRead(socket.uid, function(err) { | 	topics.markAllRead(socket.uid, function(err) { | ||||||
| 		if(err) { | 		if(err) { | ||||||
| 			return callback(err); | 			return callback(err); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		index.server.sockets.in('uid_' + socket.uid).emit('event:unread.updateCount', null, 0); | 		index.server.sockets.in('uid_' + socket.uid).emit('event:unread.updateCount', null, []); | ||||||
|  |  | ||||||
| 		callback(null); | 		callback(null); | ||||||
| 	}); | 	}); | ||||||
|   | |||||||
| @@ -141,9 +141,7 @@ SocketUser.getOnlineAnonCount = function(socket, data, callback) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| SocketUser.getUnreadCount = function(socket, data, callback) { | SocketUser.getUnreadCount = function(socket, data, callback) { | ||||||
| 	topics.getUnreadTids(socket.uid, 0, 19, function(err, tids) { | 	topics.getUnreadTids(socket.uid, 0, 19, callback); | ||||||
| 		callback(err, tids?tids.length:0); |  | ||||||
| 	}); |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
| SocketUser.getActiveUsers = function(socket, data, callback) { | SocketUser.getActiveUsers = function(socket, data, callback) { | ||||||
|   | |||||||
| @@ -184,8 +184,9 @@ var async = require('async'), | |||||||
| 									return callback(err, null); | 									return callback(err, null); | ||||||
| 								} | 								} | ||||||
|  |  | ||||||
| 								Topics.markAsRead(tid, uid); | 								Topics.markAsRead(tid, uid, function(err) { | ||||||
| 								Topics.pushUnreadCount(); | 									Topics.pushUnreadCount(null); | ||||||
|  | 								}); | ||||||
| 							}); | 							}); | ||||||
| 						}); | 						}); | ||||||
| 					}); | 					}); | ||||||
| @@ -633,9 +634,13 @@ var async = require('async'), | |||||||
| 			uids = [uids]; | 			uids = [uids]; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		uids = uids.filter(function(value) { | ||||||
|  | 			return parseInt(value, 10) !== 0; | ||||||
|  | 		}); | ||||||
|  |  | ||||||
| 		async.each(uids, function(uid, next) { | 		async.each(uids, function(uid, next) { | ||||||
| 			Topics.getUnreadTids(uid, 0, 19, function(err, tids) { | 			Topics.getUnreadTids(uid, 0, 19, function(err, tids) { | ||||||
| 				websockets.in('uid_' + uid).emit('event:unread.updateCount', null, tids.length); | 				websockets.in('uid_' + uid).emit('event:unread.updateCount', null, tids); | ||||||
| 				next(); | 				next(); | ||||||
| 			}); | 			}); | ||||||
| 		}, function(err) { | 		}, function(err) { | ||||||
| @@ -764,8 +769,9 @@ var async = require('async'), | |||||||
|  |  | ||||||
| 			// "quiet" is used for things like RSS feed updating, HTML parsing for non-js users, etc | 			// "quiet" is used for things like RSS feed updating, HTML parsing for non-js users, etc | ||||||
| 			if (!quiet) { | 			if (!quiet) { | ||||||
| 				Topics.markAsRead(tid, current_user); | 				Topics.markAsRead(tid, current_user, function(err) { | ||||||
| 				Topics.pushUnreadCount(current_user); | 					Topics.pushUnreadCount(current_user); | ||||||
|  | 				}); | ||||||
| 				Topics.increaseViewCount(tid); | 				Topics.increaseViewCount(tid); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| @@ -916,13 +922,15 @@ var async = require('async'), | |||||||
| 				return callback(err); | 				return callback(err); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			if (tids && tids.length) { | 			if(!tids || !tids.length) { | ||||||
| 				for (var i = 0; i < tids.length; ++i) { | 				return callback(null); | ||||||
| 					Topics.markAsRead(tids[i], uid); |  | ||||||
| 				} |  | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			callback(null); | 			function markRead(tid, next) { | ||||||
|  | 				Topics.markAsRead(tid, uid, next); | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			async.each(tids, markRead, callback); | ||||||
| 		}); | 		}); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -938,9 +946,13 @@ var async = require('async'), | |||||||
| 		db.delete('tid:' + tid + ':read_by_uid', callback); | 		db.delete('tid:' + tid + ':read_by_uid', callback); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	Topics.markAsRead = function(tid, uid) { | 	Topics.markAsRead = function(tid, uid, callback) { | ||||||
|  |  | ||||||
| 		db.setAdd('tid:' + tid + ':read_by_uid', uid); | 		db.setAdd('tid:' + tid + ':read_by_uid', uid, function(err) { | ||||||
|  | 			if(callback) { | ||||||
|  | 				callback(err); | ||||||
|  | 			} | ||||||
|  | 		}); | ||||||
|  |  | ||||||
| 		Topics.getTopicField(tid, 'cid', function(err, cid) { | 		Topics.getTopicField(tid, 'cid', function(err, cid) { | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user