mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +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();
|
||||
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').attr('data-content', count > 20 ? '20+' : count);
|
||||
}
|
||||
|
||||
|
||||
socket.on('event:unread.updateCount', updateUnreadCount);
|
||||
socket.emit('user.getUnreadCount', updateUnreadCount);
|
||||
});
|
||||
@@ -539,7 +539,6 @@ define(['composer'], function(composer) {
|
||||
'posts.favourite'
|
||||
]);
|
||||
|
||||
|
||||
socket.on('get_users_in_room', function(data) {
|
||||
|
||||
if(data && data.room.indexOf('topic') !== -1) {
|
||||
|
||||
@@ -71,13 +71,23 @@ SocketTopics.postcount = function(socket, tid, 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) {
|
||||
topics.markAllRead(socket.uid, function(err) {
|
||||
if(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);
|
||||
});
|
||||
|
||||
@@ -141,9 +141,7 @@ SocketUser.getOnlineAnonCount = function(socket, data, callback) {
|
||||
};
|
||||
|
||||
SocketUser.getUnreadCount = function(socket, data, callback) {
|
||||
topics.getUnreadTids(socket.uid, 0, 19, function(err, tids) {
|
||||
callback(err, tids?tids.length:0);
|
||||
});
|
||||
topics.getUnreadTids(socket.uid, 0, 19, callback);
|
||||
};
|
||||
|
||||
SocketUser.getActiveUsers = function(socket, data, callback) {
|
||||
|
||||
@@ -184,8 +184,9 @@ var async = require('async'),
|
||||
return callback(err, null);
|
||||
}
|
||||
|
||||
Topics.markAsRead(tid, uid);
|
||||
Topics.pushUnreadCount();
|
||||
Topics.markAsRead(tid, uid, function(err) {
|
||||
Topics.pushUnreadCount(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -633,9 +634,13 @@ var async = require('async'),
|
||||
uids = [uids];
|
||||
}
|
||||
|
||||
uids = uids.filter(function(value) {
|
||||
return parseInt(value, 10) !== 0;
|
||||
});
|
||||
|
||||
async.each(uids, function(uid, next) {
|
||||
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();
|
||||
});
|
||||
}, 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
|
||||
if (!quiet) {
|
||||
Topics.markAsRead(tid, current_user);
|
||||
Topics.pushUnreadCount(current_user);
|
||||
Topics.markAsRead(tid, current_user, function(err) {
|
||||
Topics.pushUnreadCount(current_user);
|
||||
});
|
||||
Topics.increaseViewCount(tid);
|
||||
}
|
||||
|
||||
@@ -916,13 +922,15 @@ var async = require('async'),
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (tids && tids.length) {
|
||||
for (var i = 0; i < tids.length; ++i) {
|
||||
Topics.markAsRead(tids[i], uid);
|
||||
}
|
||||
if(!tids || !tids.length) {
|
||||
return callback(null);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user