diff --git a/public/templates/category.tpl b/public/templates/category.tpl index 0b5e1f7bae..147bf46267 100644 --- a/public/templates/category.tpl +++ b/public/templates/category.tpl @@ -15,7 +15,7 @@
- +

{topics.recent_author}: {topics.recent_post}

@@ -37,31 +37,17 @@ Recent Replies
- - - - - - - - - +
diff --git a/src/categories.js b/src/categories.js index 9e740db8f4..1ac673d262 100644 --- a/src/categories.js +++ b/src/categories.js @@ -75,13 +75,7 @@ var RDB = require('./redis.js'), 'slug' : slug[i], 'description' : description[i], 'blockclass' : blockclass[i], - 'icon' : icon[i], - /*'topics' : [0,1], later - 'latest_post' : { - 'uid' : 1, - 'pid' : 1, - timestamp and shit - }*/ + 'icon' : icon[i] }); } diff --git a/src/posts.js b/src/posts.js index f63f155d6d..cba4c066c0 100644 --- a/src/posts.js +++ b/src/posts.js @@ -224,10 +224,23 @@ marked.setOptions({ RDB.incr('tid:' + tid + ':postcount'); - user.getUserFields(uid, ['username','picture'], function(data){ + user.getUserFields(uid, ['username'], function(data){ RDB.set('tid:' + tid + ':recent:post', content); RDB.set('tid:' + tid + ':recent:author', data.username); - RDB.set('tid:' + tid + ':recent:picture', data.picture); + + //add active users to this category + RDB.get('tid:' + tid + ':cid', function(err, cid) { + RDB.handle(err); + + // this is a bit of a naive implementation, defn something to look at post-MVP + RDB.scard('cid:' + cid + ':active_users', function(amount) { + if (amount > 10) { + RDB.spop('cid:' + cid + ':active_users'); + } + + RDB.sadd('cid:' + cid + ':active_users', data.username); + }); + }); }); diff --git a/src/topics.js b/src/topics.js index 74e44e182c..69f79e7d83 100644 --- a/src/topics.js +++ b/src/topics.js @@ -29,8 +29,7 @@ var RDB = require('./redis.js'), deleted = [], pinned = [], recent_post = [], - recent_author = [], - recent_picture = []; + recent_author = []; for (var i=0, ii=tids.length; i 0) { multi @@ -61,26 +60,25 @@ var RDB = require('./redis.js'), .mget(pinned) .mget(recent_post) .mget(recent_author) - .mget(recent_picture) } multi.exec(function(err, replies) { category_name = replies[0]; + active_usernames = replies[1]; var topics = []; if (tids.length > 0) { - title = replies[1]; - uid = replies[2]; - timestamp = replies[3]; - slug = replies[4]; - postcount = replies[5]; - locked = replies[6]; - deleted = replies[7]; - pinned = replies[8]; - recent_post = replies[9]; - recent_author = replies[10]; - recent_picture = replies[11]; + title = replies[2]; + uid = replies[3]; + timestamp = replies[4]; + slug = replies[5]; + postcount = replies[6]; + locked = replies[7]; + deleted = replies[8]; + pinned = replies[9]; + recent_post = replies[10]; + recent_author = replies[11]; var usernames, has_read; @@ -104,8 +102,7 @@ var RDB = require('./redis.js'), 'pin-icon': pinned[i] === '1' ? 'icon-pushpin' : 'none', 'badgeclass' : (has_read[i] && current_user !=0) ? '' : 'badge-important', 'recent_post' : recent_post[i], - 'recent_author' : recent_author[i], - 'recent_picture' : recent_picture[i] + 'recent_author' : recent_author[i] }); } @@ -118,11 +115,17 @@ var RDB = require('./redis.js'), } }); + var active_users = {}; + for (var username in active_usernames) { + active_users['username'] = active_usernames[username]; + } + callback({ 'category_name' : category_id ? category_name : 'Recent', 'show_topic_button' : category_id ? 'show' : 'hidden', 'category_id': category_id || 0, - 'topics': topics + 'topics': topics, + 'active_users': active_users }); } diff --git a/src/webserver.js b/src/webserver.js index 713e03d85d..fd75894fca 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -211,6 +211,21 @@ var express = require('express'), res.send(JSON.stringify(post)); }); }); + + + + //START TODO: MOVE TO GRAPH.JS + + app.get('/graph/users/:username/picture', function(req, res) { + user.get_uid_by_username(req.params.username, function(uid) { + user.getUserField(uid, 'picture', function(picture) { + res.redirect(picture); + }); + }); + + }); + + //END TODO: MOVE TO GRAPH.JS }(WebServer)); server.listen(config.port);