updates to posts

v1.18.x
psychobunny 12 years ago
parent b0e510c862
commit 126f817f7d

@ -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>

@ -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});
});
}
});
}

@ -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'

@ -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;

@ -65,6 +65,7 @@ var express = require('express'),
// need a proper way to combine these two routes together
app.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' :

Loading…
Cancel
Save