|
|
|
@ -12,29 +12,30 @@ var categories = require('./categories');
|
|
|
|
|
var privileges = require('./privileges');
|
|
|
|
|
var social = require('./social');
|
|
|
|
|
|
|
|
|
|
(function (Topics) {
|
|
|
|
|
require('./topics/data')(Topics);
|
|
|
|
|
require('./topics/create')(Topics);
|
|
|
|
|
require('./topics/delete')(Topics);
|
|
|
|
|
require('./topics/unread')(Topics);
|
|
|
|
|
require('./topics/recent')(Topics);
|
|
|
|
|
require('./topics/popular')(Topics);
|
|
|
|
|
require('./topics/user')(Topics);
|
|
|
|
|
require('./topics/fork')(Topics);
|
|
|
|
|
require('./topics/posts')(Topics);
|
|
|
|
|
require('./topics/follow')(Topics);
|
|
|
|
|
require('./topics/tags')(Topics);
|
|
|
|
|
require('./topics/teaser')(Topics);
|
|
|
|
|
require('./topics/suggested')(Topics);
|
|
|
|
|
require('./topics/tools')(Topics);
|
|
|
|
|
require('./topics/thumb')(Topics);
|
|
|
|
|
require('./topics/bookmarks')(Topics);
|
|
|
|
|
|
|
|
|
|
Topics.exists = function (tid, callback) {
|
|
|
|
|
var Topics = module.exports;
|
|
|
|
|
|
|
|
|
|
require('./topics/data')(Topics);
|
|
|
|
|
require('./topics/create')(Topics);
|
|
|
|
|
require('./topics/delete')(Topics);
|
|
|
|
|
require('./topics/unread')(Topics);
|
|
|
|
|
require('./topics/recent')(Topics);
|
|
|
|
|
require('./topics/popular')(Topics);
|
|
|
|
|
require('./topics/user')(Topics);
|
|
|
|
|
require('./topics/fork')(Topics);
|
|
|
|
|
require('./topics/posts')(Topics);
|
|
|
|
|
require('./topics/follow')(Topics);
|
|
|
|
|
require('./topics/tags')(Topics);
|
|
|
|
|
require('./topics/teaser')(Topics);
|
|
|
|
|
require('./topics/suggested')(Topics);
|
|
|
|
|
require('./topics/tools')(Topics);
|
|
|
|
|
require('./topics/thumb')(Topics);
|
|
|
|
|
require('./topics/bookmarks')(Topics);
|
|
|
|
|
|
|
|
|
|
Topics.exists = function (tid, callback) {
|
|
|
|
|
db.isSortedSetMember('topics:tid', tid, callback);
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Topics.getPageCount = function (tid, uid, callback) {
|
|
|
|
|
Topics.getPageCount = function (tid, uid, callback) {
|
|
|
|
|
var postCount;
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
@ -51,14 +52,14 @@ var social = require('./social');
|
|
|
|
|
next(null, Math.ceil((parseInt(postCount, 10) - 1) / settings.postsPerPage));
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Topics.getTidPage = function (tid, uid, callback) {
|
|
|
|
|
Topics.getTidPage = function (tid, uid, callback) {
|
|
|
|
|
console.warn('[Topics.getTidPage] deprecated!');
|
|
|
|
|
callback(null, 1);
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Topics.getTopicsFromSet = function (set, uid, start, stop, callback) {
|
|
|
|
|
Topics.getTopicsFromSet = function (set, uid, start, stop, callback) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
db.getSortedSetRevRange(set, start, stop, next);
|
|
|
|
@ -70,9 +71,9 @@ var social = require('./social');
|
|
|
|
|
next(null, { topics: topics, nextStart: stop + 1 });
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Topics.getTopics = function (tids, uid, callback) {
|
|
|
|
|
Topics.getTopics = function (tids, uid, callback) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
privileges.topics.filterTids('read', tids, uid, next);
|
|
|
|
@ -81,9 +82,9 @@ var social = require('./social');
|
|
|
|
|
Topics.getTopicsByTids(tids, uid, next);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Topics.getTopicsByTids = function (tids, uid, callback) {
|
|
|
|
|
Topics.getTopicsByTids = function (tids, uid, callback) {
|
|
|
|
|
if (!Array.isArray(tids) || !tids.length) {
|
|
|
|
|
return callback(null, []);
|
|
|
|
|
}
|
|
|
|
@ -167,9 +168,9 @@ var social = require('./social');
|
|
|
|
|
next(null, data.topics);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Topics.getTopicWithPosts = function (topicData, set, uid, start, stop, reverse, callback) {
|
|
|
|
|
Topics.getTopicWithPosts = function (topicData, set, uid, start, stop, reverse, callback) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
@ -220,9 +221,9 @@ var social = require('./social');
|
|
|
|
|
next(null, data.topic);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function getMainPostAndReplies(topic, set, uid, start, stop, reverse, callback) {
|
|
|
|
|
function getMainPostAndReplies(topic, set, uid, start, stop, reverse, callback) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
if (stop > 0) {
|
|
|
|
@ -259,68 +260,72 @@ var social = require('./social');
|
|
|
|
|
Topics.addPostData(posts, uid, next);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getDeleter(topicData, callback) {
|
|
|
|
|
function getDeleter(topicData, callback) {
|
|
|
|
|
if (!topicData.deleterUid) {
|
|
|
|
|
return setImmediate(callback, null, null);
|
|
|
|
|
}
|
|
|
|
|
user.getUserFields(topicData.deleterUid, ['username', 'userslug', 'picture'], callback);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Topics.getMainPost = function (tid, uid, callback) {
|
|
|
|
|
Topics.getMainPost = function (tid, uid, callback) {
|
|
|
|
|
Topics.getMainPosts([tid], uid, function (err, mainPosts) {
|
|
|
|
|
callback(err, Array.isArray(mainPosts) && mainPosts.length ? mainPosts[0] : null);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Topics.getMainPids = function (tids, callback) {
|
|
|
|
|
Topics.getMainPids = function (tids, callback) {
|
|
|
|
|
if (!Array.isArray(tids) || !tids.length) {
|
|
|
|
|
return callback(null, []);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Topics.getTopicsFields(tids, ['mainPid'], function (err, topicData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
Topics.getTopicsFields(tids, ['mainPid'], next);
|
|
|
|
|
},
|
|
|
|
|
function (topicData, next) {
|
|
|
|
|
var mainPids = topicData.map(function (topic) {
|
|
|
|
|
return topic && topic.mainPid;
|
|
|
|
|
});
|
|
|
|
|
callback(null, mainPids);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
next(null, mainPids);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Topics.getMainPosts = function (tids, uid, callback) {
|
|
|
|
|
Topics.getMainPids(tids, function (err, mainPids) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
getMainPosts(mainPids, uid, callback);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
Topics.getMainPosts = function (tids, uid, callback) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
Topics.getMainPids(tids, next);
|
|
|
|
|
},
|
|
|
|
|
function (mainPids, next) {
|
|
|
|
|
getMainPosts(mainPids, uid, next);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function getMainPosts(mainPids, uid, callback) {
|
|
|
|
|
posts.getPostsByPids(mainPids, uid, function (err, postData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
function getMainPosts(mainPids, uid, callback) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
posts.getPostsByPids(mainPids, uid, next);
|
|
|
|
|
},
|
|
|
|
|
function (postData, next) {
|
|
|
|
|
postData.forEach(function (post) {
|
|
|
|
|
if (post) {
|
|
|
|
|
post.index = 0;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
Topics.addPostData(postData, uid, callback);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
Topics.addPostData(postData, uid, next);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Topics.isLocked = function (tid, callback) {
|
|
|
|
|
Topics.isLocked = function (tid, callback) {
|
|
|
|
|
Topics.getTopicField(tid, 'locked', function (err, locked) {
|
|
|
|
|
callback(err, parseInt(locked, 10) === 1);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Topics.search = function (tid, term, callback) {
|
|
|
|
|
Topics.search = function (tid, term, callback) {
|
|
|
|
|
if (plugins.hasListeners('filter:topic.search')) {
|
|
|
|
|
plugins.fireHook('filter:topic.search', {
|
|
|
|
|
tid: tid,
|
|
|
|
@ -329,5 +334,4 @@ var social = require('./social');
|
|
|
|
|
} else {
|
|
|
|
|
callback(new Error('[[error:no-plugins-available]]'), []);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}(exports));
|
|
|
|
|
};
|
|
|
|
|