Node.js based forum software built for the modern web
recent page, for hour, day, week, month
Baris Usakli4e59b8507369
diff --git a/public/src/forum/recent.js b/public/src/forum/recent.jsindex 5fed07107e..a29b183631 100644--- a/public/src/forum/recent.js+++ b/public/src/forum/recent.js@@ -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);diff --git a/public/templates/config.json b/public/templates/config.jsonindex f41ecdaf19..7e0be8d93d 100644--- a/public/templates/config.json+++ b/public/templates/config.json@@ -26,6 +26,8 @@"^user.*favourites": "favourites","^user/.*": "account",+ "^recent/.*": "recent",+"reset/.*": "reset_code"},"force_refresh": {diff --git a/public/templates/recent.tpl b/public/templates/recent.tplindex 8cf6127874..25f6cd1c34 100644--- a/public/templates/recent.tpl+++ b/public/templates/recent.tpl@@ -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>diff --git a/src/routes/api.js b/src/routes/api.jsindex d201a31c93..845c95e049 100644--- a/src/routes/api.js+++ b/src/routes/api.js@@ -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);});});diff --git a/src/topics.js b/src/topics.jsindex 2e88ebf16c..5e16f791aa 100644--- a/src/topics.js+++ b/src/topics.js@@ -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) {diff --git a/src/websockets.js b/src/websockets.jsindex 8fae538380..d88d7b4e08 100644--- a/src/websockets.js+++ b/src/websockets.js@@ -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);});});