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

@ -10,6 +10,7 @@ var db = require('./database'),
plugins = require('./plugins'),
CategoryTools = require('./categoryTools'),
meta = require('./meta'),
emitter = require('./emitter'),
async = require('async'),
winston = require('winston'),
@ -299,19 +300,24 @@ var db = require('./database'),
});
};
Categories.onNewPostMade = function(uid, tid, pid, timestamp) {
topics.getTopicFields(tid, ['cid', 'pinned'], function(err, topicData) {
Categories.onNewPostMade = function(postData) {
topics.getTopicFields(postData.tid, ['cid', 'pinned'], function(err, topicData) {
if (err) {
winston.error(err.message);
}
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) {
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));

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

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

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

Loading…
Cancel
Save