Node.js based forum software built for the modern web
more fixes
Baris Usakli98013536d1eb
diff --git a/public/templates/noscript/topic.tpl b/public/templates/noscript/topic.tplindex b1581ddbe6..c9a259a6cd 100644--- a/public/templates/noscript/topic.tpl+++ b/public/templates/noscript/topic.tpl@@ -3,7 +3,7 @@<li><div class="row-fluid"><div class="span2">- <img src="{main_posts.gravatar}" /><br />+ <img src="{main_posts.picture}" /><br />{main_posts.username}</div><div class="span10">@@ -16,7 +16,7 @@<li><div class="row-fluid"><div class="span2">- <img src="{posts.gravatar}" /><br />+ <img src="{posts.picture}" /><br />{posts.username}</div><div class="span10">diff --git a/src/favourites.js b/src/favourites.jsindex 3737e1cc66..675a9fa285 100644--- a/src/favourites.js+++ b/src/favourites.js@@ -91,9 +91,10 @@ var RDB = require('./redis.js'),data[post_id] = hasFavourited;loaded ++;- if (loaded == pids.length) callback(data);+ if (loaded === pids.length)+ callback(data);});- }(pids[i]))+ }(pids[i]));}}diff --git a/src/postTools.js b/src/postTools.jsindex 46fec16701..e54cef7061 100644--- a/src/postTools.js+++ b/src/postTools.js@@ -116,65 +116,5 @@ marked.setOptions({});}- PostTools.constructPostObject = function(rawPosts, tid, current_user, privileges, callback) {- var postObj = [];-- async.waterfall([- function(next) {- if (!privileges) {- threadTools.privileges(tid, current_user, function(privs) {- privileges = privs;- next();- });- } else {- next();- }- },- function(next) {- var postData = rawPosts.postData,- userData = rawPosts.userData,- voteData = rawPosts.voteData;-- if (!postData) {- return next(null, []);- }-- for (var i=0, ii= postData.pid.length; i<ii; i++) {- var uid = postData.uid[i],- pid = postData.pid[i];-- // ############ to be moved into posts.getPostsByTid ############- if (postData.deleted[i] === null || (postData.deleted[i] === '1' && privileges.view_deleted) || current_user === uid) {- var post_obj = {- 'pid' : pid,- 'uid' : uid,- 'content' : marked(postData.content[i] || ''),- 'post_rep' : postData.reputation[i] || 0,- 'timestamp' : postData.timestamp[i],- 'relativeTime': utils.relativeTime(postData.timestamp[i]),- 'username' : userData[uid].username || 'anonymous',- 'userslug' : userData[uid].userslug || '',- 'user_rep' : userData[uid].reputation || 0,- 'gravatar' : userData[uid].picture || 'http://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e',- 'signature' : marked(userData[uid].signature || ''),- 'fav_star_class' : voteData[pid] ? 'icon-star' : 'icon-star-empty',- 'display_moderator_tools': (uid == current_user || privileges.editable) ? 'show' : 'none',- 'edited-class': postData.editor[i] !== null ? '' : 'none',- 'editor': postData.editor[i] !== null ? userData[postData.editor[i]].username : '',- 'relativeEditTime': postData.editTime !== null ? utils.relativeTime(postData.editTime[i]) : '',- 'deleted': postData.deleted[i] || '0'- };-- postObj.push(post_obj);- }- // ########## end to be moved into posts.getPostsByTid ############- }-- next(null);- }- ], function(err) {- callback(postObj);- });- }}(exports));\ No newline at end of filediff --git a/src/posts.js b/src/posts.jsindex 1d6fc26bc2..997f23f5b9 100644--- a/src/posts.js+++ b/src/posts.js@@ -101,9 +101,13 @@ marked.setOptions({for(var i=0, ii=pids.length; i<ii; ++i) {(function(index, pid) {Posts.getPostData(pid, function(postData) {-+if(postData) {- postData.relativeTime = utils.relativeTime(postData.timestamp);+ postData.relativeTime = utils.relativeTime(postData.timestamp);+ postData.post_rep = postData.reputation;+ postData['edited-class'] = postData.editor !== '' ? '' : 'none';+ postData['relativeEditTime'] = postData.edited !== '0' ? utils.relativeTime(postData.edited) : '';+posts[index] = postData;}@@ -218,7 +222,7 @@ marked.setOptions({'username' : data.username || 'anonymous','user_rep' : data.reputation || 0,'post_rep' : 0,- 'gravatar' : data.picture,+ 'picture' : data.picture,'signature' : marked(data.signature || ''),'timestamp' : timestamp,'relativeTime': utils.relativeTime(timestamp),diff --git a/src/schema.js b/src/schema.jsindex 0a64da28ba..1672b7b71f 100644--- a/src/schema.js+++ b/src/schema.js@@ -13,19 +13,6 @@Schema.topics = function(tid) {return {- /* strings */- title: 'tid:' + tid + ':title',- locked: 'tid:' + tid + ':locked',- category_name: 'tid:' + tid + ':category_name',- category_slug: 'tid:' + tid + ':category_slug',- deleted: 'tid:' + tid + ':deleted',- pinned: 'tid:' + tid + ':pinned',- uid: 'tid:' + tid + ':uid',- timestamp: 'tid:' + tid + ':timestamp',- slug: 'tid:' + tid + ':slug',- postcount: 'tid:' + tid + ':postcount',- cid: 'tid:' + tid + ':cid',-/* sets */tid: 'topics:tid',read_by_uid: 'tid:' + tid + ':read_by_uid',diff --git a/src/threadTools.js b/src/threadTools.jsindex ebe75bd0f5..e3c0cb49e8 100644--- a/src/threadTools.js+++ b/src/threadTools.js@@ -233,11 +233,16 @@ var RDB = require('./redis.js'),ThreadTools.notify_followers = function(tid, exceptUid) {async.parallel([function(next) {- topics.get_topic(tid, 0, function(threadData) {- notifications.create(threadData.teaser_username + ' has posted a reply to: "' + threadData.title + '"', null, '/topic/' + tid, 'topic:' + tid, function(nid) {- next(null, nid);++ topics.getTopicField(tid, 'title', function(title) {+ topics.get_teaser(tid, function(teaser) {+ notifications.create(teaser.username + ' has posted a reply to: "' + title + '"', null, '/topic/' + tid, 'topic:' + tid, function(nid) {+ next(null, nid);+ });});});++},function(next) {ThreadTools.get_followers(tid, function(err, followers) {diff --git a/src/topics.js b/src/topics.jsindex f1fb4209c9..ec8a91acc7 100644--- a/src/topics.js+++ b/src/topics.js@@ -9,7 +9,8 @@ var RDB = require('./redis.js')threadTools = require('./threadTools.js'),postTools = require('./postTools'),async = require('async'),- feed = require('./feed.js');+ feed = require('./feed.js'),+ favourites = require('./favourites.js');marked.setOptions({breaks: true@@ -26,24 +27,60 @@ marked.setOptions({});}- Topics.getTopicPosts = function(tid, callback) {- posts.getPostsByTid(tid, 0, -1, function(postData) {- callback(postData);+ Topics.getTopicDataWithUsername = function(tid, callback) {+ Topics.getTopicData(tid, function(topic) {+ user.getUserField(topic.uid, 'username', function(username) {++ topic.username = username;+ callback(topic);+ });});}+ Topics.getTopicPosts = function(tid, start, end, current_user, callback) {+ posts.getPostsByTid(tid, start, end, function(postData) {++ function getFavouritesData(next) {+ var pids = [];+ for(var i=0; i<postData.length; ++i)+ pids.push(postData[i].pid);++ favourites.getFavouritesByPostIDs(pids, current_user, function(fav_data) {+ next(null, fav_data);+ });+ }++ function addUserInfoToPosts(next) {+ var done = 0;- function constructPosts(topicPosts, callback) {- var done = 0;+ for(var i=0, ii=postData.length; i<ii; ++i) {- for(var i=0, ii=topicPosts.length; i<ii; ++i) {+ posts.addUserInfoToPost(postData[i], function() {+ ++done;+ if(done === postData.length)+ next(null, null);+ });+ }+ }++ function getPrivileges(next) {+ threadTools.privileges(tid, current_user, function(privData) {+ next(null, privData);+ });+ }++ async.parallel([getFavouritesData, addUserInfoToPosts, getPrivileges], function(err, results) {+ var fav_data = results[0],+ privileges = results[2];- posts.addUserInfoToPost(topicPosts[i], function() {- ++done;- if(done === topicPosts.length)- callback();+ for(var i=0; i<postData.length; ++i) {+ postData[i].fav_star_class = fav_data[postData[i].pid] ? 'icon-star' : 'icon-star-empty';+ postData[i]['display_moderator_tools'] = (postData[i].uid == current_user || privileges.editable) ? 'show' : 'none';+ }++ callback(postData);});- }+ });}Topics.getTopicById = function(tid, current_user, callback) {@@ -57,7 +94,8 @@ marked.setOptions({}function getTopicPosts(next) {- Topics.getTopicPosts(tid, function(topicPosts) {+ Topics.getTopicPosts(tid, 0, -1, current_user, function(topicPosts, privileges) {+next(null, topicPosts);});}@@ -66,45 +104,37 @@ marked.setOptions({threadTools.privileges(tid, current_user, function(privData) {next(null, privData);});- }+ }async.parallel([getTopicData, getTopicPosts, getPrivileges], function(err, results) {var topicData = results[0],topicPosts = results[1],privileges = results[2];- constructPosts(topicPosts, function() {-- var main_posts = topicPosts.splice(0, 1);-- callback({- 'topic_name':topicData.title,- 'category_name':topicData.category_name,- 'category_slug':topicData.category_slug,- 'locked': topicData.locked,- 'deleted': topicData.deleted,- 'pinned': topicData.pinned,- 'slug': topicData.slug,- 'topic_id': tid,- 'expose_tools': privileges.editable ? 1 : 0,- 'posts': topicPosts,- 'main_posts': main_posts- });+ var main_posts = topicPosts.splice(0, 1);++ callback({+ 'topic_name':topicData.title,+ 'category_name':topicData.category_name,+ 'category_slug':topicData.category_slug,+ 'locked': topicData.locked,+ 'deleted': topicData.deleted,+ 'pinned': topicData.pinned,+ 'slug': topicData.slug,+ 'topic_id': tid,+ 'expose_tools': privileges.editable ? 1 : 0,+ 'posts': topicPosts,+ 'main_posts': main_posts});-});}- Topics.get_topic = function(tid, uid, callback) {-- function get_topic_data(next) {- Topics.getTopicData(tid, function(topic) {- user.getUserField(topic.uid, 'username', function(username) {+ Topics.getTopicForCategoryView = function(tid, uid, callback) {- topic.username = username;- next(null, topic);- });+ function get_topic_data(next) {+ Topics.getTopicDataWithUsername(tid, function(topic) {+ next(null, topic);});}@@ -168,7 +198,7 @@ marked.setOptions({tids.sort(function(a, b) { return b - a; });async.each(tids, function(tid, next) {- Topics.get_topic(tid, 0, function(topicData) {+ Topics.getTopicDataWithUsername(tid, function(topicData) {topics.push(topicData);next();});@@ -235,7 +265,7 @@ marked.setOptions({Topics.get_latest_undeleted_pid = function(tid, callback) {- Topics.getTopicPosts(tid, function(posts) {+ Topics.getTopicPosts(tid, 0, -1, 0, function(posts) {var numPosts = posts.length;if(!numPosts)@@ -344,7 +374,7 @@ marked.setOptions({threadTools.toggleFollow(tid, uid);// Notify any users looking at the category that a new topic has arrived- Topics.get_topic(tid, uid, function(topicData) {+ Topics.getTopicForCategoryView(tid, uid, function(topicData) {io.sockets.in('category_' + category_id).emit('event:new_topic', topicData);io.sockets.in('recent_posts').emit('event:new_topic', topicData);diff --git a/src/webserver.js b/src/webserver.jsindex ef6ef1f96c..1fd5bdc085 100644--- a/src/webserver.js+++ b/src/webserver.js@@ -301,9 +301,9 @@ var express = require('express'),res.send(data);});*/- posts.getPostsByTid(2, 0, -1, function(data) {+ /*posts.getPostsByTid(2, 0, -1, function(data) {res.send(data);- });+ });*//* posts.getPostsByPids([1,2,3], function(data) {res.send(data);@@ -313,9 +313,9 @@ var express = require('express'),res.send(data);});*/- /*topics.getTopicById(1, 1, function(data) {+ topics.getTopicById(24, 1, function(data) {res.send(data);- });*/+ });/* categories.getCategoryById(12, 0, function(returnData) {res.send(returnData);diff --git a/src/websockets.js b/src/websockets.jsindex 29578c4fb4..b3e40b6847 100644--- a/src/websockets.js+++ b/src/websockets.js@@ -332,9 +332,11 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),socket.on('api:composer.push', function(data) {if (uid > 0) {if (parseInt(data.tid) > 0) {- topics.get_topic(data.tid, uid, function(topicData) {- topicData.tid = data.tid;- if (data.body) topicData.body = data.body;+ topics.getTopicData(data.tid, function(topicData) {++ if (data.body)+ topicData.body = data.body;+socket.emit('api:composer.push', {tid: data.tid,title: topicData.title@@ -416,14 +418,10 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),var start = data.after,end = start + 10;- posts.getPostsByTid(data.tid, start, end, function(posts){- if (!posts.error) {- postTools.constructPostObject(posts, data.tid, uid, null, function(postObj) {- io.sockets.in('topic_' + data.tid).emit('event:new_post', {- posts: postObj- });- });- }+ topics.getTopicPosts(data.tid, start, end, uid, function(posts) {+ io.sockets.in('topic_' + data.tid).emit('event:new_post', {+ posts: posts+ });});});