Node.js based forum software built for the modern web
updated category: tracking active participants + removed placeholder; recent author picture now pulled dynamically; graph/users/picture implemented
psychobunny25e218442a62
diff --git a/public/templates/category.tpl b/public/templates/category.tplindex 0b5e1f7bae..147bf46267 100644--- a/public/templates/category.tpl+++ b/public/templates/category.tpl@@ -15,7 +15,7 @@<div class="span12 topic-row img-polaroid"><div class="latest-post visible-desktop"><div class="pull-right">- <img src="{topics.recent_picture}?s=50" />+ <img style="width: 48px; height: 48px; /*temporary*/" src="/graph/users/{topics.recent_author}/picture" /><p><strong>{topics.recent_author}</strong>: {topics.recent_post}</p></div></div>@@ -37,31 +37,17 @@Recent Replies</div><div class="block-content">- <img src="http://www.gravatar.com/avatar/fd37ce111f863c6665045c2d72d199bf?s=48" class="img-polaroid" />- <img src="http://www.gravatar.com/avatar/07c9c7170c3ac676c2561e3eeaee063c?s=48" class="img-polaroid" />- <img src="http://www.gravatar.com/avatar/91050ce0072697b53380c6a03a1bc12a?s=48" class="img-polaroid" />- <img src="http://www.gravatar.com/avatar/fd37ce111f863c6665045c2d72d199bf?s=48" class="img-polaroid" />- <img src="http://www.gravatar.com/avatar/07c9c7170c3ac676c2561e3eeaee063c?s=48" class="img-polaroid" />- <img src="http://www.gravatar.com/avatar/91050ce0072697b53380c6a03a1bc12a?s=48" class="img-polaroid" />- <img src="http://www.gravatar.com/avatar/fd37ce111f863c6665045c2d72d199bf?s=48" class="img-polaroid" />- <img src="http://www.gravatar.com/avatar/07c9c7170c3ac676c2561e3eeaee063c?s=48" class="img-polaroid" />- <img src="http://www.gravatar.com/avatar/91050ce0072697b53380c6a03a1bc12a?s=48" class="img-polaroid" />+</div></div><div class="sidebar-block img-polaroid"><div class="block-header">- Top posters+ Active Participants</div><div class="block-content">- <img src="http://www.gravatar.com/avatar/fd37ce111f863c6665045c2d72d199bf?s=48" class="img-polaroid" />- <img src="http://www.gravatar.com/avatar/07c9c7170c3ac676c2561e3eeaee063c?s=48" class="img-polaroid" />- <img src="http://www.gravatar.com/avatar/91050ce0072697b53380c6a03a1bc12a?s=48" class="img-polaroid" />- <img src="http://www.gravatar.com/avatar/fd37ce111f863c6665045c2d72d199bf?s=48" class="img-polaroid" />- <img src="http://www.gravatar.com/avatar/07c9c7170c3ac676c2561e3eeaee063c?s=48" class="img-polaroid" />- <img src="http://www.gravatar.com/avatar/91050ce0072697b53380c6a03a1bc12a?s=48" class="img-polaroid" />- <img src="http://www.gravatar.com/avatar/fd37ce111f863c6665045c2d72d199bf?s=48" class="img-polaroid" />- <img src="http://www.gravatar.com/avatar/07c9c7170c3ac676c2561e3eeaee063c?s=48" class="img-polaroid" />- <img src="http://www.gravatar.com/avatar/91050ce0072697b53380c6a03a1bc12a?s=48" class="img-polaroid" />+ <!-- BEGIN active_users -->+ <a href="/users/{active_users.username}"><img style="width: 48px; height: 48px; /*temporary*/" src="/graph/users/{active_users.username}/picture" class="img-polaroid" /></a>+ <!-- END active_users --></div></div></div>diff --git a/src/categories.js b/src/categories.jsindex 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.jsindex 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.jsindex 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<ii; i++) {title.push('tid:' + tids[i] + ':title');@@ -43,11 +42,11 @@ var RDB = require('./redis.js'),pinned.push('tid:' + tids[i] + ':pinned');recent_post.push('tid:' + tids[i] + ':recent:post');recent_author.push('tid:' + tids[i] + ':recent:author');- recent_picture.push('tid:' + tids[i] + ':recent:picture');}var multi = RDB.multi()- .get('cid:' + category_id + ':name');+ .get('cid:' + category_id + ':name')+ .smembers('cid:' + category_id + ':active_users');if (tids.length > 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.jsindex 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);