v1.18.x
Baris Usakli 12 years ago
parent 676765278e
commit 52110016c7

@ -314,6 +314,32 @@ var RDB = require('./redis.js'),
}); });
} }
Categories.moveRecentReplies = function(tid, oldCid, cid, callback) {
topics.getPids(tid, function(err, pids) {
if(!err) {
function movePost(pid, callback) {
posts.getPostField(pid, 'timestamp', function(timestamp) {
RDB.zrem('categories:recent_posts:cid:' + oldCid, pid);
RDB.zadd('categories:recent_posts:cid:' + cid, timestamp, pid);
});
}
async.each(pids, movePost, function(err) {
if(!err) {
callback(null, 1)
} else {
console.log(err);
callback(err, null);
}
});
} else {
console.log(err);
callback(err, null);
}
});
}
Categories.getCategoryData = function(cid, callback) { Categories.getCategoryData = function(cid, callback) {
RDB.hgetall('category:' + cid, function(err, data) { RDB.hgetall('category:' + cid, function(err, data) {
if(err === null) if(err === null)

@ -218,9 +218,9 @@ marked.setOptions({
Posts.create(uid, tid, content, images, function(postData) { Posts.create(uid, tid, content, images, function(postData) {
if (postData) { if (postData) {
RDB.rpush('tid:' + tid + ':posts', postData.pid); topics.addPostToTopic(tid, postData.pid);
RDB.del('tid:' + tid + ':read_by_uid'); topics.markUnRead(tid);
Posts.get_cid_by_pid(postData.pid, function(cid) { Posts.get_cid_by_pid(postData.pid, function(cid) {
RDB.del('cid:' + cid + ':read_by_uid', function(err, data) { RDB.del('cid:' + cid + ':read_by_uid', function(err, data) {

@ -171,6 +171,12 @@ var RDB = require('./redis.js'),
topics.setTopicField(tid, 'cid', cid); topics.setTopicField(tid, 'cid', cid);
categories.moveRecentReplies(tid, oldCid, cid, function(err, data) {
if(err) {
console.log(err);
}
});
categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1); categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1);
categories.incrementCategoryFieldBy(cid, 'topic_count', 1); categories.incrementCategoryFieldBy(cid, 'topic_count', 1);

@ -226,6 +226,10 @@ marked.setOptions({
}); });
} }
Topics.markUnRead = function(tid) {
RDB.del('tid:' + tid + ':read_by_uid');
}
Topics.markAsRead = function(tid, uid) { Topics.markAsRead = function(tid, uid) {
RDB.sadd(schema.topics(tid).read_by_uid, uid); RDB.sadd(schema.topics(tid).read_by_uid, uid);
@ -455,4 +459,12 @@ marked.setOptions({
Topics.setTopicField(tid, 'lastposttime', timestamp); Topics.setTopicField(tid, 'lastposttime', timestamp);
} }
Topics.addPostToTopic = function(tid, pid) {
RDB.rpush('tid:' + tid + ':posts', pid);
}
Topics.getPids = function(tid, callback) {
RDB.lrange('tid:' + tid + ':posts', 0, -1, callback);
}
}(exports)); }(exports));
Loading…
Cancel
Save