|
|
|
@ -454,7 +454,7 @@ var async = require('async'),
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}, function(tids) {
|
|
|
|
|
Topics.getTopicsByTids(tids, current_user, function(topicData) {
|
|
|
|
|
Topics.getTopicsByTids(tids, 0, current_user, function(err, topicData) {
|
|
|
|
|
latestTopics.topics = topicData;
|
|
|
|
|
callback(err, latestTopics);
|
|
|
|
|
});
|
|
|
|
@ -476,8 +476,9 @@ var async = require('async'),
|
|
|
|
|
function(callback) {
|
|
|
|
|
db.getSortedSetRevRange('topics:recent', start, stop, function(err, tids) {
|
|
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tids && !tids.length) {
|
|
|
|
|
done = true;
|
|
|
|
@ -499,7 +500,7 @@ var async = require('async'),
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
function(err) {
|
|
|
|
|
callback({
|
|
|
|
|
callback(null, {
|
|
|
|
|
count: unreadTids.length
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -569,19 +570,22 @@ var async = require('async'),
|
|
|
|
|
'show_topic_button': 'hidden',
|
|
|
|
|
'show_markallread_button': 'show',
|
|
|
|
|
'no_topics_message': 'hidden',
|
|
|
|
|
'topic_row_size': 'col-md-12',
|
|
|
|
|
'topics': []
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function noUnreadTopics() {
|
|
|
|
|
unreadTopics.no_topics_message = 'show';
|
|
|
|
|
unreadTopics.show_markallread_button = 'hidden';
|
|
|
|
|
callback(unreadTopics);
|
|
|
|
|
callback(null, unreadTopics);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function sendUnreadTopics(topicIds) {
|
|
|
|
|
|
|
|
|
|
Topics.getTopicsByTids(topicIds, uid, function(topicData) {
|
|
|
|
|
Topics.getTopicsByTids(topicIds, 0, uid, function(err, topicData) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unreadTopics.topics = topicData;
|
|
|
|
|
unreadTopics.nextStart = stop + 1;
|
|
|
|
|
if (!topicData || topicData.length === 0) {
|
|
|
|
@ -591,13 +595,13 @@ var async = require('async'),
|
|
|
|
|
unreadTopics.show_markallread_button = 'hidden';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(unreadTopics);
|
|
|
|
|
callback(null, unreadTopics);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Topics.getUnreadTids(uid, start, stop, function(err, unreadTids) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback([]);
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (unreadTids.length) {
|
|
|
|
@ -634,13 +638,12 @@ var async = require('async'),
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Topics.getTopicsByTids = function(tids, current_user, callback, category_id) {
|
|
|
|
|
Topics.getTopicsByTids = function(tids, cid, current_user, callback) {
|
|
|
|
|
|
|
|
|
|
var retrieved_topics = [];
|
|
|
|
|
|
|
|
|
|
if (!Array.isArray(tids) || tids.length === 0) {
|
|
|
|
|
callback(retrieved_topics);
|
|
|
|
|
return;
|
|
|
|
|
return callback(null, retrieved_topics);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getTopicInfo(topicData, callback) {
|
|
|
|
@ -664,19 +667,19 @@ var async = require('async'),
|
|
|
|
|
// temporary. I don't think this call should belong here
|
|
|
|
|
|
|
|
|
|
function getPrivileges(next) {
|
|
|
|
|
categoryTools.privileges(category_id, current_user, function(err, user_privs) {
|
|
|
|
|
next(err, user_privs);
|
|
|
|
|
});
|
|
|
|
|
categoryTools.privileges(cid, current_user, next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getCategoryInfo(next) {
|
|
|
|
|
categories.getCategoryFields(topicData.cid, ['name', 'slug', 'icon'], function(err, categoryData) {
|
|
|
|
|
next(err, categoryData);
|
|
|
|
|
});
|
|
|
|
|
categories.getCategoryFields(topicData.cid, ['name', 'slug', 'icon'], next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async.parallel([getUserInfo, hasReadTopic, getTeaserInfo, getPrivileges, getCategoryInfo], function(err, results) {
|
|
|
|
|
callback({
|
|
|
|
|
if(err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(null, {
|
|
|
|
|
username: results[0].username,
|
|
|
|
|
userslug: results[0].userslug,
|
|
|
|
|
picture: results[0].picture,
|
|
|
|
@ -694,13 +697,20 @@ var async = require('async'),
|
|
|
|
|
return !deleted || (deleted && topicInfo.privileges.view_deleted) || topicData.uid === current_user;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadTopic(tid, callback) {
|
|
|
|
|
function loadTopic(tid, next) {
|
|
|
|
|
Topics.getTopicData(tid, function(err, topicData) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!topicData) {
|
|
|
|
|
return callback(null);
|
|
|
|
|
return next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getTopicInfo(topicData, function(topicInfo) {
|
|
|
|
|
getTopicInfo(topicData, function(err, topicInfo) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
topicData['pin-icon'] = parseInt(topicData.pinned, 10) === 1 ? 'fa-thumb-tack' : 'none';
|
|
|
|
|
topicData['lock-icon'] = parseInt(topicData.locked, 10) === 1 ? 'fa-lock' : 'none';
|
|
|
|
@ -720,18 +730,17 @@ var async = require('async'),
|
|
|
|
|
topicData.teaser_pid = topicInfo.teaserInfo.pid;
|
|
|
|
|
topicData.teaser_timestamp = topicInfo.teaserInfo.timestamp ? (new Date(parseInt(topicInfo.teaserInfo.timestamp, 10)).toISOString()) : '';
|
|
|
|
|
|
|
|
|
|
if (isTopicVisible(topicData, topicInfo))
|
|
|
|
|
if (isTopicVisible(topicData, topicInfo)) {
|
|
|
|
|
retrieved_topics.push(topicData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(null);
|
|
|
|
|
next(null);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async.eachSeries(tids, loadTopic, function(err) {
|
|
|
|
|
if (!err) {
|
|
|
|
|
callback(retrieved_topics);
|
|
|
|
|
}
|
|
|
|
|
callback(err, retrieved_topics);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|