mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 16:05:49 +01:00
recent unread cleanup
This commit is contained in:
@@ -396,6 +396,16 @@ var socket,
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
app.enableInfiniteLoading = function(callback) {
|
||||||
|
$(window).off('scroll').on('scroll', function() {
|
||||||
|
var bottom = ($(document).height() - $(window).height()) * 0.9;
|
||||||
|
|
||||||
|
if ($(window).scrollTop() > bottom) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var titleObj = {
|
var titleObj = {
|
||||||
active: false,
|
active: false,
|
||||||
interval: undefined,
|
interval: undefined,
|
||||||
|
|||||||
@@ -44,10 +44,8 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
|||||||
|
|
||||||
function enableInfiniteLoading() {
|
function enableInfiniteLoading() {
|
||||||
if(!config.usePagination) {
|
if(!config.usePagination) {
|
||||||
$(window).off('scroll').on('scroll', function (ev) {
|
app.enableInfiniteLoading(function() {
|
||||||
var bottom = ($(document).height() - $(window).height()) * 0.9;
|
if(!loadingMoreTopics) {
|
||||||
|
|
||||||
if ($(window).scrollTop() > bottom && !loadingMoreTopics) {
|
|
||||||
Category.loadMoreTopics(templates.get('category_id'));
|
Category.loadMoreTopics(templates.get('category_id'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,20 +1,16 @@
|
|||||||
define(function() {
|
define(function() {
|
||||||
var Recent = {};
|
var Recent = {};
|
||||||
|
|
||||||
Recent.newTopicCount = 0;
|
var newTopicCount = 0,
|
||||||
Recent.newPostCount = 0;
|
newPostCount = 0,
|
||||||
Recent.loadingMoreTopics = false;
|
loadingMoreTopics = false;
|
||||||
|
|
||||||
var active = '';
|
var active = '';
|
||||||
|
|
||||||
Recent.init = function() {
|
Recent.init = function() {
|
||||||
app.enterRoom('recent_posts');
|
app.enterRoom('recent_posts');
|
||||||
|
|
||||||
ajaxify.register_events([
|
Recent.watchForNewPosts();
|
||||||
'event:new_topic',
|
|
||||||
'event:new_post'
|
|
||||||
]);
|
|
||||||
|
|
||||||
|
|
||||||
function getActiveSection() {
|
function getActiveSection() {
|
||||||
var url = window.location.href,
|
var url = window.location.href,
|
||||||
@@ -37,65 +33,58 @@ define(function() {
|
|||||||
$(this).addClass('hide');
|
$(this).addClass('hide');
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('event:new_topic', function(data) {
|
|
||||||
++Recent.newTopicCount;
|
|
||||||
Recent.updateAlertText();
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('event:new_post', function(data) {
|
app.enableInfiniteLoading(function() {
|
||||||
++Recent.newPostCount;
|
if(!loadingMoreTopics) {
|
||||||
Recent.updateAlertText();
|
|
||||||
});
|
|
||||||
|
|
||||||
$(window).off('scroll').on('scroll', function() {
|
|
||||||
var bottom = ($(document).height() - $(window).height()) * 0.9;
|
|
||||||
|
|
||||||
if ($(window).scrollTop() > bottom && !Recent.loadingMoreTopics) {
|
|
||||||
Recent.loadMoreTopics();
|
Recent.loadMoreTopics();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Recent.watchForNewPosts = function () {
|
||||||
|
|
||||||
|
newPostCount = 0;
|
||||||
|
newTopicCount = 0;
|
||||||
|
|
||||||
|
ajaxify.register_events([
|
||||||
|
'event:new_topic',
|
||||||
|
'event:new_post'
|
||||||
|
]);
|
||||||
|
|
||||||
|
socket.on('event:new_topic', function(data) {
|
||||||
|
++newTopicCount;
|
||||||
|
Recent.updateAlertText();
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('event:new_post', function(data) {
|
||||||
|
++newPostCount;
|
||||||
|
Recent.updateAlertText();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Recent.updateAlertText = function() {
|
Recent.updateAlertText = function() {
|
||||||
var text = 'There';
|
var text = 'There';
|
||||||
|
|
||||||
if (Recent.newTopicCount > 1) {
|
if (newTopicCount > 1) {
|
||||||
text += ' are ' + Recent.newTopicCount + ' new topics';
|
text += ' are ' + newTopicCount + ' new topics';
|
||||||
} else if (Recent.newTopicCount === 1) {
|
} else if (newTopicCount === 1) {
|
||||||
text += ' is a new topic';
|
text += ' is a new topic';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Recent.newPostCount > 1) {
|
if (newPostCount > 1) {
|
||||||
text += (Recent.newTopicCount?' and ':' are ') + Recent.newPostCount + ' new posts';
|
text += (newTopicCount?' and ':' are ') + newPostCount + ' new posts';
|
||||||
} else if(newPostCount === 1) {
|
} else if(newPostCount === 1) {
|
||||||
text += (Recent.newTopicCount?' and ':' is ') + ' a new post';
|
text += (newTopicCount?' and ':' is ') + ' a new post';
|
||||||
}
|
}
|
||||||
|
|
||||||
text += '. Click here to reload.';
|
text += '. Click here to reload.';
|
||||||
|
|
||||||
$('#new-topics-alert').html(text).removeClass('hide').fadeIn('slow');
|
$('#new-topics-alert').html(text).removeClass('hide').fadeIn('slow');
|
||||||
}
|
$('#category-no-topics').addClass('hide');
|
||||||
|
|
||||||
Recent.onTopicsLoaded = function(topics) {
|
|
||||||
var html = templates.prepare(templates['recent'].blocks['topics']).parse({
|
|
||||||
topics: topics
|
|
||||||
});
|
|
||||||
|
|
||||||
translator.translate(html, function(translatedHTML) {
|
|
||||||
var container = $('#topics-container');
|
|
||||||
|
|
||||||
$('#category-no-topics').remove();
|
|
||||||
|
|
||||||
html = $(translatedHTML);
|
|
||||||
container.append(html);
|
|
||||||
$('span.timeago').timeago();
|
|
||||||
app.createUserTooltips();
|
|
||||||
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Recent.loadMoreTopics = function() {
|
Recent.loadMoreTopics = function() {
|
||||||
Recent.loadingMoreTopics = true;
|
loadingMoreTopics = true;
|
||||||
socket.emit('topics.loadMoreRecentTopics', {
|
socket.emit('topics.loadMoreRecentTopics', {
|
||||||
after: $('#topics-container').children('li').length,
|
after: $('#topics-container').children('li').length,
|
||||||
term: active
|
term: active
|
||||||
@@ -103,10 +92,29 @@ define(function() {
|
|||||||
if(err) {
|
if(err) {
|
||||||
return app.alertError(err.message);
|
return app.alertError(err.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.topics && data.topics.length) {
|
if (data.topics && data.topics.length) {
|
||||||
Recent.onTopicsLoaded(data.topics);
|
Recent.onTopicsLoaded('recent', data.topics);
|
||||||
}
|
}
|
||||||
Recent.loadingMoreTopics = false;
|
|
||||||
|
loadingMoreTopics = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Recent.onTopicsLoaded = function(template, topics) {
|
||||||
|
var html = templates.prepare(templates[template].blocks['topics']).parse({
|
||||||
|
topics: topics
|
||||||
|
});
|
||||||
|
|
||||||
|
translator.translate(html, function(translatedHTML) {
|
||||||
|
|
||||||
|
$('#category-no-topics').remove();
|
||||||
|
|
||||||
|
html = $(translatedHTML);
|
||||||
|
$('#topics-container').append(html);
|
||||||
|
$('span.timeago').timeago();
|
||||||
|
app.createUserTooltips();
|
||||||
|
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -346,10 +346,8 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
|||||||
|
|
||||||
function enableInfiniteLoading() {
|
function enableInfiniteLoading() {
|
||||||
if(!config.usePagination) {
|
if(!config.usePagination) {
|
||||||
$(window).off('scroll').on('scroll', function() {
|
app.enableInfiniteLoading(function() {
|
||||||
var bottom = ($(document).height() - $(window).height()) * 0.9;
|
if (!infiniteLoaderActive && $('#post-container').children().length) {
|
||||||
|
|
||||||
if ($(window).scrollTop() > bottom && !infiniteLoaderActive && $('#post-container').children().length) {
|
|
||||||
loadMorePosts(tid, function(posts) {
|
loadMorePosts(tid, function(posts) {
|
||||||
fixDeleteStateForPosts();
|
fixDeleteStateForPosts();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,53 +1,15 @@
|
|||||||
define(function() {
|
define(['forum/recent'], function(recent) {
|
||||||
var Unread = {},
|
var Unread = {},
|
||||||
loadingMoreTopics = false;
|
loadingMoreTopics = false;
|
||||||
|
|
||||||
Unread.init = function() {
|
Unread.init = function() {
|
||||||
app.enterRoom('recent_posts');
|
app.enterRoom('recent_posts');
|
||||||
|
|
||||||
ajaxify.register_events([
|
|
||||||
'event:new_topic',
|
|
||||||
'event:new_post',
|
|
||||||
'topics.markAllRead'
|
|
||||||
]);
|
|
||||||
|
|
||||||
var newTopicCount = 0,
|
|
||||||
newPostCount = 0;
|
|
||||||
|
|
||||||
$('#new-topics-alert').on('click', function() {
|
$('#new-topics-alert').on('click', function() {
|
||||||
$(this).addClass('hide');
|
$(this).addClass('hide');
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('event:new_topic', function(data) {
|
recent.watchForNewPosts();
|
||||||
++newTopicCount;
|
|
||||||
updateAlertText();
|
|
||||||
});
|
|
||||||
|
|
||||||
function updateAlertText() {
|
|
||||||
var text = 'There';
|
|
||||||
|
|
||||||
if (newTopicCount > 1) {
|
|
||||||
text += ' are ' + newTopicCount + ' new topics';
|
|
||||||
} else if (newTopicCount === 1) {
|
|
||||||
text += ' is a new topic';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newPostCount > 1) {
|
|
||||||
text += (newTopicCount?' and ':' are ') + newPostCount + ' new posts';
|
|
||||||
} else if(newPostCount === 1) {
|
|
||||||
text += (newTopicCount?' and ':' is ') + ' a new post';
|
|
||||||
}
|
|
||||||
|
|
||||||
text += '. Click here to reload.';
|
|
||||||
|
|
||||||
$('#new-topics-alert').html(text).removeClass('hide').fadeIn('slow');
|
|
||||||
$('#category-no-topics').addClass('hidden');
|
|
||||||
}
|
|
||||||
|
|
||||||
socket.on('event:new_post', function(data) {
|
|
||||||
++newPostCount;
|
|
||||||
updateAlertText();
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#mark-allread-btn').on('click', function() {
|
$('#mark-allread-btn').on('click', function() {
|
||||||
var btn = $(this);
|
var btn = $(this);
|
||||||
@@ -67,25 +29,20 @@ define(function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function onTopicsLoaded(topics) {
|
if ($("body").height() <= $(window).height() && $('#topics-container').children().length >= 20) {
|
||||||
|
$('#load-more-btn').show();
|
||||||
var html = templates.prepare(templates['unread'].blocks['topics']).parse({
|
|
||||||
topics: topics
|
|
||||||
});
|
|
||||||
|
|
||||||
translator.translate(html, function(translatedHTML) {
|
|
||||||
var container = $('#topics-container');
|
|
||||||
|
|
||||||
$('#category-no-topics').remove();
|
|
||||||
|
|
||||||
html = $(translatedHTML);
|
|
||||||
container.append(html);
|
|
||||||
$('span.timeago').timeago();
|
|
||||||
app.createUserTooltips();
|
|
||||||
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$('#load-more-btn').on('click', function() {
|
||||||
|
loadMoreTopics();
|
||||||
|
});
|
||||||
|
|
||||||
|
app.enableInfiniteLoading(function() {
|
||||||
|
if(!loadingMoreTopics) {
|
||||||
|
loadMoreTopics();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function loadMoreTopics() {
|
function loadMoreTopics() {
|
||||||
loadingMoreTopics = true;
|
loadingMoreTopics = true;
|
||||||
socket.emit('topics.loadMoreUnreadTopics', {
|
socket.emit('topics.loadMoreUnreadTopics', {
|
||||||
@@ -96,7 +53,7 @@ define(function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data.topics && data.topics.length) {
|
if (data.topics && data.topics.length) {
|
||||||
onTopicsLoaded(data.topics);
|
recent.onTopicsLoaded('unread', data.topics);
|
||||||
$('#topics-container').attr('data-next-start', data.nextStart);
|
$('#topics-container').attr('data-next-start', data.nextStart);
|
||||||
} else {
|
} else {
|
||||||
$('#load-more-btn').hide();
|
$('#load-more-btn').hide();
|
||||||
@@ -105,23 +62,6 @@ define(function() {
|
|||||||
loadingMoreTopics = false;
|
loadingMoreTopics = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$(window).off('scroll').on('scroll', function() {
|
|
||||||
var bottom = ($(document).height() - $(window).height()) * 0.9;
|
|
||||||
|
|
||||||
if ($(window).scrollTop() > bottom && !loadingMoreTopics) {
|
|
||||||
loadMoreTopics();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
if ($("body").height() <= $(window).height() && $('#topics-container').children().length >= 20) {
|
|
||||||
$('#load-more-btn').show();
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#load-more-btn').on('click', function() {
|
|
||||||
loadMoreTopics();
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return Unread;
|
return Unread;
|
||||||
|
|||||||
Reference in New Issue
Block a user