mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-17 05:50:25 +01:00
This commit is contained in:
@@ -24,17 +24,41 @@ 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) {
|
function prepareUnreadButton() {
|
||||||
if (parseInt(app.uid, 10)) {
|
var unreadTopics = {};
|
||||||
socket.emit('user.getUnreadCount', updateUnreadTopicCount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
socket.on('event:new_post', onNewPost);
|
function onNewPost(data) {
|
||||||
|
if (data && data.posts && data.posts.length) {
|
||||||
|
var post = data.posts[0];
|
||||||
|
|
||||||
|
if (parseInt(post.uid, 10) !== parseInt(app.uid, 10) && !unreadTopics[post.topic.tid]) {
|
||||||
|
increaseUnreadCount();
|
||||||
|
unreadTopics[post.topic.tid] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function increaseUnreadCount() {
|
||||||
|
var count = parseInt($('#unread-count').attr('data-content'), 10) + 1;
|
||||||
|
updateUnreadTopicCount(null, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
$(window).on('action:ajaxify.end', function(ev, data) {
|
||||||
|
var tid = data.url.match(/^topic\/(\d+)/);
|
||||||
|
|
||||||
|
if (tid && tid[1]) {
|
||||||
|
delete unreadTopics[tid[1]];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
socket.on('event:unread.updateChatCount', updateUnreadChatCount);
|
socket.on('event:unread.updateChatCount', updateUnreadChatCount);
|
||||||
socket.emit('user.getUnreadChatCount', updateUnreadChatCount);
|
socket.emit('user.getUnreadChatCount', updateUnreadChatCount);
|
||||||
|
|
||||||
|
prepareUnreadButton();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user