|
|
|
@ -20,8 +20,6 @@ marked.setOptions({
|
|
|
|
|
|
|
|
|
|
(function(Topics) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Topics.getTopicData = function(tid, callback) {
|
|
|
|
|
RDB.hgetall('topic:' + tid, function(err, data) {
|
|
|
|
|
if(err === null)
|
|
|
|
@ -33,8 +31,7 @@ marked.setOptions({
|
|
|
|
|
|
|
|
|
|
Topics.getTopicDataWithUsername = function(tid, callback) {
|
|
|
|
|
Topics.getTopicData(tid, function(topic) {
|
|
|
|
|
user.getUserField(topic.uid, 'username', function(username) {
|
|
|
|
|
|
|
|
|
|
user.getUserField(topic.uid, 'username', function(err, username) {
|
|
|
|
|
topic.username = username;
|
|
|
|
|
callback(topic);
|
|
|
|
|
});
|
|
|
|
@ -128,17 +125,45 @@ marked.setOptions({
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Topics.getTotalUnread = function(uid, callback) {
|
|
|
|
|
RDB.zrevrange('topics:recent', 0, 21, function (err, tids) {
|
|
|
|
|
Topics.hasReadTopics(tids, uid, function(read) {
|
|
|
|
|
var unreadTids = tids.filter(function(tid, index, self) {
|
|
|
|
|
return read[index] === 0;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var unreadTids = [],
|
|
|
|
|
start = 0,
|
|
|
|
|
stop = 21,
|
|
|
|
|
done = false;
|
|
|
|
|
|
|
|
|
|
async.whilst(
|
|
|
|
|
function () { return unreadTids.length < 21 && !done; },
|
|
|
|
|
function (callback) {
|
|
|
|
|
RDB.zrevrange('topics:recent', start, stop, function(err, tids) {
|
|
|
|
|
|
|
|
|
|
if(err)
|
|
|
|
|
return callback(err);
|
|
|
|
|
|
|
|
|
|
if(tids && !tids.length) {
|
|
|
|
|
done = true;
|
|
|
|
|
return callback(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Topics.hasReadTopics(tids, uid, function(read) {
|
|
|
|
|
|
|
|
|
|
var newtids = tids.filter(function(tid, index, self) {
|
|
|
|
|
return read[index] === 0;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
unreadTids.push.apply(unreadTids, newtids);
|
|
|
|
|
|
|
|
|
|
start = stop + 1;
|
|
|
|
|
stop = start + 21;
|
|
|
|
|
callback(null);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
function (err) {
|
|
|
|
|
callback({
|
|
|
|
|
count: unreadTids.length
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Topics.getUnreadTopics = function(uid, start, stop, callback) {
|
|
|
|
@ -153,50 +178,67 @@ marked.setOptions({
|
|
|
|
|
'topics' : []
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
RDB.zrevrange('topics:recent', start, stop, function (err, tids) {
|
|
|
|
|
function noUnreadTopics() {
|
|
|
|
|
unreadTopics.no_topics_message = 'show';
|
|
|
|
|
unreadTopics.show_markallread_button = 'hidden';
|
|
|
|
|
callback(unreadTopics);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function noUnreadTopics() {
|
|
|
|
|
unreadTopics.no_topics_message = 'show';
|
|
|
|
|
unreadTopics.show_markallread_button = 'hidden';
|
|
|
|
|
function sendUnreadTopics(topicIds) {
|
|
|
|
|
Topics.getTopicsByTids(topicIds, uid, function(topicData) {
|
|
|
|
|
unreadTopics.topics = topicData;
|
|
|
|
|
unreadTopics.nextStart = start + topicIds.length;
|
|
|
|
|
if(!topicData || topicData.length === 0)
|
|
|
|
|
unreadTopics.no_topics_message = 'show';
|
|
|
|
|
if(uid === 0 || topicData.length === 0)
|
|
|
|
|
unreadTopics.show_markallread_button = 'hidden';
|
|
|
|
|
callback(unreadTopics);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function sendUnreadTopics(topicIds) {
|
|
|
|
|
Topics.getTopicsByTids(topicIds, uid, function(topicData) {
|
|
|
|
|
unreadTopics.topics = topicData;
|
|
|
|
|
unreadTopics.nextStart = start + tids.length;
|
|
|
|
|
if(!topicData || topicData.length === 0)
|
|
|
|
|
unreadTopics.no_topics_message = 'show';
|
|
|
|
|
if(uid === 0 || topicData.length === 0)
|
|
|
|
|
unreadTopics.show_markallread_button = 'hidden';
|
|
|
|
|
callback(unreadTopics);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
var unreadTids = [],
|
|
|
|
|
done = false;
|
|
|
|
|
|
|
|
|
|
if (!tids || !tids.length) {
|
|
|
|
|
noUnreadTopics();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
async.whilst(
|
|
|
|
|
function () { return unreadTids.length < 20 && !done; },
|
|
|
|
|
function (callback) {
|
|
|
|
|
RDB.zrevrange('topics:recent', start, stop, function(err, tids) {
|
|
|
|
|
if(err)
|
|
|
|
|
return callback(err);
|
|
|
|
|
|
|
|
|
|
if(uid === 0) {
|
|
|
|
|
sendUnreadTopics(tids);
|
|
|
|
|
} else {
|
|
|
|
|
if(tids && !tids.length) {
|
|
|
|
|
done = true;
|
|
|
|
|
return callback(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Topics.hasReadTopics(tids, uid, function(read) {
|
|
|
|
|
if(uid === 0) {
|
|
|
|
|
unreadTids.push.apply(unreadTids, tids);
|
|
|
|
|
callback(null);
|
|
|
|
|
} else {
|
|
|
|
|
Topics.hasReadTopics(tids, uid, function(read) {
|
|
|
|
|
|
|
|
|
|
var unreadTids = tids.filter(function(tid, index, self) {
|
|
|
|
|
return read[index] === 0;
|
|
|
|
|
});
|
|
|
|
|
var newtids = tids.filter(function(tid, index, self) {
|
|
|
|
|
return read[index] === 0;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!unreadTids || !unreadTids.length) {
|
|
|
|
|
noUnreadTopics();
|
|
|
|
|
return;
|
|
|
|
|
unreadTids.push.apply(unreadTids, newtids);
|
|
|
|
|
start = stop + 1;
|
|
|
|
|
stop = start + 19;
|
|
|
|
|
callback(null);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sendUnreadTopics(unreadTids);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
function (err) {
|
|
|
|
|
if(err)
|
|
|
|
|
return callback([]);
|
|
|
|
|
if(unreadTids.length)
|
|
|
|
|
sendUnreadTopics(unreadTids);
|
|
|
|
|
else
|
|
|
|
|
noUnreadTopics();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Topics.getTopicsByTids = function(tids, current_user, callback, category_id) {
|
|
|
|
@ -572,8 +614,8 @@ marked.setOptions({
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
user.getUserField(uid, 'lastposttime', function(lastposttime) {
|
|
|
|
|
|
|
|
|
|
user.getUserField(uid, 'lastposttime', function(err, lastposttime) {
|
|
|
|
|
if (err) lastposttime = 0;
|
|
|
|
|
if(Date.now() - lastposttime < meta.config.postDelay) {
|
|
|
|
|
callback(new Error('too-many-posts'), null);
|
|
|
|
|
return;
|
|
|
|
@ -650,14 +692,7 @@ marked.setOptions({
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Topics.getTopicFields = function(tid, fields, callback) {
|
|
|
|
|
RDB.hmgetObject('topic:' + tid, fields, function(err, data) {
|
|
|
|
|
if(err === null) {
|
|
|
|
|
callback(data);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
console.log(err);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
RDB.hmgetObject('topic:' + tid, fields, callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Topics.setTopicField = function(tid, field, value) {
|
|
|
|
@ -675,7 +710,7 @@ marked.setOptions({
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Topics.updateTimestamp = function(tid, timestamp) {
|
|
|
|
|
RDB.zadd(schema.topics().recent, timestamp, tid);
|
|
|
|
|
RDB.zadd('topics:recent', timestamp, tid);
|
|
|
|
|
Topics.setTopicField(tid, 'lastposttime', timestamp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -687,6 +722,18 @@ marked.setOptions({
|
|
|
|
|
RDB.lrange('tid:' + tid + ':posts', 0, -1, callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Topics.delete = function(tid) {
|
|
|
|
|
Topics.setTopicField(tid, 'deleted', 1);
|
|
|
|
|
RDB.zrem('topics:recent', tid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Topics.restore = function(tid) {
|
|
|
|
|
Topics.setTopicField(tid, 'deleted', 0);
|
|
|
|
|
Topics.getTopicField(tid, 'lastposttime', function(err, lastposttime) {
|
|
|
|
|
RDB.zadd('topics:recent', lastposttime, tid);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Topics.reIndexTopic = function(tid, callback) {
|
|
|
|
|
Topics.getPids(tid, function(err, pids) {
|
|
|
|
|
if(err) {
|
|
|
|
|