|
|
@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
var db = require('./database'),
|
|
|
|
var db = require('./database'),
|
|
|
|
utils = require('./../public/src/utils'),
|
|
|
|
utils = require('./../public/src/utils'),
|
|
|
|
user = require('./user'),
|
|
|
|
user = require('./user'),
|
|
|
@ -43,7 +45,7 @@ var db = require('./database'),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
function(pid, next) {
|
|
|
|
function(pid, next) {
|
|
|
|
plugins.fireHook('filter:post.save', content, function(err, newContent) {
|
|
|
|
plugins.fireHook('filter:post.save', content, function(err, newContent) {
|
|
|
|
next(err, pid, newContent)
|
|
|
|
next(err, pid, newContent);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
function(pid, newContent, next) {
|
|
|
|
function(pid, newContent, next) {
|
|
|
@ -62,7 +64,7 @@ var db = require('./database'),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (toPid) {
|
|
|
|
if (toPid) {
|
|
|
|
postData['toPid'] = toPid;
|
|
|
|
postData.toPid = toPid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
db.setObject('post:' + pid, postData, function(err) {
|
|
|
|
db.setObject('post:' + pid, postData, function(err) {
|
|
|
@ -196,7 +198,7 @@ var db = require('./database'),
|
|
|
|
|
|
|
|
|
|
|
|
db.sortedSetRevRank('uid:' + uid + ':posts', posts[posts.length - 1].pid, function(err, rank) {
|
|
|
|
db.sortedSetRevRank('uid:' + uid + ':posts', posts[posts.length - 1].pid, function(err, rank) {
|
|
|
|
if(err) {
|
|
|
|
if(err) {
|
|
|
|
return calllback(err);
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var userPosts = {
|
|
|
|
var userPosts = {
|
|
|
|
posts: posts,
|
|
|
|
posts: posts,
|
|
|
@ -207,7 +209,7 @@ var db = require('./database'),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Posts.addUserInfoToPost = function(post, callback) {
|
|
|
|
Posts.addUserInfoToPost = function(post, callback) {
|
|
|
|
user.getUserFields(post.uid, ['username', 'userslug', 'reputation', 'postcount', 'picture', 'signature', 'banned'], function(err, userData) {
|
|
|
|
user.getUserFields(post.uid, ['username', 'userslug', 'reputation', 'postcount', 'picture', 'signature', 'banned'], function(err, userData) {
|
|
|
@ -299,7 +301,7 @@ var db = require('./database'),
|
|
|
|
postData.title = validator.escape(topicData.title);
|
|
|
|
postData.title = validator.escape(topicData.title);
|
|
|
|
postData.topicSlug = topicData.slug;
|
|
|
|
postData.topicSlug = topicData.slug;
|
|
|
|
next(null, postData);
|
|
|
|
next(null, postData);
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
function(postData, next) {
|
|
|
|
function(postData, next) {
|
|
|
@ -404,7 +406,7 @@ var db = require('./database'),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Posts.uploadPostImage = function(image, callback) {
|
|
|
|
Posts.uploadPostImage = function(image, callback) {
|
|
|
|
|
|
|
|
|
|
|
@ -418,7 +420,7 @@ var db = require('./database'),
|
|
|
|
callback(new Error('Uploads are disabled!'));
|
|
|
|
callback(new Error('Uploads are disabled!'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Posts.uploadPostFile = function(file, callback) {
|
|
|
|
Posts.uploadPostFile = function(file, callback) {
|
|
|
|
|
|
|
|
|
|
|
@ -450,9 +452,8 @@ var db = require('./database'),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// this function should really be called User.getFavouritePosts
|
|
|
|
|
|
|
|
Posts.getFavourites = function(uid, start, end, callback) {
|
|
|
|
Posts.getFavourites = function(uid, start, end, callback) {
|
|
|
|
db.getSortedSetRevRange('uid:' + uid + ':favourites', start, end, function(err, pids) {
|
|
|
|
db.getSortedSetRevRange('uid:' + uid + ':favourites', start, end, function(err, pids) {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
@ -470,7 +471,7 @@ var db = require('./database'),
|
|
|
|
|
|
|
|
|
|
|
|
db.sortedSetRevRank('uid:' + uid + ':favourites', posts[posts.length - 1].pid, function(err, rank) {
|
|
|
|
db.sortedSetRevRank('uid:' + uid + ':favourites', posts[posts.length - 1].pid, function(err, rank) {
|
|
|
|
if(err) {
|
|
|
|
if(err) {
|
|
|
|
return calllback(err);
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var favourites = {
|
|
|
|
var favourites = {
|
|
|
|
posts: posts,
|
|
|
|
posts: posts,
|
|
|
@ -480,28 +481,20 @@ var db = require('./database'),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Posts.getPidPage = function(pid, uid, callback) {
|
|
|
|
Posts.getPidPage = function(pid, uid, callback) {
|
|
|
|
if(!pid) {
|
|
|
|
if(!pid) {
|
|
|
|
return callback(new Error('invalid-pid'));
|
|
|
|
return callback(new Error('invalid-pid'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var index = 0;
|
|
|
|
var index = 0;
|
|
|
|
async.waterfall([
|
|
|
|
async.waterfall([
|
|
|
|
function(next) {
|
|
|
|
function(next) {
|
|
|
|
Posts.getPostField(pid, 'tid', next);
|
|
|
|
Posts.getPidIndex(pid, next);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
function(tid, next) {
|
|
|
|
function(result, next) {
|
|
|
|
topics.getPids(tid, next);
|
|
|
|
index = result;
|
|
|
|
},
|
|
|
|
|
|
|
|
function(pids, next) {
|
|
|
|
|
|
|
|
index = pids.indexOf(pid.toString());
|
|
|
|
|
|
|
|
if(index === -1) {
|
|
|
|
|
|
|
|
return next(new Error('pid not found'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
next();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function(next) {
|
|
|
|
|
|
|
|
user.getSettings(uid, next);
|
|
|
|
user.getSettings(uid, next);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
function(settings, next) {
|
|
|
|
function(settings, next) {
|
|
|
@ -518,6 +511,6 @@ var db = require('./database'),
|
|
|
|
|
|
|
|
|
|
|
|
db.sortedSetRank('tid:' + tid + ':posts', pid, callback);
|
|
|
|
db.sortedSetRank('tid:' + tid + ':posts', pid, callback);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}(exports));
|
|
|
|
}(exports));
|
|
|
|