mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 10:06:13 +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);
|
.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.on('event:unread.updateCount', updateUnreadTopicCount);
|
||||||
socket.emit('user.getUnreadCount', updateUnreadTopicCount);
|
socket.emit('user.getUnreadCount', updateUnreadTopicCount);
|
||||||
|
|||||||
@@ -51,14 +51,13 @@ SocketPosts.reply = function(socket, data, callback) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for(var i=0; i<uids.length; ++i) {
|
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.in('uid_' + uids[i]).emit('event:new_post', result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
websockets.emitTopicPostStats();
|
websockets.emitTopicPostStats();
|
||||||
topics.pushUnreadCount();
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ SocketTopics.post = function(socket, data, callback) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for(var i=0; i<uids.length; ++i) {
|
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_post', result.postData);
|
||||||
websockets.in('uid_' + uids[i]).emit('event:new_topic', result.topicData);
|
websockets.in('uid_' + uids[i]).emit('event:new_topic', result.topicData);
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,6 @@ SocketTopics.post = function(socket, data, callback) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
websockets.emitTopicPostStats();
|
websockets.emitTopicPostStats();
|
||||||
topics.pushUnreadCount();
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -188,7 +187,7 @@ SocketTopics.markAsUnreadForAll = function(socket, tids, callback) {
|
|||||||
if(err) {
|
if(err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
topics.pushUnreadCount();
|
topics.pushUnreadCount(socket.uid);
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -156,38 +156,18 @@ module.exports = function(Topics) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.pushUnreadCount = function(uids, callback) {
|
Topics.pushUnreadCount = function(uid, callback) {
|
||||||
if (typeof callback === 'function') {
|
callback = callback || function() {}:
|
||||||
return callback(null);
|
|
||||||
} else {
|
if (!uid || parseInt(uid, 10) === 0) {
|
||||||
return null;
|
return callback();
|
||||||
}
|
}
|
||||||
|
Topics.getTotalUnread(uid, function(err, count) {
|
||||||
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) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
winston.error(err.message);
|
return callback(err);
|
||||||
}
|
|
||||||
|
|
||||||
if (callback) {
|
|
||||||
callback();
|
|
||||||
}
|
}
|
||||||
|
require('../socket.io').in('uid_' + uid).emit('event:unread.updateCount', null, count);
|
||||||
|
callback();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -135,8 +135,8 @@ var
|
|||||||
|
|
||||||
User.updateLastOnlineTime = function(uid, callback) {
|
User.updateLastOnlineTime = function(uid, callback) {
|
||||||
callback = callback || function() {};
|
callback = callback || function() {};
|
||||||
User.getUserField(uid, 'status', function(err, status) {
|
User.getUserFields(uid, ['status', 'lastonline'], function(err, userData) {
|
||||||
if(err || status === 'offline') {
|
if(err || userData.status === 'offline' || Date.now() - parseInt(userData.lastonline, 10) < 300000) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user