started working on threadss, implemented slug url, fixed crashing bug during post creation

v1.18.x
psychobunny 12 years ago
parent a085b7eb0a
commit 98ca14e31c

@ -25,27 +25,20 @@ var ajaxify = {};
var tpl_url = (url === '') ? 'home' : url; var tpl_url = (url === '') ? 'home' : url;
if (templates[tpl_url]) { if (templates[tpl_url]) {
if (current_state === null || current_state != url) { window.history.pushState({}, url, "/" + url);
current_state = url;
window.history.pushState({}, url, "/" + url); jQuery('#content, #footer').fadeOut(100);
jQuery('#content, #footer').fadeOut(150, function() { load_template(function() {
//content.innerHTML = templates[tpl_url]; exec_body_scripts(content);
load_template(function() {
exec_body_scripts(content);
ajaxify.enable(); ajaxify.enable();
if (callback) { if (callback) {
callback(); callback();
} }
jQuery('#content, #footer').fadeIn(200); jQuery('#content, #footer').fadeIn(200);
}); });
});
}
return true; return true;
} }

@ -1,10 +1,10 @@
<button id="new_post" class="btn btn-primary btn-large">New Post</button> <button id="new_post" class="btn btn-primary btn-large">New Post</button>
<ul class="topic-container"> <ul class="topic-container">
<!-- BEGIN topics --> <!-- BEGIN topics -->
<li class="topic-row"> <a href="topics/{topics.slug}"><li class="topic-row">
<h4>{topics.title}</h4> <h4>{topics.title}</h4>
<p>Posted on {topics.timestamp} by user {topics.uid}. {topics.post_count} replies.</p> <p>Posted on {topics.timestamp} by user {topics.uid}. {topics.post_count} posts.</p>
</li> </li></a>
<!-- END topics --> <!-- END topics -->
</ul> </ul>
<script type="text/javascript"> <script type="text/javascript">

@ -21,6 +21,17 @@ 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);
});
};
// this needs to move into forum.js
Topics.generate_forum_body = function(callback, start, end) { Topics.generate_forum_body = function(callback, start, end) {
var forum_body = global.templates['home']; var forum_body = global.templates['home'];
@ -31,6 +42,10 @@ var RDB = require('./redis.js'),
}, start, end); }, start, end);
}; };
Topics.get_postIDs_by_topicID = function(topicID, start, end) {
};
Topics.get = function(callback, start, end) { Topics.get = function(callback, start, end) {
if (start == null) start = 0; if (start == null) start = 0;
if (end == null) end = start + 10; if (end == null) end = start + 10;
@ -40,29 +55,30 @@ var RDB = require('./redis.js'),
var title = [], var title = [],
uid = [], uid = [],
timestamp = [], timestamp = [],
posts = []; slug = [],
postcount = [];
for (var i=0, ii=tids.length; i<ii; i++) { for (var i=0, ii=tids.length; i<ii; i++) {
title.push('tid:' + tids[i] + ':title'); title.push('tid:' + tids[i] + ':title');
uid.push('tid:' + tids[i] + ':uid'); uid.push('tid:' + tids[i] + ':uid');
timestamp.push('tid:' + tids[i] + ':timestamp'); timestamp.push('tid:' + tids[i] + ':timestamp');
posts.push('tid:' + tids[i] + ':posts'); slug.push('tid:' + tids[i] + ':slug');
postcount.push('tid:' + tids[i] + ':postcount');
} }
/*RDB.mget(topic, function(topic_data) {
callback(topic_data);
});*/
if (tids.length > 0) { if (tids.length > 0) {
RDB.multi() RDB.multi()
.mget(title) .mget(title)
.mget(uid) .mget(uid)
.mget(timestamp) .mget(timestamp)
.mget(posts) .mget(slug)
.mget(postcount)
.exec(function(err, replies) { .exec(function(err, replies) {
title = replies[0]; title = replies[0];
uid = replies[1]; uid = replies[1];
timestamp = replies[2]; timestamp = replies[2];
posts = replies[3]; slug = replies[3];
postcount = replies[4];
var topics = []; var topics = [];
for (var i=0, ii=title.length; i<ii; i++) { for (var i=0, ii=title.length; i<ii; i++) {
@ -70,8 +86,8 @@ var RDB = require('./redis.js'),
'title' : title[i], 'title' : title[i],
'uid' : uid[i], 'uid' : uid[i],
'timestamp' : timestamp[i], 'timestamp' : timestamp[i],
'posts' : posts[i], 'slug' : slug[i],
'post_count' : 0 'post_count' : postcount[i]
}); });
} }
@ -99,6 +115,7 @@ var RDB = require('./redis.js'),
RDB.incr('global:next_topic_id', function(tid) { RDB.incr('global:next_topic_id', function(tid) {
// Global Topics // Global Topics
if (global.uid == null) global.uid = 0;
if (global.uid !== null) { if (global.uid !== null) {
RDB.lpush('topics:tid', tid); RDB.lpush('topics:tid', tid);
} else { } else {
@ -112,20 +129,25 @@ var RDB = require('./redis.js'),
RDB.lpush('topics:' + category + ':tid', tid); RDB.lpush('topics:' + category + ':tid', tid);
} }
var slug = tid + '/' + slugify(title);
// Topic Info // Topic Info
RDB.set('tid:' + tid + ':title', title); RDB.set('tid:' + tid + ':title', title);
RDB.set('tid:' + tid + ':uid', global.uid); RDB.set('tid:' + tid + ':uid', global.uid);
RDB.set('tid:' + tid + ':slug', slug);
RDB.set('tid:' + tid + ':timestamp', new Date().getTime()); RDB.set('tid:' + tid + ':timestamp', new Date().getTime());
RDB.incr('tid:' + tid + ':postcount');
RDB.set('topic:slug:' + tid + '/' + slugify(title) + ':tid', tid); RDB.set('topic:slug:' + slug + ':tid', tid);
// Posts // Posts
posts.create(content, function(pid) { posts.create(content, function(pid) {
RDB.lpush('tid:' + tid + ':posts', pid); RDB.lpush('tid:' + tid + ':posts', pid);
}); });
// User Details - move this out later // User Details - move this out later
RDB.lpush('uid:' + uid + ':topics', tid); RDB.lpush('uid:' + global.uid + ':topics', tid);
global.socket.emit('event:alert', { global.socket.emit('event:alert', {

@ -60,6 +60,19 @@ var express = require('express'),
}); });
}); });
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']);
}, req.params.topic_id)
});
app.get('/topics/:topic_id/:slug', function(req, res) {
global.modules.topics.generate_topic_body(function(topic_body) {
res.send(templates['header'] + topic_body + templates['footer']);
}, req.params.topic_id)
});
app.get('/api/:method', function(req, res) { app.get('/api/:method', function(req, res) {
switch(req.params.method) { switch(req.params.method) {
case 'home' : case 'home' :

Loading…
Cancel
Save