v1.18.x
barisusakli 11 years ago
parent ef97f627f4
commit 8efc33d6a1

@ -10,6 +10,7 @@ var db = require('./database'),
plugins = require('./plugins'), plugins = require('./plugins'),
CategoryTools = require('./categoryTools'), CategoryTools = require('./categoryTools'),
meta = require('./meta'), meta = require('./meta'),
emitter = require('./emitter'),
async = require('async'), async = require('async'),
winston = require('winston'), winston = require('winston'),
@ -299,19 +300,24 @@ var db = require('./database'),
}); });
}; };
Categories.onNewPostMade = function(uid, tid, pid, timestamp) { Categories.onNewPostMade = function(postData) {
topics.getTopicFields(tid, ['cid', 'pinned'], function(err, topicData) { topics.getTopicFields(postData.tid, ['cid', 'pinned'], function(err, topicData) {
if (err) {
winston.error(err.message);
}
var cid = topicData.cid; var cid = topicData.cid;
db.sortedSetAdd('categories:recent_posts:cid:' + cid, timestamp, pid); db.sortedSetAdd('categories:recent_posts:cid:' + cid, postData.timestamp, postData.pid);
if(parseInt(topicData.pinned, 10) === 0) { if(parseInt(topicData.pinned, 10) === 0) {
db.sortedSetAdd('categories:' + cid + ':tid', timestamp, tid); db.sortedSetAdd('categories:' + cid + ':tid', postData.timestamp, postData.tid);
} }
Categories.addActiveUser(cid, uid, timestamp); Categories.addActiveUser(cid, postData.uid, postData.timestamp);
}); });
}; };
emitter.on('newpost', Categories.onNewPostMade);
}(exports)); }(exports));

@ -9,6 +9,7 @@ var db = require('./database'),
categories = require('./categories'), categories = require('./categories'),
plugins = require('./plugins'), plugins = require('./plugins'),
meta = require('./meta'), meta = require('./meta'),
emitter = require('./emitter'),
async = require('async'), async = require('async'),
path = require('path'), path = require('path'),
@ -68,9 +69,7 @@ var db = require('./database'),
db.incrObjectField('global', 'postCount'); db.incrObjectField('global', 'postCount');
topics.onNewPostMade(tid, postData.pid, timestamp); emitter.emit('newpost', postData);
categories.onNewPostMade(uid, tid, postData.pid, timestamp);
user.onNewPostMade(uid, tid, postData.pid, timestamp);
plugins.fireHook('filter:post.get', postData, next); plugins.fireHook('filter:post.get', postData, next);
}, },

@ -21,7 +21,8 @@ var async = require('async'),
notifications = require('./notifications'), notifications = require('./notifications'),
favourites = require('./favourites'), favourites = require('./favourites'),
meta = require('./meta'), meta = require('./meta'),
Plugins = require('./plugins'); Plugins = require('./plugins'),
emitter = require('./emitter');
(function(Topics) { (function(Topics) {
@ -1015,12 +1016,14 @@ var async = require('async'),
Topics.setTopicField(tid, 'lastposttime', timestamp); Topics.setTopicField(tid, 'lastposttime', timestamp);
}; };
Topics.onNewPostMade = function(tid, pid, timestamp, callback) { Topics.onNewPostMade = function(postData) {
Topics.increasePostCount(tid); Topics.increasePostCount(postData.tid);
Topics.updateTimestamp(tid, timestamp); Topics.updateTimestamp(postData.tid, postData.timestamp);
Topics.addPostToTopic(tid, pid, timestamp, callback); Topics.addPostToTopic(postData.tid, postData.pid, postData.timestamp);
}; };
emitter.on('newpost', Topics.onNewPostMade);
Topics.addPostToTopic = function(tid, pid, timestamp, callback) { Topics.addPostToTopic = function(tid, pid, timestamp, callback) {
db.sortedSetAdd('tid:' + tid + ':posts', timestamp, pid, callback); db.sortedSetAdd('tid:' + tid + ':posts', timestamp, pid, callback);
}; };

@ -15,6 +15,7 @@ var bcrypt = require('bcryptjs'),
groups = require('./groups'), groups = require('./groups'),
topics = require('./topics'), topics = require('./topics'),
events = require('./events'), events = require('./events'),
emitter = require('./emitter'),
Emailer = require('./emailer'); Emailer = require('./emailer');
(function(User) { (function(User) {
@ -339,16 +340,18 @@ var bcrypt = require('bcryptjs'),
}); });
}; };
User.onNewPostMade = function(uid, tid, pid, timestamp) { User.onNewPostMade = function(postData) {
User.addPostIdToUser(uid, pid, timestamp); User.addPostIdToUser(postData.uid, postData.pid, postData.timestamp);
User.incrementUserFieldBy(uid, 'postcount', 1, function(err, newpostcount) { User.incrementUserFieldBy(postData.uid, 'postcount', 1, function(err, newpostcount) {
db.sortedSetAdd('users:postcount', newpostcount, uid); db.sortedSetAdd('users:postcount', newpostcount, postData.uid);
}); });
User.setUserField(uid, 'lastposttime', timestamp); User.setUserField(postData.uid, 'lastposttime', postData.timestamp);
}; };
emitter.on('newpost', User.onNewPostMade);
User.addPostIdToUser = function(uid, pid, timestamp) { User.addPostIdToUser = function(uid, pid, timestamp) {
db.sortedSetAdd('uid:' + uid + ':posts', timestamp, pid); db.sortedSetAdd('uid:' + uid + ':posts', timestamp, pid);
}; };

Loading…
Cancel
Save