Node.js based forum software built for the modern web
updates to posts
psychobunny126f817f7d25
diff --git a/public/templates/topic.tpl b/public/templates/topic.tplindex e69de29bb2..56c230a31f 100644--- a/public/templates/topic.tpl+++ b/public/templates/topic.tpl@@ -0,0 +1,8 @@+<ul class="topic-container">+<!-- BEGIN posts -->+<li class="topic-row">+ <p>{posts.content}</p>+ <p>Posted on {posts.timestamp} by user {posts.uid}.</p>+</li>+<!-- END posts -->+</ul>\ No newline at end of filediff --git a/src/posts.js b/src/posts.jsindex 361b561684..bc1e7ea174 100644--- a/src/posts.js+++ b/src/posts.js@@ -11,7 +11,47 @@ var RDB = require('./redis.js');- Posts.get = function(topic) {+ Posts.get = function(callback, tid, start, end) {+ if (start == null) start = 0;+ if (end == null) end = start + 10;++ RDB.lrange('tid:' + tid + ':posts', start, end, function(pids) {++ var content = [],+ uid = [],+ timestamp = [];++ for (var i=0, ii=pids.length; i<ii; i++) {+ content.push('pid:' + pids[i] + ':content');+ uid.push('pid:' + pids[i] + ':uid');+ timestamp.push('pid:' + pids[i] + ':timestamp');+ }++ if (pids.length > 0) {+ RDB.multi()+ .mget(content)+ .mget(uid)+ .mget(timestamp)+ .exec(function(err, replies) {+ content = replies[0];+ uid = replies[1];+ timestamp = replies[2];++ var posts = [];+ for (var i=0, ii=content.length; i<ii; i++) {+ posts.push({+ 'content' : content[i],+ 'uid' : uid[i],+ 'timestamp' : timestamp[i]+ });+ }++ callback({'posts': posts});+ });+ }+++ });}diff --git a/src/templates.js b/src/templates.jsindex c66932fcff..3954a792c4 100644--- a/src/templates.js+++ b/src/templates.js@@ -25,7 +25,7 @@ var fs = require('fs');Templates.init = function() {loadTemplates([- 'header', 'footer', 'register', 'home',+ 'header', 'footer', 'register', 'home', 'topic','login', 'reset', 'reset_code', 'account_settings','logout', '403','emails/reset', 'emails/reset_plaintext'diff --git a/src/topics.js b/src/topics.jsindex 4265e3b12c..2fdf66bfc3 100644--- a/src/topics.js+++ b/src/topics.js@@ -23,12 +23,12 @@ var RDB = require('./redis.js'),Topics.generate_topic_body = function(callback, tid, start, end) {- if (start == null) start = 0;- if (end == null) end = start + 10;-- RDB.lrange('tid:' + tid + ':posts', start, end, function(tids) {- callback(tids);- });+ 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@@ -42,10 +42,6 @@ var RDB = require('./redis.js'),}, start, end);};- Topics.get_postIDs_by_topicID = function(topicID, start, end) {-- };-Topics.get = function(callback, start, end) {if (start == null) start = 0;if (end == null) end = start + 10;diff --git a/src/webserver.js b/src/webserver.jsindex b1d7b5d085..45bce265c8 100644--- a/src/webserver.js+++ b/src/webserver.js@@ -65,6 +65,7 @@ var express = require('express'),+ // need a proper way to combine these two routes togetherapp.get('/topics/:topic_id', function(req, res) {global.modules.topics.generate_topic_body(function(topic_body) {res.send(templates['header'] + topic_body + templates['footer']);@@ -76,6 +77,8 @@ var express = require('express'),}, req.params.topic_id)});++app.get('/api/:method', function(req, res) {switch(req.params.method) {case 'home' :