recent page, for hour, day, week, month

v1.18.x
Baris Usakli 12 years ago
parent 9af26db57a
commit 4e59b85073

@ -5,6 +5,8 @@ define(function() {
Recent.newPostCount = 0; Recent.newPostCount = 0;
Recent.loadingMoreTopics = false; Recent.loadingMoreTopics = false;
var active = '';
Recent.init = function() { Recent.init = function() {
app.enter_room('recent_posts'); app.enter_room('recent_posts');
@ -13,6 +15,24 @@ define(function() {
'event:new_post' '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() { $('#new-topics-alert').on('click', function() {
$(this).hide(); $(this).hide();
}); });
@ -75,7 +95,8 @@ define(function() {
Recent.loadMoreTopics = function() { Recent.loadMoreTopics = function() {
Recent.loadingMoreTopics = true; Recent.loadingMoreTopics = true;
socket.emit('api:topics.loadMoreRecentTopics', { socket.emit('api:topics.loadMoreRecentTopics', {
after: $('#topics-container').children().length after: $('#topics-container').children().length,
term: active
}, function(data) { }, function(data) {
if (data.topics && data.topics.length) { if (data.topics && data.topics.length) {
Recent.onTopicsLoaded(data.topics); Recent.onTopicsLoaded(data.topics);

@ -26,6 +26,8 @@
"^user.*favourites": "favourites", "^user.*favourites": "favourites",
"^user/.*": "account", "^user/.*": "account",
"^recent/.*": "recent",
"reset/.*": "reset_code" "reset/.*": "reset_code"
}, },
"force_refresh": { "force_refresh": {

@ -4,6 +4,15 @@
<div id="category_active_users"></div> <div id="category_active_users"></div>
</ol> </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"> <a href="/recent">
<div class="alert hide" id="new-topics-alert"></div> <div class="alert hide" id="new-topics-alert"></div>
</a> </a>

@ -131,9 +131,9 @@ var user = require('./../user.js'),
}, req.params.id, uid); }, 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; 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); 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 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) { RDB.zrevrangebyscore(args, function(err, tids) {

@ -783,7 +783,7 @@ module.exports.init = function(io) {
var start = data.after, var start = data.after,
end = start + 9; end = start + 9;
topics.getLatestTopics(uid, start, end, function(latestTopics) { topics.getLatestTopics(uid, start, end, data.term, function(latestTopics) {
callback(latestTopics); callback(latestTopics);
}); });
}); });

Loading…
Cancel
Save