var RDB = require('./redis.js'), posts = require('./posts.js'), utils = require('./utils.js'), user = require('./user.js'); (function(Topics) { //data structure //*global:next_topic_id // *tid:1:title // *tid:1:uid // *tid:1:posts (array of pid) // *tid:1:timestamp // *uid:1:tozpics // *topic:slug:how-to-eat-chicken:tid Topics.get_by_category = function(callback, category, start, end) { } Topics.generate_topic_body = function(callback, tid, start, end) { var topic_body = global.templates['topic']; posts.get(function(data) { topic_body = topic_body.parse(data); callback(topic_body); }, tid, start, end); }; // this needs to move into forum.js Topics.generate_forum_body = function(callback, start, end) { var forum_body = global.templates['home']; Topics.get(function(data) { forum_body = forum_body.parse(data); callback(forum_body); }, start, end); }; Topics.get = function(callback, start, end) { if (start == null) start = 0; if (end == null) end = start + 10; RDB.lrange('topics:tid', start, end, function(tids) { var title = [], uid = [], timestamp = [], slug = [], postcount = []; for (var i=0, ii=tids.length; i 0) { RDB.multi() .mget(title) .mget(uid) .mget(timestamp) .mget(slug) .mget(postcount) .exec(function(err, replies) { title = replies[0]; uid = replies[1]; timestamp = replies[2]; slug = replies[3]; postcount = replies[4]; user.get_usernames_by_uids(uid, function(userNames) { var topics = []; for (var i=0, ii=title.length; i 0) RDB.lpush('tid:' + tid + ':posts', pid); }); // User Details - move this out later RDB.lpush('uid:' + uid + ':topics', tid); socket.emit('event:alert', { title: 'Thank you for posting', message: 'You have successfully posted. Click here to view your post.', type: 'notify', timeout: 2000 }); }); }; }(exports)); //http://dense13.com/blog/2009/05/03/converting-string-to-slug-javascript/ function slugify(str) { str = str.replace(/^\s+|\s+$/g, ''); // trim str = str.toLowerCase(); // remove accents, swap ñ for n, etc var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;"; var to = "aaaaeeeeiiiioooouuuunc------"; for (var i=0, l=from.length ; i