Skip to content

Node.js based forum software built for the modern web

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

psychobunny98ca14e31c00
diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js
index 971f9aef71..ac3d7d4db0 100644
--- a/public/src/ajaxify.js
+++ b/public/src/ajaxify.js
@@ -25,27 +25,20 @@ var ajaxify = {};
var tpl_url = (url === '') ? 'home' : url;
if (templates[tpl_url]) {
- if (current_state === null || current_state != url) {
- current_state = url;
-
- window.history.pushState({}, url, "/" + url);
-
- jQuery('#content, #footer').fadeOut(150, function() {
- //content.innerHTML = templates[tpl_url];
- load_template(function() {
- exec_body_scripts(content);
-
- ajaxify.enable();
- if (callback) {
- callback();
- }
-
- jQuery('#content, #footer').fadeIn(200);
- });
-
- });
+ window.history.pushState({}, url, "/" + url);
+
+ jQuery('#content, #footer').fadeOut(100);
+
+ load_template(function() {
+ exec_body_scripts(content);
+
+ ajaxify.enable();
+ if (callback) {
+ callback();
+ }
- }
+ jQuery('#content, #footer').fadeIn(200);
+ });
return true;
}
diff --git a/public/templates/home.tpl b/public/templates/home.tpl
index 35b4880009..3149404251 100644
--- a/public/templates/home.tpl
+++ b/public/templates/home.tpl
@@ -1,10 +1,10 @@
<button id="new_post" class="btn btn-primary btn-large">New Post</button>
<ul class="topic-container">
<!-- BEGIN topics -->
-<li class="topic-row">
+<a href="topics/{topics.slug}"><li class="topic-row">
<h4>{topics.title}</h4>
- <p>Posted on {topics.timestamp} by user {topics.uid}. {topics.post_count} replies.</p>
-</li>
+ <p>Posted on {topics.timestamp} by user {topics.uid}. {topics.post_count} posts.</p>
+</li></a>
<!-- END topics -->
</ul>
<script type="text/javascript">
diff --git a/public/templates/topic.tpl b/public/templates/topic.tpl
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/src/posts.js b/src/posts.js
index 5568f2a030..361b561684 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -31,7 +31,7 @@ var RDB = require('./redis.js');
// User Details - move this out later
RDB.lpush('uid:' + uid + ':posts', pid);
-
+
if (callback) callback(pid);
});
diff --git a/src/topics.js b/src/topics.js
index 222c55c459..4265e3b12c 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -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) {
var forum_body = global.templates['home'];
@@ -31,6 +42,10 @@ 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;
@@ -40,29 +55,30 @@ var RDB = require('./redis.js'),
var title = [],
uid = [],
timestamp = [],
- posts = [];
+ slug = [],
+ postcount = [];
for (var i=0, ii=tids.length; i<ii; i++) {
title.push('tid:' + tids[i] + ':title');
uid.push('tid:' + tids[i] + ':uid');
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) {
RDB.multi()
.mget(title)
.mget(uid)
.mget(timestamp)
- .mget(posts)
+ .mget(slug)
+ .mget(postcount)
.exec(function(err, replies) {
title = replies[0];
uid = replies[1];
timestamp = replies[2];
- posts = replies[3];
+ slug = replies[3];
+ postcount = replies[4];
var topics = [];
for (var i=0, ii=title.length; i<ii; i++) {
@@ -70,8 +86,8 @@ var RDB = require('./redis.js'),
'title' : title[i],
'uid' : uid[i],
'timestamp' : timestamp[i],
- 'posts' : posts[i],
- 'post_count' : 0
+ 'slug' : slug[i],
+ 'post_count' : postcount[i]
});
}
@@ -99,6 +115,7 @@ var RDB = require('./redis.js'),
RDB.incr('global:next_topic_id', function(tid) {
// Global Topics
+ if (global.uid == null) global.uid = 0;
if (global.uid !== null) {
RDB.lpush('topics:tid', tid);
} else {
@@ -112,20 +129,25 @@ var RDB = require('./redis.js'),
RDB.lpush('topics:' + category + ':tid', tid);
}
+ var slug = tid + '/' + slugify(title);
+
// Topic Info
RDB.set('tid:' + tid + ':title', title);
RDB.set('tid:' + tid + ':uid', global.uid);
+ RDB.set('tid:' + tid + ':slug', slug);
RDB.set('tid:' + tid + ':timestamp', new Date().getTime());
-
- RDB.set('topic:slug:' + tid + '/' + slugify(title) + ':tid', tid);
+ RDB.incr('tid:' + tid + ':postcount');
+
+ RDB.set('topic:slug:' + slug + ':tid', tid);
// Posts
posts.create(content, function(pid) {
RDB.lpush('tid:' + tid + ':posts', pid);
});
+
// User Details - move this out later
- RDB.lpush('uid:' + uid + ':topics', tid);
+ RDB.lpush('uid:' + global.uid + ':topics', tid);
global.socket.emit('event:alert', {
diff --git a/src/webserver.js b/src/webserver.js
index 683dcd7e98..f8e33fc972 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -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) {
switch(req.params.method) {
case 'home' :