mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-14 01:45:47 +01:00
recent page, for hour, day, week, month
This commit is contained in:
@@ -5,6 +5,8 @@ define(function() {
|
||||
Recent.newPostCount = 0;
|
||||
Recent.loadingMoreTopics = false;
|
||||
|
||||
var active = '';
|
||||
|
||||
Recent.init = function() {
|
||||
app.enter_room('recent_posts');
|
||||
|
||||
@@ -13,6 +15,24 @@ define(function() {
|
||||
'event:new_post'
|
||||
]);
|
||||
|
||||
|
||||
function getActiveSection() {
|
||||
var url = window.location.href,
|
||||
parts = url.split('/'),
|
||||
active = parts[parts.length - 1];
|
||||
return active;
|
||||
}
|
||||
|
||||
active = getActiveSection();
|
||||
|
||||
jQuery('.nav-pills li').removeClass('active');
|
||||
jQuery('.nav-pills li a').each(function() {
|
||||
if (this.getAttribute('href').match(active)) {
|
||||
jQuery(this.parentNode).addClass('active');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
$('#new-topics-alert').on('click', function() {
|
||||
$(this).hide();
|
||||
});
|
||||
@@ -75,7 +95,8 @@ define(function() {
|
||||
Recent.loadMoreTopics = function() {
|
||||
Recent.loadingMoreTopics = true;
|
||||
socket.emit('api:topics.loadMoreRecentTopics', {
|
||||
after: $('#topics-container').children().length
|
||||
after: $('#topics-container').children().length,
|
||||
term: active
|
||||
}, function(data) {
|
||||
if (data.topics && data.topics.length) {
|
||||
Recent.onTopicsLoaded(data.topics);
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
"^user.*favourites": "favourites",
|
||||
"^user/.*": "account",
|
||||
|
||||
"^recent/.*": "recent",
|
||||
|
||||
"reset/.*": "reset_code"
|
||||
},
|
||||
"force_refresh": {
|
||||
|
||||
@@ -4,6 +4,15 @@
|
||||
<div id="category_active_users"></div>
|
||||
</ol>
|
||||
|
||||
<ul class="nav nav-pills">
|
||||
<li class=''><a href='/recent/hour'>[[recent:hour]]</a></li>
|
||||
<li class=''><a href='/recent/day'>[[recent:day]]</a></li>
|
||||
<li class=''><a href='/recent/week'>[[recent:week]]</a></li>
|
||||
<li class=''><a href='/recent/month'>[[recent:month]]</a></li>
|
||||
</ul>
|
||||
|
||||
<br />
|
||||
|
||||
<a href="/recent">
|
||||
<div class="alert hide" id="new-topics-alert"></div>
|
||||
</a>
|
||||
|
||||
@@ -131,9 +131,9 @@ var user = require('./../user.js'),
|
||||
}, req.params.id, uid);
|
||||
});
|
||||
|
||||
app.get('/recent', function (req, res) {
|
||||
app.get('/recent/:term?', function (req, res) {
|
||||
var uid = (req.user) ? req.user.uid : 0;
|
||||
topics.getLatestTopics(uid, 0, 19, function (data) {
|
||||
topics.getLatestTopics(uid, 0, 19, req.params.term, function (data) {
|
||||
res.json(data);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -94,11 +94,22 @@ schema = require('./schema.js'),
|
||||
});
|
||||
}
|
||||
|
||||
Topics.getLatestTopics = function(current_user, start, end, callback) {
|
||||
Topics.getLatestTopics = function(current_user, start, end, term, callback) {
|
||||
|
||||
var timestamp = Date.now();
|
||||
|
||||
var args = ['topics:recent', '+inf', timestamp - 86400000, 'LIMIT', start, end - start + 1];
|
||||
var terms = {
|
||||
hour: 3600000,
|
||||
day: 86400000,
|
||||
week: 604800000,
|
||||
month: 18144000000
|
||||
};
|
||||
|
||||
var since = terms['day'];
|
||||
if(terms[term])
|
||||
since = terms[term];
|
||||
|
||||
var args = ['topics:recent', '+inf', timestamp - since, 'LIMIT', start, end - start + 1];
|
||||
|
||||
RDB.zrevrangebyscore(args, function(err, tids) {
|
||||
|
||||
|
||||
@@ -783,7 +783,7 @@ module.exports.init = function(io) {
|
||||
var start = data.after,
|
||||
end = start + 9;
|
||||
|
||||
topics.getLatestTopics(uid, start, end, function(latestTopics) {
|
||||
topics.getLatestTopics(uid, start, end, data.term, function(latestTopics) {
|
||||
callback(latestTopics);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user